Concrete implementation of OptionContext.
More...
#include <OptionDictionary.h>
Concrete implementation of OptionContext.
This context subclass supports having a parent context. If an option is not found in the receiving instance, the request is passed to the parent. The hasOption() and getOption() methods will ask up the parent chain if the requested option does not exist in the receiving instance. But the setOption() and deleteOption() methods only operate locally, on the instance on which they were called. This allows a caller to locally override an option value without affecting any of the parent contexts.
| OptionDictionary::~OptionDictionary |
( |
| ) |
|
Destructor.
Deletes all of the option values that have been assigned locally.
| void OptionDictionary::deleteOption |
( |
const std::string & |
name | ) |
|
|
virtual |
Removes an option from the table.
- Parameters
-
| name | The name of the option to remove. |
Implements elftosb::OptionContext.
| const Value * OptionDictionary::getOption |
( |
const std::string & |
name | ) |
const |
|
virtual |
Returns the option's value.
If this object does not contain an option with the name of name, then the parent is asked for the value (if a parent has been set).
- Parameters
-
| name | The name of the option. |
- Returns
- The value for the option named name.
- Return values
-
| NULL | No option is in the table with that name. An option may also explicitly be set to a NULL value. The only way to tell the difference is to use the hasOption() method. |
Implements elftosb::OptionContext.
Returns the current parent context.
- Returns
- The current parent context instance.
- Return values
-
| NULL | No parent has been set. |
| bool OptionDictionary::hasOption |
( |
const std::string & |
name | ) |
const |
|
virtual |
Detemine whether the named option is present in the table.
If a parent context has been set and the option does not exist in this instance, then the parent is asked if it contains the option.
- Parameters
-
| name | The name of the option to query. |
- Return values
-
| true | The option is present in this instance or one of the parent. |
| false | No option with that name is in the dictionary, or any parent |
Implements elftosb::OptionContext.
| bool OptionDictionary::isOptionLocked |
( |
const std::string & |
name | ) |
const |
Returns true if the specified option is locked from further changes.
- Parameters
-
| name | Name of the option to query. |
- Returns
- True if the option is locked, false if unlocked or not present.
| void OptionDictionary::lockOption |
( |
const std::string & |
name | ) |
|
Prevent further modifications of an option's value.
- Parameters
-
| name | Name of the option to lock. |
| const Value * OptionDictionary::operator[] |
( |
const std::string & |
name | ) |
const |
Indexing operator; returns the value for the option name.
Simply calls getOption().
| void OptionDictionary::setOption |
( |
const std::string & |
name, |
|
|
Value * |
value |
|
) |
| |
|
virtual |
Adds or changes an option's value.
If the option was not already present in the table, it is added. Otherwise the old value is replaced. The option is always set locally; parent objects are never modified.
If the option has been locked with a call to lockOption() before trying to set its value, the setOption() is effectively ignored. To tell if an option is locked, use the isOptionLocked() method.
- Warning
- If the option already had a value, that previous value is deleted. This means that it cannot currently be in use by another piece of code. See the note in getOption().
- Parameters
-
| name | The option's name. |
| value | New value for the option. |
Implements elftosb::OptionContext.
| void elftosb::OptionDictionary::setParent |
( |
OptionContext * |
newParent | ) |
|
|
inline |
Change the parent context.
- Parameters
-
| newParent | The parent context object. May be NULL, in which case the object will no longer have a parent context. |
| void OptionDictionary::unlockOption |
( |
const std::string & |
name | ) |
|
Allow an option to be changed.
- Parameters
-
| name | Name of the option to unlock. |
The documentation for this class was generated from the following files: