#include <modecontroller.h>
Public Types | |
| typedef ModeConfigurationParser | ConfParser |
Public Member Functions | |
| ModeController () | |
| ModeController (PropertyMode defMod) | |
| virtual | ~ModeController () |
| virtual PropertyMode | getDefaultMode () const |
| virtual PropertyMode | setDefaultMode (PropertyMode mode) |
| virtual PropertyMode | getMode (const std::string &type, const std::string &name) const |
Private Attributes | |
| PropertyMode | defaultMode |
| ModeMatcher | matcher |
Basic mode controller implementation.
Provides mapping from type, name pair to Property mode, where type stands for complex type name (Value of complex - dictionary - Type field value) and name for field name in given complex type.
Rules
We will write type, name pair in following format:
type[.name]: mode
not specified is represented by empty string or word containing just blanks.
not specified type and name. Each type name combination matches.
Example: .: mdUnknown is same as : mdUnknown
Default mode is mdUnknown
type with name unspecified is same as pure type and specifies all fields from dictionary with given Type field value.
Example: Page. : mdAdvanced is same as Page : mdAdvanced
All fields from Page complex value is mdAdvanced
unspecified type and specified name stands for all fields with given name with no respect to complex type. It has higher priority than pure type specification.
Example: Page. : mdNormal .Value: mdReadOnly
Page.foo is mdNormal Page.Value is mdReadOnly Foo.Value is mdReadOnly
Type, Name specifies concrete field on complex type (Type field value of complex) and field name in this complex. This has the highest priority.
Example: Page. : mdNormal .Value: mdReadOnly Page.Value: mdAdvanced
Page.Value is mdAdvanced Page.foo is mdNormal foo.Value is mdReadOnly
Usage
Instance with empty constructor is created with mdUnknown default mode. If you need to specify different one, use setDefaultMode method or constructor with parameter.
Rules for modes can be add either manualy by addRule (inherited from RulesManager class) method or from file using loadFromFile method. loadFromFile method requires file name and parser parameters. Second one is implementator which implements parsing functionality for given configuration file format.
Example:
// Initializes mode controller //============================
// creates ModeController instance ModeController modeControler;
// Creates low-level parser for simple configuration files (one line one // setting). This base parser is used by ConfParser which is used by // ModeController in loadFromFile StringConfigurationParser baseParser(StringConfigurationParser(NULL)); ModeController::ConfParser parser(baseParser);
// parser is ready, we can load rules int result=modeControler.loadFromFile(fileName, parser); if(result==-1) cerr << "File \""<<fileName<<"" parsing failed"<<endl; else cout << result << "new rules added"<<endl;
// use mode controller //==================== PropertyMode mode=modeControler.getMode(ParentType, ChildName);
Type for configuration parser for loadFromFile method.
| configuration::ModeController::ModeController | ( | ) | [inline] |
Constructor.
Intiailizes defaultMode to mdUnknown. Sets ModeMatcher instance to ModeRulesManager.
References matcher, and rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::setRuleMatcher().
| configuration::ModeController::ModeController | ( | PropertyMode | defMod | ) | [inline] |
Constructor with default mode.
| defMod | Default mode to be used. |
Initializes defaultMode with given one. Sets ModeMatcher instance to ModeRulesManager.
References matcher, and rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::setRuleMatcher().
| virtual configuration::ModeController::~ModeController | ( | ) | [inline, virtual] |
Virtual destructor. This method is empty, because no special treatment is required.
| virtual PropertyMode configuration::ModeController::getDefaultMode | ( | ) | const [inline, virtual] |
Get default mode.
Default policy for non matching rules.
References defaultMode.
| virtual PropertyMode configuration::ModeController::getMode | ( | const std::string & | type, | |
| const std::string & | name | |||
| ) | const [inline, virtual] |
Get mode for value with given type and name.
| type | Type field value of complex type. | |
| name | Name if the field in complex type. |
Given parameters may be empty what means not specified.
If no rule matches given pair, getDefaultMode is returned.
References defaultMode, and rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >::findMatching().
Referenced by gui::PropertyModeController::mode().
| virtual PropertyMode configuration::ModeController::setDefaultMode | ( | PropertyMode | mode | ) | [inline, virtual] |
Sets default mode.
| mode | New default mode. |
References defaultMode.
Default mode.
Value is set in constructor.
Referenced by getDefaultMode(), getMode(), and setDefaultMode().
Matcher for rules.
This matched for supertype matcher intialization in constructor.
Reimplemented from rulesmanager::RulesManager< RuleType, RuleTarget, RuleStorage >.
Referenced by ModeController().