/*! \brief Removes config contexts found at the specified scope path. \param[in] Scope String containing scope to use when overwriting. \return Returns dmz::True if config context was successfully removed. */ dmz::Boolean dmz::Config::remove_config (const String &Scope) { Boolean result = False; if (Scope) { result = True; String value, remainder; if (pop_last_config_scope_element (Scope, value, remainder)) { Config list; lookup_all_config (remainder, list); ConfigIterator it; Config cd; while (list.get_next_config (it, cd)) { ConfigContext *context (cd.get_config_context ()); if (context) { context->remove_config (value); } } } else if (_state.context) { _state.context->remove_config (Scope); } } return result; }
/*! \brief Removes an attribute from the Config. \details The \a Name parameter may be scoped. \param[in] Name String containing name of attribute to remove. \param[out] value String used to return value of attribute if removed. \return Returns dmz::True if an attribute with \a Name is removed. */ dmz::Boolean dmz::Config::remove_attribute (const String &Name, String &value) { Boolean result (False); if (_state.context) { String dataName; String attrName; if (!pop_last_config_scope_element (Name, dataName, attrName)) { attrName = Name; } Config cd; if (dataName) { lookup_config (dataName, cd); } else { cd = *this; } if (cd) { ConfigAttributeContext *ac = cd._state.context->attrTable.lookup (attrName); if (ac) { ac->lock.lock (); value = ac->value; ac->value.empty (); ac->lock.unlock (); if (value.get_buffer ()) { result = True; } } } } return result; }
/*! \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; }