コード例 #1
0
ファイル: dmzRuntimeConfig.cpp プロジェクト: ben-sangster/dmz
/*!

\brief Looks up all config contexts with the given name.
\details All config context found with a matching name are stored as children of \a data.
\param[in] Name String containing name of config contexts to lookup.
\param[out] data Config to store the found config contexts.
\return Returns dmz::True if any config contexts were found.

*/
dmz::Boolean
dmz::Config::lookup_all_config (const String &Name, Config &data) const {

   Boolean result (False);
   StringTokenizer it (Name, LocalScopeChar);
   String sub = it.get_next ();
   Boolean done (!sub ? True : False);

   Config prev ("prev");
   prev.add_config (*this);
   Config current (sub);

   while (!done) {

      ConfigIterator tableIt;
      Config next;

      ConfigContext *curContext = current.get_config_context ();

      while (prev.get_next_config (tableIt, next)) {

         ConfigContext *nextContext = next.get_config_context ();

         if (nextContext && curContext) {

            ConfigContext::DataList *dl (nextContext->configTable.lookup (sub));

            if (dl) {

               dl->lock.lock ();
                  ConfigContext::DataStruct *ds = dl->head;
                  while (ds) {

                     if (ds->handle) {

                        curContext->add_config (ds->context);
                     }

                     ds = ds->next;
                  }
               dl->lock.unlock ();
            }
         }
      }

      if (current.is_empty ()) { done = True; }
      else {

         sub = it.get_next ();
         if (!sub) { data = current; done = True; result = True; }
         else { prev = current; Config next (sub); current = next; }
      }
   }

   if (data.is_empty ()) { data.set_config_context (0); result = False; }

   return result;
}
コード例 #2
0
ファイル: dmzRuntimeConfig.cpp プロジェクト: ben-sangster/dmz
/*!

\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;
}