<?xml?>

<tm2>
  <typedef id="AB_VALUE" lang="c" type="pointer" >
    <identifier>AB_VALUE</identifier>
    <prefix>AB_Value</prefix>
    <aqdb_type>AQDB_DataType_Amount</aqdb_type>
  
    <codedefs>

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

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

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

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

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

        </code>
      </codedef>

      <codedef id="toXml">
        <!-- !attribute -->
        <code>
          if ($(src)) {
            GWEN_BUFFER *tbuf=GWEN_Buffer_new(0, 64, 0, 1);
        
            AB_Value_toString($(src), tbuf);
            GWEN_XMLNode_SetCharValue($(db), "$(name)", GWEN_Buffer_GetStart(tbuf));
            GWEN_Buffer_free(tbuf);
          }
        </code>
      </codedef>

      <codedef id="fromXml">
        <code>
          {
            const char *s;
            
            s=GWEN_XMLNode_GetCharValue($(db), "$(name)", NULL);
            if (s)
             $(dst)=AB_Value_fromString(s);
            else
              $(dst)=$(default);
          }
        </code>
      </codedef>



      <codedef id="toObject">
        <code>
          if ($(src)) {
            GWEN_BUFFER *tbuf=GWEN_Buffer_new(0, 64, 0, 1);
        
            AB_Value_toString($(src), tbuf);
            $(retval)=AQDB_Object_SetFieldString($(db),
                                                 $(fieldid),
                                                 GWEN_Buffer_GetStart(tbuf));
            GWEN_Buffer_free(tbuf);
          }
          else 
            $(retval)=AQDB_Object_SetFieldString($(db), $(fieldid), NULL);
        </code>
      </codedef>



      <codedef id="fromObject">
        <code>
          {
            const char *s;
            
            $(retval)=AQDB_Object_GetFieldString($(db), $(fieldId), &amp;s);
            if ($(retval)&gt;=0 &amp;&amp; s)
              $(dst)=AB_Value_fromString(s);
            else
              $(dst)=$(default);
          }
        </code>
      </codedef>



      <codedef id="toDb">
        <code>
          if ($(src)) {
            GWEN_BUFFER *tbuf=GWEN_Buffer_new(0, 64, 0, 1);
        
            AB_Value_toString($(src), tbuf);
            $(retval)=GWEN_DB_SetCharValue($(db),
                                           GWEN_DB_FLAGS_OVERWRITE_VARS, 
                                           "$(name)", 
                                           GWEN_Buffer_GetStart(tbuf));
            GWEN_Buffer_free(tbuf);
          }
          else {
            GWEN_DB_DeleteVar($(db), "$(name)");
            $(retval)=0;
          }
        </code>
      </codedef>



      <codedef id="fromDb">
        <code>
          {
            const char *s;
            
            s=GWEN_DB_GetCharValue($(db), "$(name)", 0, NULL);
            if (s)
             $(dst)=AB_Value_fromString(s);
            else
              $(dst)=$(default);
          }
        </code>
      </codedef>



      <codedef id="toHashString">
        <code>
          if ($(src)) {
            double d=AB_Value_GetValueAsDouble($(src));
            char numbuf[32];
            
            snprintf(numbuf, sizeof(numbuf)-1, "%.4f", d);
            numbuf[sizeof(numbuf)-1]=0;
            GWEN_Buffer_AppendString($(buffer), numbuf);
          }
        </code>
      </codedef>




    </codedefs>



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


  </typedef>
</tm2>
