2 * File: OptionDictionary.h
4 * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5 * See included license file for license details.
7 #if !defined(_OptionDictionary_h_)
8 #define _OptionDictionary_h_
10 #include "OptionContext.h"
17 * \brief Concrete implementation of OptionContext.
19 * This context subclass supports having a parent context. If an option is not
20 * found in the receiving instance, the request is passed to the parent.
21 * The hasOption() and getOption() methods will ask up the parent chain
22 * if the requested option does not exist in the receiving instance.
23 * But the setOption() and deleteOption() methods only operate locally,
24 * on the instance on which they were called. This allows a caller to
25 * locally override an option value without affecting any of the parent
28 class OptionDictionary : public OptionContext
31 //! \brief Default constructor.
32 OptionDictionary() : m_parent(0) {}
34 //! \brief Constructor taking a parent context.
35 OptionDictionary(OptionContext * parent) : m_parent(parent) {}
37 //! \brief Destructor.
42 //! \brief Returns the current parent context.
43 //! \return The current parent context instance.
44 //! \retval NULL No parent has been set.
45 inline OptionContext * getParent() const { return m_parent; }
47 //! \brief Change the parent context.
48 //! \param newParent The parent context object. May be NULL, in which case
49 //! the object will no longer have a parent context.
50 inline void setParent(OptionContext * newParent) { m_parent = newParent; }
55 //! \brief Detemine whether the named option is present in the table.
56 virtual bool hasOption(const std::string & name) const;
58 //! \brief Returns the option's value.
59 virtual const Value * getOption(const std::string & name) const;
61 //! \brief Adds or changes an option's value.
62 virtual void setOption(const std::string & name, Value * value);
64 //! \brief Removes an option from the table.
65 virtual void deleteOption(const std::string & name);
70 //! \brief Returns true if the specified option is locked from further changes.
71 bool isOptionLocked(const std::string & name) const;
73 //! \brief Prevent further modifications of an option's value.
74 void lockOption(const std::string & name);
76 //! \brief Allow an option to be changed.
77 void unlockOption(const std::string & name);
82 //! \brief Indexing operator; returns the value for the option \a name.
83 const Value * operator [] (const std::string & name) const;
87 OptionContext * m_parent; //!< Our parent context.
90 * \brief Information about one option's value.
94 Value * m_value; //!< The object for this option's value.
95 bool m_isLocked; //!< True if this value is locked from further changes.
97 //! \brief Constructor.
98 OptionValue() : m_value(0), m_isLocked(false) {}
101 typedef std::map<std::string, OptionValue> option_map_t; //!< Map from option name to value.
102 option_map_t m_options; //!< The option dictionary.
105 }; // namespace elftosb
107 #endif // _OptionDictionary_h_