<?xml?>

<tm2>

  <typedef id="list2_base" type="pointer" lang="c" >

    <codedefs>

      <codedef id="construct">
        <code>
          $(dst)=$(preset);
        </code>
      </codedef>

      <codedef id="destruct">
        <code>
          $(member_prefix)_free($(src));
          $(src)=NULL;
        </code>
      </codedef>

      <codedef id="assign">
        <code>
          $(dst)=$(src);
        </code>
      </codedef>

      <codedef id="dup">
        <code>
          $(dst)=$(member_prefix)_dup($(src));
        </code>
      </codedef>

      <codedef id="compare">
        <code>
        </code>
      </codedef>

      <codedef id="toXml">
        <code>
          {
            if ($(src)) {
              GWEN_XMLNODE *dbDest;
              $(member_basetype_type)_LIST2_ITERATOR *it;
              
              dbDest=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "$(name)");
              it=$(member_prefix)_List2__First($(src));
              if (it) {
                $(member_basetype_type) *elem;
                
                elem=$(member_prefix)Iterator_Data(it);
                while(elem) {
                  GWEN_XMLNODE *dbElem;
                
                  dbElem=GWEN_XMLNode_new(GWEN_XMLNodeTypeTag, "$(element_name)");
                  assert(dbElem);
                  $(member_basetype_prefix)_toXml(elem, dbElem);
                  GWEN_XMLNode_AddChild(dbDest, dbElem);
                  elem=$(member_prefix)Iterator_Next(it);
                }
                $(member_prefix)Iterator_free(it);
              }
              
              GWEN_XMLNode_AddChild($(db), dbDest);
            }
          }
        </code>
      </codedef>


      <codedef id="fromXml">
        <code>
           {
            GWEN_XMLNODE *dbSource;
            
            dbSource=GWEN_XMLNode_FindFirstTag($(db), "$(name)", NULL, NULL);
            if (dbSource) {
              $(member_type) *t;
              GWEN_XMLNODE *dbT;
              
              t=$(member_prefix)_new();
              dbT=GWEN_XMLNode_FindFirstTag(dbSource, "$(element_name)", NULL, NULL);
              while(dbT) {
                $(member_basetype_type) *elem;
                
                elem=$(member_basetype_prefix)_fromXml(dbT);
                if (elem)
                  $(member_prefix)_PushBack(t, elem);
                dbT=GWEN_XMLNode_FindNextTag(dbT, "$(element_name)", NULL, NULL);
              }
              $(dst)=t;
            }
            else
              $(dst)=$(preset);
          }
        </code>
      </codedef>



      <codedef id="toObject">
        <code>
        </code>
      </codedef>



      <codedef id="fromObject">
        <code>
        </code>
      </codedef>



      <codedef id="toDb">
        <code>
          {
            if ($(src)) {
              GWEN_DB_NODE *dbDest;
              $(member_basetype_type)_LIST2_ITERATOR *it;
              
             
              dbDest=GWEN_DB_GetGroup($(db), GWEN_DB_FLAGS_OVERWRITE_GROUPS, "$(name)");
              assert(dbDest);
              
              it=$(member_prefix)_First($(src));
              if (it) {
                $(member_basetype_type) *elem;

                $(retval)=0;
                
                elem=$(member_prefix)Iterator_Data(it);
                while(elem) {
                  GWEN_DB_NODE *dbElem;
                  
                  dbElem=GWEN_DB_GetGroup(dbDest, GWEN_PATH_FLAGS_CREATE_GROUP, "$(element_name)");
                  assert(dbElem);
                  $(retval)=$(member_basetype_prefix)_toDb(elem, dbElem);
                  if ($(retval)&lt;0) {
                    DBG_INFO(GWEN_LOGDOMAIN, "here (%d)", $(retval));
                    break;
                  }
                  elem=$(member_prefix)Iterator_Next(it);
                }
                $(member_prefix)Iterator_free(it);
              }
            }
            else
              $(retval)=0;
          }
        </code>
      </codedef>



      <codedef id="fromDb">
        <code>
          {
            GWEN_DB_NODE *dbSource;
            
            dbSource=GWEN_DB_GetGroup($(db), GWEN_PATH_FLAGS_NAMEMUSTEXIST, "$(name)");
            if (dbSource) {
              $(member_type) *t;
              GWEN_DB_NODE *dbT;
              
              t=$(member_prefix)_new();
              dbT=GWEN_DB_FindFirstGroup(dbSource, "$(element_name)");
              while(dbT) {
                $(member_basetype_type) *elem;
                
                elem=$(member_basetype_prefix)_fromDb(dbT);
                if (elem)
                  $(member_prefix)_PushBack(t, elem);
                dbT=GWEN_DB_FindNextGroup(dbT, "$(element_name)");
              }
              $(dst)=t;
            }
            else
              $(dst)=$(preset);
          }
        </code>
      </codedef>


    </codedefs>



    <defaults>
      <!-- defaults flags etc for member declarations of this type -->
      <default>NULL</default>
      <preset>NULL</preset>
      <setflags>const dup</setflags>
      <getflags>const</getflags>
      <dupflags>const</dupflags>
    </defaults>
  
  </typedef>

</tm2>
