elftosb::OptionDictionary Class Reference

Concrete implementation of OptionContext. More...

`#include <OptionDictionary.h>`

Inheritance diagram for elftosb::OptionDictionary:
[legend]
Collaboration diagram for elftosb::OptionDictionary:
[legend]

## Classes

struct | OptionValue
| Information about one option's value. More...

## Public Member Functions

| OptionDictionary ()
| Default constructor.
| OptionDictionary (OptionContext *parent)
| Constructor taking a parent context.
| ~OptionDictionary ()
| Destructor. More...
Parents
OptionContext * | getParent () const
| Returns the current parent context. More...
void | setParent (OptionContext *newParent)
| Change the parent context. More...
Options
virtual bool | hasOption (const std::string &name) const
| Detemine whether the named option is present in the table. More...
virtual const Value * | getOption (const std::string &name) const
| Returns the option's value. More...
virtual void | setOption (const std::string &name, Value *value)
| Adds or changes an option's value. More...
virtual void | deleteOption (const std::string &name)
| Removes an option from the table. More...
Locking
bool | isOptionLocked (const std::string &name) const
| Returns true if the specified option is locked from further changes. More...
void | lockOption (const std::string &name)
| Prevent further modifications of an option's value. More...
void | unlockOption (const std::string &name)
| Allow an option to be changed. More...
Operators
const Value * | operator[] (const std::string &name) const
| Indexing operator; returns the value for the option name. More...
Public Member Functions inherited from elftosb::OptionContext
virtual | ~OptionContext ()
| Make the dtor virtual.

## Protected Types

typedef std::map< std::string, OptionValue > | option_map_t
| Map from option name to value.

## Protected Attributes

OptionContext * | m_parent
| Our parent context.
option_map_t | m_options
| The option dictionary.

## Detailed Description

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.

## Constructor & Destructor Documentation

OptionDictionary::~OptionDictionary | ( |  | ) |

Destructor.

Deletes all of the option values that have been assigned locally.

## Member Function Documentation

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.

OptionContext* elftosb::OptionDictionary::getParent | ( |  | ) | const

inline

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:

- OptionDictionary.h
- OptionDictionary.cpp