37 template class KeyValueDirectory<String>;
52 m_parameter_list.push_back(parameter);
56 Getopt::instance().addParameter(parameter);
61 for (ConfigParameterList::const_iterator it = parameters.begin(); it != parameters.end(); ++it)
72 m_postional_parameter_list.push_back(parameter);
76 Getopt::instance().addParameter(parameter);
81 for (ConfigPositionalParameterList::const_iterator it = parameters.begin(); it != parameters.end(); ++it)
91 std::cerr <<
"CONFIG WARNING: The configuration framework is already initialized!" <<
std::endl;
101 std::cerr <<
"CONFIG ERROR: The configuration file '" << filename <<
"' could not be loaded!" 110 for (ConfigParameterList::const_iterator it = m_parameter_list.begin(); it != m_parameter_list.end(); ++it)
112 if (it->configKey() !=
"")
115 if (Getopt::instance().paramOptPresent(it->option()))
117 insert(it->configKey(), Getopt::instance().paramOpt(it->option()));
118 notify(it->configKey());
121 else if (!hasKey(it->configKey()) && it->hasDefaultValue())
123 insert(it->configKey(), it->defaultValue());
124 notify(it->configKey());
130 for (ConfigPositionalParameterList::const_iterator it = m_postional_parameter_list.begin(); it != m_postional_parameter_list.end(); ++it)
132 if (it->configKey() !=
"")
135 if (Getopt::instance().paramOptPresent(it->name()))
137 insert(it->configKey(), Getopt::instance().paramOpt(it->name()));
138 notify(it->configKey());
141 else if (!hasKey(it->configKey()) && it->hasDefaultValue())
143 insert(it->configKey(), it->defaultValue());
144 notify(it->configKey());
151 for (Getopt::KeyValueList::const_iterator it = option_params.begin(); it != option_params.end(); ++it)
153 insert(it->m_key, it->m_value);
163 m_initialized =
true;
169 std::cout <<
"--- BEGIN CONFIGURATION DUMP ---" <<
std::endl;
175 std::cout <<
"--- END CONFIGURATION DUMP ---" <<
std::endl;
178 ConfigManager::ConfigManager()
179 : m_initialized(false)
182 "Specifies the path to the configuration file."));
184 "Dump the configuration read from the configuration file."));
186 "Overwrite a configuration option.",
true));
193 if (fp.extension() ==
".AttributeTree" || fp.extension() ==
".tree")
196 int res = attribute_tree.
load(filename.c_str());
207 std::cerr <<
"CONFIG ERROR: Could not load configuration file '" << filename <<
std::endl;
213 TiXmlDocument doc(filename.c_str());
216 TiXmlElement *root_element = doc.RootElement();
217 if (root_element != 0)
219 readXml(
"", root_element, fp,
false);
225 std::cerr <<
"CONFIG ERROR: Could not load configuration file '" << filename <<
"' (" << doc.ErrorRow()
226 <<
", " << doc.ErrorCol() <<
"): " << doc.ErrorDesc() <<
std::endl;
238 fq_node_name = prefix +
"/" + node_name;
241 TiXmlNode *child = node->IterateChildren(NULL);
244 if (child->Type() == TiXmlNode::TINYXML_ELEMENT)
246 if (strcmp(child->Value(),
"INCLUDE") == 0)
248 TiXmlElement *child_element =
dynamic_cast<TiXmlElement*
>(child);
249 assert(child_element != NULL);
250 const char *included_file = child_element->GetText();
251 if (included_file != NULL)
258 readXml(fq_node_name, child, fp);
261 else if (child->Type() == TiXmlNode::TINYXML_TEXT)
263 insert(fq_node_name, child->Value());
267 child = node->IterateChildren(child);
281 fq_node_name = prefix +
"/" + node_name;
291 while (child != NULL)
300 assert(observer &&
"Null must not be passed as config observer");
312 else if (
find(key).next())
320 assert(observer &&
"Null must not be passed as config observer");
325 iter->second.remove(observer);
330 #ifdef _IC_BUILDER_DEPRECATED_STYLE_ 368 bool ConfigManager::IsInitialized()
const 408 ObserverMap::const_iterator find_it =
m_observers.find(key);
411 observers.insert(observers.end(), find_it->second.begin(), find_it->second.end());
416 observers.insert(observers.end(), find_it->second.begin(), find_it->second.end());
420 for (iter = observers.begin(); iter != observers.end(); ++iter)
422 (*iter)->valueChanged(key);
static ConfigManager & instance()
bool initialize(int &argc, char *argv[], bool remove_read_arguments)
bool insert(const String &key, typename ConvertToRef< icl_core::String >::ToConstRef value)
Class for handling configuration files.
Interface for observing configuration changes.
const char * getDescription() const
ICL_CORE_VC_DEPRECATE_STYLE void AddParameter(const ConfigParameter ¶meter) ICL_CORE_GCC_DEPRECATE_STYLE
int load(const char *filename, bool unmark_changes=true, bool process_include=true, bool load_comments=false, bool preserve_order=false)
void registerObserver(ConfigObserver *observer, const String &key="")
Base header file for the configuration framework.
icl_core::String configKey() const
void readAttributeTree(const icl_core::String &prefix, AttributeTree *at, bool extend_prefix=true)
void notify(const icl_core::String &key) const
Notify all observers about a changed key/value pair.
ICL_CORE_VC_DEPRECATE_STYLE bool Initialize(int &argc, char *argv[], bool remove_read_arguments) ICL_CORE_GCC_DEPRECATE_STYLE
icl_core::String configKey() const
void addParameter(const ConfigParameter ¶meter)
AttributeTree * nextSubTree(AttributeTree *subtree)
ICL_CORE_VC_DEPRECATE_STYLE void Dump() ICL_CORE_GCC_DEPRECATE_STYLE
KeyValueDirectoryIterator< T > find(const String &query) const
ThreadStream & endl(ThreadStream &stream)
const char * CONFIGFILE_CONFIG_KEY
ConfigIterator find(const ::icl_core::String &query)
void addParameter(const ConfigParameter ¶meter)
Contains KeyValueDirectory.
void readXml(const ::icl_core::String &prefix, TiXmlNode *node, FilePath fp, bool extend_prefix=true)
virtual void valueChanged(const icl_core::String &key)=0
static Getopt & instance()
bool load(const icl_core::String &filename)
Reads configuration from a file.
bool isInitialized() const
const char * attribute() const
ConvertToRef< T >::ToConstRef value() const
icl_core::String path() const
void addParameter(const GetoptParameter ¶meter)
bool paramOptPresent(const icl_core::String &name)
AttributeTree * firstSubTree()
Reads a configuration file in the old MCA attribute tree format.
void unregisterObserver(ConfigObserver *observer)