30#ifndef INCLUDE_OLA_EXPORTMAP_H_
31#define INCLUDE_OLA_EXPORTMAP_H_
68 const std::string
Name()
const {
return m_name; }
74 virtual const std::string
Value()
const = 0;
81 BaseVariable*, bool> {
107 void Set(
bool value) { m_value = value; }
113 bool Get()
const {
return m_value; }
121 const std::string
Value()
const {
return m_value ?
"1" :
"0"; }
138 void Set(
const std::string &value) { m_value = value; }
139 const std::string Get()
const {
return m_value; }
140 const std::string
Value()
const {
return m_value; }
157 void Set(
int value) { m_value = value; }
158 void operator++(
int) { m_value++; }
159 void operator--(
int) { m_value--; }
160 void Reset() { m_value = 0; }
161 int Get()
const {
return m_value; }
163 std::ostringstream out;
183 void operator++(
int) { m_value++; }
184 void operator+=(
unsigned int value) { m_value += value; }
185 void Reset() { m_value = 0; }
186 unsigned int Get()
const {
return m_value; }
188 std::ostringstream out;
194 unsigned int m_value;
201template<
typename Type>
204 MapVariable(
const std::string &name,
const std::string &label)
210 void Set(
const std::string &key, Type value);
211 Type &operator[](
const std::string &key);
213 const std::string Label()
const {
return m_label; }
216 std::map<std::string, Type> m_variables;
222typedef MapVariable<std::string> StringMap;
230 IntMap(
const std::string &name,
const std::string &label)
233 void Increment(
const std::string &key) {
244 UIntMap(
const std::string &name,
const std::string &label)
247 void Increment(
const std::string &key) {
257template<
typename Type>
259 return m_variables[key];
266template<
typename Type>
267void MapVariable<Type>::Set(
const std::string &key, Type value) {
268 m_variables[key] = value;
276template<
typename Type>
278 typename std::map<std::string, Type>::iterator iter = m_variables.find(key);
280 if (iter != m_variables.end())
281 m_variables.erase(iter);
290template<
typename Type>
292 std::ostringstream value;
293 value <<
"map:" << m_label;
294 typename std::map<std::string, Type>::const_iterator iter;
295 for (iter = m_variables.begin(); iter != m_variables.end(); ++iter)
296 value <<
" " << iter->first <<
":" << iter->second;
306 std::ostringstream value;
307 value <<
"map:" << m_label;
308 std::map<std::string, std::string>::const_iterator iter;
309 for (iter = m_variables.begin(); iter != m_variables.end(); ++iter) {
310 std::string var = iter->second;
312 value <<
" " << iter->first <<
":\"" << var <<
"\"";
369 StringMap *GetStringMapVar(
const std::string &name,
370 const std::string &label =
"");
371 IntMap *GetIntMapVar(
const std::string &name,
const std::string &label =
"");
372 UIntMap *GetUIntMapVar(
const std::string &name,
373 const std::string &label =
"");
382 template<
typename Type>
383 Type *GetVar(std::map<std::string, Type*> *var_map,
384 const std::string &name);
386 template<
typename Type>
387 Type *GetMapVar(std::map<std::string, Type*> *var_map,
388 const std::string &name,
389 const std::string &label);
391 std::map<std::string, BoolVariable*> m_bool_variables;
392 std::map<std::string, CounterVariable*> m_counter_variables;
393 std::map<std::string, IntegerVariable*> m_int_variables;
394 std::map<std::string, StringVariable*> m_string_variables;
396 std::map<std::string, StringMap*> m_str_map_variables;
397 std::map<std::string, IntMap*> m_int_map_variables;
398 std::map<std::string, UIntMap*> m_uint_map_variables;
Various string utility functions.
The base variable class.
Definition ExportMap.h:51
virtual ~BaseVariable()
Definition ExportMap.h:62
BaseVariable(const std::string &name)
Create a new BaseVariable.
Definition ExportMap.h:57
virtual const std::string Value() const =0
Return the value of the variable as a string.
const std::string Name() const
Return the name of this variable.
Definition ExportMap.h:68
A boolean variable.
Definition ExportMap.h:92
void Set(bool value)
Set the value of the variable.
Definition ExportMap.h:107
BoolVariable(const std::string &name)
Create a new BoolVariable.
Definition ExportMap.h:98
const std::string Value() const
Get the value of this variable as a string.
Definition ExportMap.h:121
bool Get() const
Get the value of this variable.
Definition ExportMap.h:113
Definition ExportMap.h:176
const std::string Value() const
Return the value of the variable as a string.
Definition ExportMap.h:187
A container for the exported variables.
Definition ExportMap.h:324
StringVariable * GetStringVar(const std::string &name)
Lookup or create a StringVariable.
Definition ExportMap.cpp:59
BoolVariable * GetBoolVar(const std::string &name)
Lookup or create a BoolVariable.
Definition ExportMap.cpp:47
std::vector< BaseVariable * > AllVariables() const
Fetch a list of all known variables.
Definition ExportMap.cpp:101
CounterVariable * GetCounterVar(const std::string &name)
Lookup or create a CounterVariable.
Definition ExportMap.cpp:55
IntegerVariable * GetIntegerVar(const std::string &name)
Lookup or create an IntegerVariable.
Definition ExportMap.cpp:51
Definition ExportMap.h:228
Definition ExportMap.h:150
const std::string Value() const
Return the value of the variable as a string.
Definition ExportMap.h:162
Definition ExportMap.h:202
void Remove(const std::string &key)
Definition ExportMap.h:277
const std::string Value() const
Return the value of the variable as a string.
Definition ExportMap.h:291
Definition ExportMap.h:131
const std::string Value() const
Return the value of the variable as a string.
Definition ExportMap.h:140
Definition ExportMap.h:242
The namespace containing all OLA symbols.
Definition Credentials.cpp:44
void Escape(string *original)
Escape a string with \ .
Definition StringUtils.cpp:249
Definition ExportMap.h:81