ConfigManager.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2016 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00024 //----------------------------------------------------------------------
00025 #ifndef ICL_CORE_CONFIG_CONFIG_MANAGER_H_INCLUDED
00026 #define ICL_CORE_CONFIG_CONFIG_MANAGER_H_INCLUDED
00027 
00028 #include <icl_core/BaseTypes.h>
00029 #include <icl_core/List.h>
00030 #include <icl_core/Map.h>
00031 #include <icl_core/TemplateHelper.h>
00032 #include "icl_core_config/ConfigIterator.h"
00033 #include "icl_core_config/ConfigParameter.h"
00034 #include "icl_core_config/ConfigPositionalParameter.h"
00035 #include "icl_core_config/ImportExport.h"
00036 #include "icl_core_config/AttributeTree.h"
00037 
00038 #include <boost/lexical_cast.hpp>
00039 
00040 #include <cassert>
00041 
00042 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00043 # include "icl_core/Deprecate.h"
00044 #endif
00045 
00046 class TiXmlNode;
00047 
00048 namespace icl_core {
00049 namespace config {
00050 
00051 class AttributeTree;
00052 class ConfigObserver;
00053 
00055 
00079 class ICL_CORE_CONFIG_IMPORT_EXPORT ConfigManager: public icl_core::KeyValueDirectory<icl_core::String>
00080 {
00081 public:
00085   static ConfigManager& instance();
00086 
00090   void addParameter(const ConfigParameter& parameter);
00094   void addParameter(const ConfigParameterList& parameters);
00095 
00099   void addParameter(const ConfigPositionalParameter& parameter);
00103   void addParameter(const ConfigPositionalParameterList& parameters);
00104 
00115   bool initialize();
00116 
00120   bool isInitialized() const
00121   {
00122     return m_initialized;
00123   }
00124 
00129   void dump() const;
00130 
00132   template <class T>
00133   bool setValue(const icl_core::String &key, typename icl_core::ConvertToRef<T>::ToConstRef value)
00134   {
00135     icl_core::String string_value = boost::lexical_cast<icl_core::String>(value);
00136 
00137     if (key == "/configfile")
00138     {
00139       load(string_value);
00140     }
00141 
00142     bool result = insert(key, string_value);
00143     notify(key);
00144     return result;
00145   }
00146 
00151   void registerObserver(ConfigObserver *observer, const String &key = "");
00152 
00157   void unregisterObserver(ConfigObserver *observer);
00158 
00160 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00161 
00165   static ICL_CORE_VC_DEPRECATE_STYLE ConfigManager& Instance() ICL_CORE_GCC_DEPRECATE_STYLE;
00166 
00170   ICL_CORE_VC_DEPRECATE_STYLE void AddParameter(const ConfigParameter& parameter) ICL_CORE_GCC_DEPRECATE_STYLE;
00171 
00175   ICL_CORE_VC_DEPRECATE_STYLE void AddParameter(const ConfigParameterList& parameters) ICL_CORE_GCC_DEPRECATE_STYLE;
00176 
00180   ICL_CORE_VC_DEPRECATE_STYLE bool Initialize() ICL_CORE_GCC_DEPRECATE_STYLE;
00181 
00186   ICL_CORE_VC_DEPRECATE_STYLE bool IsInitialized() const ICL_CORE_GCC_DEPRECATE_STYLE;
00187 
00192   ICL_CORE_VC_DEPRECATE_STYLE void Dump() const ICL_CORE_GCC_DEPRECATE_STYLE;
00193 
00197   template <class T>
00198   bool SetValue(const icl_core::String &key,
00199                 typename icl_core::ConvertToRef<T>::ToConstRef value)
00200     ICL_CORE_GCC_DEPRECATE_STYLE;
00201 
00206   ICL_CORE_VC_DEPRECATE_STYLE void RegisterObserver(ConfigObserver *observer, const String &key = "")
00207     ICL_CORE_GCC_DEPRECATE_STYLE;
00208 
00213   ICL_CORE_VC_DEPRECATE_STYLE void UnregisterObserver(ConfigObserver *observer)
00214     ICL_CORE_GCC_DEPRECATE_STYLE;
00215 
00216 #endif
00217 
00218 
00219 private:
00221   ConfigManager();
00222 
00224   bool load(const icl_core::String& filename);
00225 
00227   void notify(const icl_core::String &key) const;
00228 
00229   void readXml(const ::icl_core::String& prefix, TiXmlNode *node, FilePath fp, bool extend_prefix = true);
00230   void readAttributeTree(const icl_core::String& prefix, AttributeTree *at, bool extend_prefix = true);
00231 
00232   //typedef ::icl_core::Map< ::icl_core::String, ::icl_core::String> KeyValueMap;
00233   //KeyValueMap m_config_items;
00234   bool m_initialized;
00235 
00236   ConfigParameterList m_parameter_list;
00237   ConfigPositionalParameterList m_postional_parameter_list;
00238 
00239   typedef icl_core::Map<icl_core::String, icl_core::List<ConfigObserver*> > ObserverMap;
00240   ObserverMap m_observers;
00241 };
00242 
00244 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00245 
00246 template <class T> ICL_CORE_VC_DEPRECATE_STYLE
00247 bool ConfigManager::SetValue(const icl_core::String &key,
00248                              typename icl_core::ConvertToRef<T>::ToConstRef value)
00249 {
00250   return setValue<T>(key, value);
00251 }
00252 
00253 #endif
00254 
00255 
00256 }
00257 }
00258 
00259 #endif


fzi_icl_core
Author(s):
autogenerated on Tue Aug 8 2017 02:28:03