#include <rulesmanager.h>
Public Types | |
| typedef IRuleMatcher< RuleType > | RuleMatcherType |
| typedef RuleStorage::iterator | iterator |
| typedef RuleStorage::const_iterator | const_iterator |
| typedef RuleStorage::value_type | MappingType |
Public Member Functions | |
| RulesManager () | |
| RulesManager (const RuleMatcherType *m) | |
| RulesManager (const RuleMatcherType *m, RuleStorage map) | |
| virtual | ~RulesManager () |
| virtual const RuleMatcherType * | setRuleMatcher (const RuleMatcherType *newMatcher) |
| virtual void | addRule (RuleType ruleDef, RuleTarget target) |
| template<typename Parser > | |
| int | loadFromFile (const std::string &confFile, Parser &parser) |
| virtual bool | delRule (RuleType ruleDef, RuleTarget *target) |
| virtual void | delMatching (const RuleType &ruleDef, RuleStorage *removed) |
| virtual void | clear (RuleStorage *removed) |
| virtual bool | findMatching (const RuleType &rule, RuleTarget *target) const |
Private Member Functions | |
| iterator | find (RuleType &rule, iterator &start, iterator &end) |
Private Attributes | |
| RuleStorage | mapping |
| const RuleMatcherType * | matcher |
Manager for rules.
Template class to maintain mapping from rules to rules targets (specified by template parameters RuleType and RuleTarget) and query for RuleTargets from given rules with most specific matching one.
RuleType template parameter specifies rule structure. It has to implement at least bool operator==(const RuleType &)const which returns true for two same rules (Note same are allways mathich but oposit implication doesn't have to be true).
RuleTarget template parameter specifies target of the rule. There are no constrains (except for correct allocation, deallocation and copying) on type. RulesManager user has to understand usage and meaning.
Uses IRuleMatcher implementation for specific rule decisions, defined in constructor. This can be changed in runtime to better fit different strathegies.
This class is responsible for correct rules storing and mapping to rule targets. All matching logic is delegated to the IRuleMatcher and just best candidate is returned. Mapping is stored in container defined as RuleStorage template paramter. This has to provide: forward iterators (both const and non const), clear method, push_back method, erase method.
| typedef RuleStorage::const_iterator rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::const_iterator |
Alias for Rules storage constant iterator.
| typedef RuleStorage::iterator rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::iterator |
Alias for Rules storage iterator.
| typedef RuleStorage::value_type rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::MappingType |
Alias for Rules storage mapping entry.
| typedef IRuleMatcher<RuleType> rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::RuleMatcherType |
Alias for Rules matcher.
| rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::RulesManager | ( | ) | [inline] |
Empty constructor. Initializes matcher to NULL.
| rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::RulesManager | ( | const RuleMatcherType * | m | ) | [inline] |
Constructor.
| m | Implementation of rules matcher. |
Sets matcher field and creates empty mapping.
| rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::RulesManager | ( | const RuleMatcherType * | m, | |
| RuleStorage | map | |||
| ) | [inline] |
Constructor with initial mapping.
| m | Implementation of rules matcher. | |
| map | Initial rules mapping. |
Sets matcher field and initializes mapping with given storage.
| virtual rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::~RulesManager | ( | ) | [inline, virtual] |
Virtual destructor. This method is empty, because no special treatment is required.
| virtual void rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::addRule | ( | RuleType | ruleDef, | |
| RuleTarget | target | |||
| ) | [inline, virtual] |
Adds given rule, target mapping.
| ruleDef | Rule definition. | |
| target | Target for given rule. |
Inserts mapping with given ruleDef, target pair. Mapping is inserted even if ruleDef is already in. It depends on implementation of IRuleMatcher which one is used (by default one specified later because IRuleMatcher::betterMatch returns true for same priority by default).
Referenced by rulesmanager::RulesManager< std::string, std::string >::loadFromFile().
| virtual void rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::clear | ( | RuleStorage * | removed | ) | [inline, virtual] |
Clears whole mapping.
| removed | Place where to store removed mapping (only if non NULL). |
If removed parameter is non NULL, copies mapping content to it befor clearing (given container is cleared before).
| virtual void rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::delMatching | ( | const RuleType & | ruleDef, | |
| RuleStorage * | removed | |||
| ) | [inline, virtual] |
Removes all mappings matching given rule.
| ruleDef | Rule to match. | |
| removed | RuleStorage with all removed rule, target pairs (only if non NULL). |
Goes through whole mapping and checks all rules whether they match given rule. If yes, removes them from mapping and if removed parameter is non NULL, inserts rule, target pair to it (container is cleared at the begining in any case).
If matcher is not specified (it is NULL), returns immediately after removed container is cleared.
| virtual bool rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::delRule | ( | RuleType | ruleDef, | |
| RuleTarget * | target | |||
| ) | [inline, virtual] |
Removes mapping for given ruleDef.
| ruleDef | Rule definition. | |
| target | Place where to place associated target. |
First occurence in mapping is removed.
If mapping is found and target parameter is non NULL, rule target is set to place where it points.
| iterator rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::find | ( | RuleType & | rule, | |
| iterator & | start, | |||
| iterator & | end | |||
| ) | [inline, private] |
Searches for given rule in [start, end) range.
| rule | Rule to search. | |
| start | Iterator to first element to search. | |
| end | Iterator behind last element to consider. |
Checks for all elements in range [start, end) and compares it with given rule (using RuleType::== operator). If found, returns iterator.
Referenced by rulesmanager::RulesManager< std::string, std::string >::delRule().
| virtual bool rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::findMatching | ( | const RuleType & | rule, | |
| RuleTarget * | target | |||
| ) | const [inline, virtual] |
Finds best fit mapping.
| rule | Rule to find. | |
| target | Place where to put target if rule matches (only if non NULL). |
Goes through whole mapping and compares given rule with those from mapping using IRuleMatcher implementation. If multiple rules matches use one which matches the best according priority.
If at least one mapping matches and target parameter is non NULL, associated target is stored to place where it points.
if no matcher is specified (it is NULL), immediately returns with false.
Referenced by configuration::ModeController::getMode().
| int rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::loadFromFile | ( | const std::string & | confFile, | |
| Parser & | parser | |||
| ) | [inline] |
Reads given configuration file.
| confFile | Configuration file name. | |
| parser | Parser to be used for file parsing. |
Uses given parser to get key (RuleType) and value (RuleTarget) from given file. Given parser has to support given file format. Parsed rules are registered using addRule method.
Note that Parser template type has to provide correct types for key and value. IConfigurationParser descendant should be used.
Referenced by gui::PropertyModeController::PropertyModeController().
| virtual const RuleMatcherType* rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::setRuleMatcher | ( | const RuleMatcherType * | newMatcher | ) | [inline, virtual] |
Sets new rule matcher implementation.
| newMatcher | New matcher implementation. |
Referenced by configuration::ModeController::ModeController().
RuleStorage rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::mapping [private] |
Rules to targets mapping.
Referenced by rulesmanager::RulesManager< std::string, std::string >::addRule(), rulesmanager::RulesManager< std::string, std::string >::clear(), rulesmanager::RulesManager< std::string, std::string >::delMatching(), rulesmanager::RulesManager< std::string, std::string >::delRule(), and rulesmanager::RulesManager< std::string, std::string >::findMatching().
const RuleMatcherType* rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::matcher [private] |
IRuleMatcher implementator for rule matching.
First implementation is set in constructor and can be changed by setRuleMatcher method. If NULL is provided, findMatching always return false.
Reimplemented in configuration::ModeController.
Referenced by rulesmanager::RulesManager< std::string, std::string >::delMatching(), rulesmanager::RulesManager< std::string, std::string >::findMatching(), and rulesmanager::RulesManager< std::string, std::string >::setRuleMatcher().