Ejemplo n.º 1
0
/*!

\brief Converts Data to Config.
\details Defined in dmzRuntimeConfigWrite.h.
\note Unlike the config_to_* functions, the \a Name parameter can not be scoped.
The \a Name parameter should not contain "." characters.
\param[in] Source Data object to convert.
\param[in] context Pointer to the runtime context.
\param[in] log Pointer to the Log to be used for log messages.
\return Returns a Config object containing the converted Data object.
\sa config_to_data(const String &Name, const Config &Source, RuntimeContext *context, Data &target, Log *log)

*/
dmz::Config
dmz::data_to_config (
     const String &Name,
     const Data &Source,
     RuntimeContext *context,
     Log *log) {

   Config result (Name);

   Definitions defs (context);

   RuntimeIterator it;

   Handle handle (Source.get_first_attribute (it));

   while (handle) {

      Config attr ("attribute");

      attr.store_attribute ("name", defs.lookup_named_handle_name (handle));
      attr.store_attribute (
         "type",
         base_type_enum_to_string (Source.lookup_attribute_base_type_enum (handle)));

      result.add_config (attr);

      const Int32 ElementCount (Source.lookup_attribute_element_count (handle));

      for (Int32 ix = 0; ix < ElementCount; ix++) {

         Config element ("element");

         String value;
         Source.lookup_string (handle, ix, value);
         element.store_attribute ("value", value);

         attr.add_config (element);
      }

      handle = Source.get_next_attribute (it);
   }

   return result;
}
Ejemplo n.º 2
0
//! Write a Data object to the Stream.
Stream &
operator<< (Stream &stream, const Data &Value) {

      stream << "dmz::Data object" << endl;

      RuntimeContext *context (Value.get_runtime_context ());
      Definitions defs (context);

      DataIterator it;

      String buffer;
      buffer.repeat (" ", 3);

      for (
            Handle handle = Value.get_first_attribute (it);
            handle;
            handle = Value.get_next_attribute (it)) {

         if (context) {

            stream << buffer << defs.lookup_named_handle_name (handle)
               << "[" << handle << "]" << " =";
         }
         else { stream << buffer << handle << " ="; }

         const Int32 Elements (Value.lookup_attribute_element_count (handle));

         for (Int32 ix = 0; ix < Elements; ix++) {

            String value;
            if (Value.lookup_string (handle, ix, value)) {

               stream << " '" << value << "'";
            }
            else { stream << " " << "<undefined element>"; }
         }
         stream << ";" << endl;
      }

   return stream;
}