/*! \brief Store a name-value pair in the config context. \details If an attribute with \a Name already exists, the value is over-written. The \a Name parameter may be used to store an attribute in child config contexts. For example the following code snippet: \code dmz::Config dataDMZ; if (global.lookup_data ("dmz", dataDMZ)) { dmz::Config dataType if (dataDMZ.lookup_data ("type", dataType)) { const dmz::String Value ("This is the tag value"); dataType.store_attribute ("tag", Value); } } \endcode May also be written as: \code const dmz::String Value ("This is the tag value"); global.store_attribute ("dmz.type.tag", Value); \endcode Any child config context that is named in the scope of the attribute \a Name that does not exist will be created. For example, in the above code sample, if the child config context named "type" does not exist, it will be created and added to the config context named "dmz". \param[in] Name String containing the name of the attribute. \param[in] Value String containing the value of the attribute. \return Returns dmz::True if the attribute was stored successfully. */ dmz::Boolean dmz::Config::store_attribute (const String &Name, const String &Value) { Boolean result (False); if (_state.context && Name) { String dataName; String attrName; if (!pop_last_config_scope_element (Name, dataName, attrName)) { attrName = Name; } ConfigContext *context (0); if (dataName) { context = local_get_config_from_scope (dataName, _state.context, True); } else { context = _state.context; } if (context) { ConfigAttributeContext *ac (context->attrTable.lookup (attrName)); if (!ac) { ac = new ConfigAttributeContext (Value); if (ac && context->attrTable.store (attrName, ac)) { result = True; } else if (ac) { delete ac; ac = 0; } } else { result = True; ac->lock.lock (); ac->value = Value; ac->lock.unlock (); } } } return result; }
/*! \brief Adds a config context. \details The \a Scope parameter may be used to add a config context to child config contexts. For example the following code snippet: \code dmz::Config dataDMZ; if (global.lookup_data ("dmz", dataDMZ)) { dmz::Config dataType if (dataDMZ.lookup_data ("type", dataType)) { Config fooData ("foo"); dataType.add_config (fooData); } } \endcode May also be written as: \code Config fooData ("foo"); global.add_config ("dmz.type", fooData); \endcode \param[in] Scope String containing the scope at witch to add the config context. \param[in] Data Config containing config context to add. \return Returns dmz::True if the config context was successfully added. */ dmz::Boolean dmz::Config::add_config (const String &Scope, const Config &Data) { Boolean result (False); if (_state.context && _state.context->Name) { ConfigContext *cd = Data.get_config_context (); ConfigContext *target = local_get_config_from_scope (Scope, _state.context, True); if (cd && target) { result = target->add_config (cd); } } return result; }