ConfigManager.h
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // This file is part of FZIs ic_workspace.
5 //
6 // This program is free software licensed under the LGPL
7 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
8 // You can find a copy of this license in LICENSE folder in the top
9 // directory of the source code.
10 //
11 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
12 //
13 // -- END LICENSE BLOCK ------------------------------------------------
14 
15 //----------------------------------------------------------------------
24 //----------------------------------------------------------------------
25 #ifndef ICL_CORE_CONFIG_CONFIG_MANAGER_H_INCLUDED
26 #define ICL_CORE_CONFIG_CONFIG_MANAGER_H_INCLUDED
27 
28 #include <icl_core/BaseTypes.h>
29 #include <icl_core/List.h>
30 #include <icl_core/Map.h>
37 
38 #include <boost/lexical_cast.hpp>
39 
40 #include <cassert>
41 
42 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
43 # include "icl_core/Deprecate.h"
44 #endif
45 
46 class TiXmlNode;
47 
48 namespace icl_core {
49 namespace config {
50 
51 class AttributeTree;
52 class ConfigObserver;
53 
55 
80 {
81 public:
85  static ConfigManager& instance();
86 
90  void addParameter(const ConfigParameter& parameter);
94  void addParameter(const ConfigParameterList& parameters);
95 
99  void addParameter(const ConfigPositionalParameter& parameter);
103  void addParameter(const ConfigPositionalParameterList& parameters);
104 
115  bool initialize();
116 
120  bool isInitialized() const
121  {
122  return m_initialized;
123  }
124 
129  void dump() const;
130 
132  template <class T>
134  {
135  icl_core::String string_value = boost::lexical_cast<icl_core::String>(value);
136 
137  if (key == "/configfile")
138  {
139  load(string_value);
140  }
141 
142  bool result = insert(key, string_value);
143  notify(key);
144  return result;
145  }
146 
151  void registerObserver(ConfigObserver *observer, const String &key = "");
152 
157  void unregisterObserver(ConfigObserver *observer);
158 
160 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
161 
166 
171 
176 
181 
187 
193 
197  template <class T>
198  bool SetValue(const icl_core::String &key,
201 
206  ICL_CORE_VC_DEPRECATE_STYLE void RegisterObserver(ConfigObserver *observer, const String &key = "")
208 
213  ICL_CORE_VC_DEPRECATE_STYLE void UnregisterObserver(ConfigObserver *observer)
215 
216 #endif
217 
219 private:
221  ConfigManager();
222 
224  bool load(const icl_core::String& filename);
225 
227  void notify(const icl_core::String &key) const;
228 
229  void readXml(const ::icl_core::String& prefix, TiXmlNode *node, FilePath fp, bool extend_prefix = true);
230  void readAttributeTree(const icl_core::String& prefix, AttributeTree *at, bool extend_prefix = true);
231 
232  //typedef ::icl_core::Map< ::icl_core::String, ::icl_core::String> KeyValueMap;
233  //KeyValueMap m_config_items;
235 
238 
240  ObserverMap m_observers;
241 };
242 
244 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
245 
246 template <class T> ICL_CORE_VC_DEPRECATE_STYLE
249 {
250  return setValue<T>(key, value);
251 }
252 
253 #endif
254 
256 }
257 }
258 
259 #endif
ConfigPositionalParameterList m_postional_parameter_list
Helper definitions for template programming.
bool initialize(int &argc, char *argv[], bool remove_read_arguments)
Definition: Config.cpp:50
#define ICL_CORE_VC_DEPRECATE_STYLE
Definition: Deprecate.h:53
Contains ConfigParameter.
Class for handling configuration files.
Definition: ConfigManager.h:79
Interface for observing configuration changes.
#define ICL_CORE_CONFIG_IMPORT_EXPORT
Contains macros to deprecate classes, types, functions and variables.
Contains ConfigPositionalParameter.
ICL_CORE_VC_DEPRECATE_STYLE void AddParameter(const ConfigParameter &parameter) ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Config.h:872
void SetValue(const icl_core::String &key, typename icl_core::ConvertToRef< T >::ToConstRef value) ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Config.h:744
icl_core::Map< icl_core::String, icl_core::List< ConfigObserver * > > ObserverMap
ICL_CORE_VC_DEPRECATE_STYLE bool Initialize(int &argc, char *argv[], bool remove_read_arguments) ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Config.h:902
ICL_CORE_VC_DEPRECATE_STYLE void Dump() ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Config.h:609
ConfigParameterList m_parameter_list
Contains import/export definitions for the Win32 plattform.
void addParameter(const ConfigParameter &parameter)
Definition: Config.h:541
std::string String
Definition: BaseTypes.h:43
Contains Interface base classes and base types.
Contains ConfigIterator.
bool setValue(const icl_core::String &key, typename icl_core::ConvertToRef< T >::ToConstRef value)
Add a key/value pair or change a value. In contrast to Insert, this method notifies observers...
Reads a configuration file in the old MCA attribute tree format.
#define ICL_CORE_GCC_DEPRECATE_STYLE
Definition: Deprecate.h:54


fzi_icl_core
Author(s):
autogenerated on Mon Jun 10 2019 13:17:58