LogViewer
A modern log viewer with AI-assisted analysis (Qt 6)
Loading...
Searching...
No Matches
IFilterStrategy.hpp File Reference

Strategy interface for different filter matching algorithms. More...

#include <memory>
#include <mutex>
#include <regex>
#include <string>
#include <vector>
Include dependency graph for IFilterStrategy.hpp:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  filters::IFilterStrategy
 Abstract strategy interface for filter matching. More...
 
class  filters::RegexFilterStrategy
 Regex-based matching using std::regex. More...
 
class  filters::ExactMatchStrategy
 Exact string matching. More...
 
class  filters::FuzzyMatchStrategy
 Fuzzy matching using Levenshtein distance. More...
 
class  filters::WildcardStrategy
 Wildcard pattern matching (* and ?) More...
 

Namespaces

namespace  filters
 

Functions

std::unique_ptr< IFilterStrategy > filters::createStrategy (const std::string &strategyName)
 Strategy factory for creating strategies from names.
 

Detailed Description

Strategy interface for different filter matching algorithms.

Author
LogViewer Development Team
Date
2025

Implements the Strategy design pattern for filter matching. Allows runtime selection of different matching algorithms:

  • Regex matching (default)
  • Exact string matching
  • Fuzzy matching (Levenshtein distance)
  • Wildcard matching
  • Custom user-defined strategies
Example Usage:
// Use regex strategy (default)
auto filter = Filter("ErrorFilter", "message", "error.*", true);
filter.setStrategy(std::make_unique<RegexFilterStrategy>());
// Use exact match for performance-critical filtering
auto exactFilter = Filter("ExactFilter", "level", "ERROR");
exactFilter.setStrategy(std::make_unique<ExactMatchStrategy>());
// Use fuzzy matching for typo tolerance
auto fuzzyFilter = Filter("FuzzyFilter", "username", "admin", false);
fuzzyFilter.setStrategy(std::make_unique<FuzzyMatchStrategy>(2)); // max distance 2
Performance Characteristics:
  • RegexFilterStrategy: O(n) regex search, compiled once
  • ExactMatchStrategy: O(n) string comparison or O(1) hash lookup
  • FuzzyMatchStrategy: O(n*m) Levenshtein distance calculation
  • WildcardStrategy: O(n) pattern matching with * and ? wildcards
Thread Safety:
All strategy implementations must be thread-safe for concurrent reads. Pattern compilation should be done in constructor or separate init method.