<?xml?>

<tm2>

  <typedef id="gwen_time" type="pointer" lang="c" >
    <identifier>GWEN_TIME</identifier>
    <aqdb_type>AQDB_DataType_Date</aqdb_type>


    <codedefs>

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

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

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

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

      <codedef id="compare">
        <code>
          if ($(dst) &amp;&amp; $(src))
            $(retval)=GWEN_Time_Compare($(src), $(dst));
          else if ($(src))
            $(retval)=1;
          else if ($(dst))
            $(retval)=-1;
          else
            $(retval)=0;
        </code>
      </codedef>

      <codedef id="toXml">
        <!-- !attribute -->
        <memberFlagsMask>  attribute</memberFlagsMask>
        <memberFlagsValue>          </memberFlagsValue>
        <code>
          if ($(src)){
            GWEN_BUFFER *xbuf;
            int rv;
  
            xbuf=GWEN_Buffer_new(0, 32, 0, 1);
            rv=GWEN_Time_toString($(src), "YYYY/MM/DD-hh:mm", xbuf);
            if (rv&gt;=0) 
              GWEN_XMLNode_SetCharValue($(db), "$(name)", GWEN_Buffer_GetStart(xbuf));
            GWEN_Buffer_free(xbuf);
          }
        </code>
      </codedef>

      <codedef id="toXml">
        <!-- attribute -->
        <memberFlagsMask>  attribute</memberFlagsMask>
        <memberFlagsValue> attribute</memberFlagsValue>
        <code>
          if ($(src)){
            GWEN_BUFFER *xbuf;
            int rv;
  
            xbuf=GWEN_Buffer_new(0, 32, 0, 1);
            rv=GWEN_Time_toString($(src), "YYYY/MM/DD-hh:mm", xbuf);
            if (rv&gt;=0) 
              GWEN_XMLNode_SetProperty($(db), "$(name)", GWEN_Buffer_GetStart(xbuf));
            GWEN_Buffer_free(xbuf);
          }
        </code>
      </codedef>

      <codedef id="fromXml">
        <!-- !attribute -->
        <memberFlagsMask>  attribute</memberFlagsMask>
        <memberFlagsValue>          </memberFlagsValue>
        <code>
          {
            const char *s;
            
            s=GWEN_XMLNode_GetCharValue($(db), "$(name)", NULL);
            if (s && *s)
              $(dst)=GWEN_Time_fromString(s, "YYYY/MM/DD-hh:mm");
          }
        </code>
      </codedef>

      <codedef id="fromXml">
        <!-- enum | attribute -->
        <memberFlagsMask>  attribute</memberFlagsMask>
        <memberFlagsValue> attribute</memberFlagsValue>
        <code>
          {
            const char *s;
            
            s=GWEN_XMLNode_GetProperty($(db), "$(name)", NULL);
            if (s && *s)
              $(dst)=GWEN_Time_fromString(s, "YYYY/MM/DD-hh:mm");
          }
        </code>
      </codedef>



      <codedef id="toDb">
        <code>
          if ($(src)){
            GWEN_DB_NODE *dbDest;
            
            dbDest=GWEN_DB_GetGroup($(db), GWEN_DB_FLAGS_OVERWRITE_GROUPS, "$(name)");
            assert(dbDest);
            $(retval)=GWEN_Time_toDb($(src), dbDest);
          }
          else
            $(retval)=0;
        </code>
      </codedef>



      <codedef id="fromDb">
        <code>
          {
            GWEN_DB_NODE *dbDest;
            
            dbDest=GWEN_DB_GetGroup($(db), GWEN_PATH_FLAGS_NAMEMUSTEXIST, "$(name)");
            if (dbDest)
              $(dst)=GWEN_Time_fromDb(dbDest);
          }
        </code>
      </codedef>



      <codedef id="toObject">
        <code>
          if ($(src)){
            GWEN_BUFFER *xbuf=GWEN_Buffer_new(0, 64, 0, 1);
            $(retval)=GWEN_Time_toUtcString($(src), "YYYYMMDD-hhmmss", xbuf);
            if ($(retval)&gt;=0)
              $(retval)=AQDB_Object_SetFieldString($(db), $(fieldid), GWEN_Buffer_GetStart(xbuf));
            GWEN_Buffer_free(xbuf);
          }
          else
            $(retval)=0;
        </code>
      </codedef>



      <codedef id="fromObject">
        <code>
          {
            const char *s;
            
            $(retval)=AQDB_Object_GetFieldString($(db), $(fieldid), &s);
            if ($(retval)&gt;=0 && s && *s) {
              $(dst)=GWEN_Time_fromUtcString(s, "YYYYMMDD-hhmmss");
              if ($(dst)==NULL)
                $(retval)=GWEN_ERROR_BAD_DATA;
            }
            else
              $(retval)=0;
          }
        </code>
      </codedef>



      <codedef id="toHashString">
        <code>
          if ($(src))
            GWEN_Time_toUtcString($(src), "YYYY/MM/DD-hh:mm", $(buffer));
        </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>
