Kinetis Bootloader Host  2.0.0
Host Tools for Kinetis devices
OptionDictionary.h
1 /*
2  * File: OptionDictionary.h
3  *
4  * Copyright (c) Freescale Semiconductor, Inc. All rights reserved.
5  * See included license file for license details.
6  */
7 #if !defined(_OptionDictionary_h_)
8 #define _OptionDictionary_h_
9 
10 #include "OptionContext.h"
11 #include <map>
12 
13 namespace elftosb
14 {
28 {
29 public:
32  : m_parent(0)
33  {
34  }
35 
38  : m_parent(parent)
39  {
40  }
41 
44 
46 
47  inline OptionContext *getParent() const { return m_parent; }
54  inline void setParent(OptionContext *newParent) { m_parent = newParent; }
56 
58 
59  virtual bool hasOption(const std::string &name) const;
61 
63  virtual const Value *getOption(const std::string &name) const;
64 
66  virtual void setOption(const std::string &name, Value *value);
67 
69  virtual void deleteOption(const std::string &name);
71 
73 
74  bool isOptionLocked(const std::string &name) const;
76 
78  void lockOption(const std::string &name);
79 
81  void unlockOption(const std::string &name);
83 
85 
86  const Value *operator[](const std::string &name) const;
89 
90 protected:
92 
96  struct OptionValue
97  {
99  bool m_isLocked;
100 
103  : m_value(0)
104  , m_isLocked(false)
105  {
106  }
107  };
108 
109  typedef std::map<std::string, OptionValue> option_map_t;
110  option_map_t m_options;
111 };
112 
113 }; // namespace elftosb
114 
115 #endif // _OptionDictionary_h_
OptionDictionary(OptionContext *parent)
Constructor taking a parent context.
Definition: OptionDictionary.h:37
std::map< std::string, OptionValue > option_map_t
Map from option name to value.
Definition: OptionDictionary.h:109
void unlockOption(const std::string &name)
Allow an option to be changed.
Definition: OptionDictionary.cpp:153
virtual const Value * getOption(const std::string &name) const
Returns the option&#39;s value.
Definition: OptionDictionary.cpp:50
OptionValue()
Constructor.
Definition: OptionDictionary.h:102
void lockOption(const std::string &name)
Prevent further modifications of an option&#39;s value.
Definition: OptionDictionary.cpp:141
option_map_t m_options
The option dictionary.
Definition: OptionDictionary.h:110
Concrete implementation of OptionContext.
Definition: OptionDictionary.h:27
Value * m_value
The object for this option&#39;s value.
Definition: OptionDictionary.h:98
OptionContext * getParent() const
Returns the current parent context.
Definition: OptionDictionary.h:50
bool isOptionLocked(const std::string &name) const
Returns true if the specified option is locked from further changes.
Definition: OptionDictionary.cpp:128
~OptionDictionary()
Destructor.
Definition: OptionDictionary.cpp:14
void setParent(OptionContext *newParent)
Change the parent context.
Definition: OptionDictionary.h:54
Definition: BootImage.h:13
Abstract base class for values of arbitrary types.
Definition: apps/elftosb/common/Value.h:20
Pure abstract interface class to a table of options.
Definition: apps/elftosb/common/OptionContext.h:18
virtual void setOption(const std::string &name, Value *value)
Adds or changes an option&#39;s value.
Definition: OptionDictionary.cpp:82
virtual bool hasOption(const std::string &name) const
Detemine whether the named option is present in the table.
Definition: OptionDictionary.cpp:32
const Value * operator[](const std::string &name) const
Indexing operator; returns the value for the option name.
Definition: OptionDictionary.cpp:165
Information about one option&#39;s value.
Definition: OptionDictionary.h:96
bool m_isLocked
True if this value is locked from further changes.
Definition: OptionDictionary.h:99
OptionContext * m_parent
Our parent context.
Definition: OptionDictionary.h:91
virtual void deleteOption(const std::string &name)
Removes an option from the table.
Definition: OptionDictionary.cpp:112
OptionDictionary()
Default constructor.
Definition: OptionDictionary.h:31