- Main Page
- Namespaces
- Classes
- Files

# proto/Source/filter.h

Go to the documentation of this file.

    00001
    00009 #ifndef _FILTER_H
    00010 #define _FILTER_H
    00011
    00012 #include <string>
    00013 #include <vector>
    00014
    00015 namespace ace {
    00016
    00019 typedef std::string unirule_t;
    00020
    00023 typedef std::vector<std::string> multirule_t;
    00024
    00027 typedef std::vector<size_t> filter_matches_stats_t;
    00028
    00031 class Filter {
    00032 public:
    00035     struct Stats {
    00038         filter_matches_stats_t matched;
    00041         size_t unmatched;
    00044         Stats(void): matched(), unmatched(0) {}
    00047         void reset(void);
    00048     };
    00049 protected:
    00052     Stats _stats_so_far;
    00055     Stats _recent_stats;
    00056 public:
    00059     virtual ~Filter(void) {}
    00062     virtual bool is_on(void) const = 0;
    00065     inline Stats recent_stats(void) const { return _recent_stats; }
    00068     inline void reset_recent_stats(void) { _recent_stats.reset(); }
    00071     inline Stats stats_so_far(void) const { return _stats_so_far; }
    00072 };
    00073
    00074
    00078 class UniRulesFilter: public Filter {
    00079 public:
    00082     typedef std::vector<unirule_t> rules_t;
    00083 private:
    00086     rules_t _rules;
    00087 public:
    00091     void add_rule(unirule_t& rule);
    00094     inline const rules_t& get_rules(void) const { return _rules; }
    00100     bool match(const unirule_t& value, bool include_in_stats = true);
    00103     virtual bool is_on(void) const { return !_rules.empty(); }
    00108     bool read_rules(const char *rules_filename);
    00109 };
    00110
    00111
    00115 class MultiRulesFilter: public Filter {
    00116 public:
    00119     typedef std::vector<multirule_t> rules_t;
    00120 private:
    00123     rules_t _rules;
    00124 public:
    00128     void add_rule(multirule_t& rule);
    00131     inline const rules_t& get_rules(void) const { return _rules; }
    00137     bool match(const multirule_t& value, bool include_in_stats = true);
    00140     virtual bool is_on(void) const { return !_rules.empty(); }
    00146     bool read_rules(const char *rules_filename, size_t only_of_size = 0);
    00147 };
    00148
    00149 } // namespace ace
    00150
    00151 #endif