Browse Source

cmData.h/c : Initial implementation of serialization functions.

Not yet tested.
master
kpl 11 years ago
parent
commit
341bde7a7c
2 changed files with 183 additions and 63 deletions
  1. 151
    45
      cmData.c
  2. 32
    18
      cmData.h

+ 151
- 45
cmData.c View File

10
 
10
 
11
 cmData_t cmDataNull = { kInvalidDtId,0,NULL,NULL,0 };
11
 cmData_t cmDataNull = { kInvalidDtId,0,NULL,NULL,0 };
12
 
12
 
13
-typedef struct
14
-{
15
-  cmDataFmtId_t tid;
16
-  unsigned      cnt;
17
-} cmDataSerialHdr_t;
18
-
19
 cmDtRC_t  _cmDataSetError( unsigned err )
13
 cmDtRC_t  _cmDataSetError( unsigned err )
20
 {
14
 {
21
   _cmDataErrNo = err;
15
   _cmDataErrNo = err;
62
 
56
 
63
 unsigned _cmDataByteCount( const cmData_t* p )
57
 unsigned _cmDataByteCount( const cmData_t* p )
64
 {
58
 {
65
-  unsigned n = sizeof(cmDataSerialHdr_t);
59
+  unsigned n = 0;
66
 
60
 
67
   switch( p->tid )
61
   switch( p->tid )
68
   {
62
   {
1866
   return p;
1860
   return p;
1867
 }
1861
 }
1868
 
1862
 
1869
-cmDtRC_t _cmDataRecdParseV(cmData_t* p, bool idFl, cmErr_t* err, va_list vl )
1863
+cmDtRC_t _cmDataRecdParseV(cmData_t* p, bool idFl, cmErr_t* err, unsigned errRC, va_list vl )
1870
 {
1864
 {
1871
   bool      contFl = true;
1865
   bool      contFl = true;
1872
   cmDtRC_t  rc     = kOkDtRC;
1866
   cmDtRC_t  rc     = kOkDtRC;
1889
     cmDataFmtId_t typeId = va_arg(vl,unsigned);
1883
     cmDataFmtId_t typeId = va_arg(vl,unsigned);
1890
     void*         v      = va_arg(vl,void*);
1884
     void*         v      = va_arg(vl,void*);
1891
     cmData_t*     np     = NULL;
1885
     cmData_t*     np     = NULL;
1886
+    bool          optFl  = cmIsFlag(typeId,kOptArgDtFl);
1887
+    cmDtRC_t      rc0    = kOkDtRC;
1888
+
1889
+    typeId = cmClrFlag(typeId,kOptArgDtFl);
1892
 
1890
 
1893
     if( idFl )
1891
     if( idFl )
1894
       np = cmDataRecdValueFromLabel( p, label );
1892
       np = cmDataRecdValueFromLabel( p, label );
1895
     else
1893
     else
1896
       np = cmDataRecdValueFromId( p, id );
1894
       np = cmDataRecdValueFromId( p, id );
1897
 
1895
 
1896
+    // if the field was not found
1897
+    if( np == NULL )
1898
+    {
1899
+      if(optFl)
1900
+        continue;
1901
+
1902
+      if( err != NULL )
1903
+      {
1904
+        if( idFl )
1905
+          cmErrMsg(err,errRC,"The required field (id=%i) was not found.",id);
1906
+        else
1907
+          cmErrMsg(err,errRC,"The required field '%s' was not found.",cmStringNullGuard(label));
1908
+      }
1909
+
1910
+      rc = kMissingFieldDtRC;
1911
+    }
1912
+
1898
     switch(typeId)
1913
     switch(typeId)
1899
     {
1914
     {
1900
       case kNullDtId:
1915
       case kNullDtId:
1901
         break;
1916
         break;
1902
 
1917
 
1903
       case kUCharDtId: 
1918
       case kUCharDtId: 
1904
-        rc = cmDataGetUChar(np,(unsigned char*)v);
1919
+        rc0 = cmDataGetUChar(np,(unsigned char*)v);
1905
         break;
1920
         break;
1906
 
1921
 
1907
       case kCharDtId:
1922
       case kCharDtId:
1908
-        rc = cmDataGetChar(np,(char*)v);
1923
+        rc0 = cmDataGetChar(np,(char*)v);
1909
         break;
1924
         break;
1910
 
1925
 
1911
       case kUShortDtId:
1926
       case kUShortDtId:
1912
-        rc = cmDataGetUShort(np,(unsigned short*)v);
1927
+        rc0 = cmDataGetUShort(np,(unsigned short*)v);
1913
         break;
1928
         break;
1914
 
1929
 
1915
       case kShortDtId:
1930
       case kShortDtId:
1916
-        rc = cmDataGetShort(np,(short*)v);
1931
+        rc0 = cmDataGetShort(np,(short*)v);
1917
         break;
1932
         break;
1918
 
1933
 
1919
       case kUIntDtId:
1934
       case kUIntDtId:
1920
-        rc = cmDataGetUInt(np,(unsigned int*)v);        
1935
+        rc0 = cmDataGetUInt(np,(unsigned int*)v);        
1921
         break;
1936
         break;
1922
 
1937
 
1923
       case kIntDtId:
1938
       case kIntDtId:
1924
-        rc = cmDataGetInt(np,(int*)v);
1939
+        rc0 = cmDataGetInt(np,(int*)v);
1925
         break;
1940
         break;
1926
 
1941
 
1927
       case kULongDtId:
1942
       case kULongDtId:
1928
-        rc = cmDataGetULong(np,(unsigned long*)v);
1943
+        rc0 = cmDataGetULong(np,(unsigned long*)v);
1929
         break;
1944
         break;
1930
 
1945
 
1931
       case kLongDtId:
1946
       case kLongDtId:
1932
-        rc = cmDataGetLong(np,(long*)v);
1947
+        rc0 = cmDataGetLong(np,(long*)v);
1933
         break;
1948
         break;
1934
 
1949
 
1935
       case kFloatDtId:
1950
       case kFloatDtId:
1936
-        rc = cmDataGetFloat(np,(float*)v);
1951
+        rc0 = cmDataGetFloat(np,(float*)v);
1937
         break;
1952
         break;
1938
 
1953
 
1939
       case kDoubleDtId:
1954
       case kDoubleDtId:
1940
-        rc = cmDataGetDouble(np,(double*)v);
1955
+        rc0 = cmDataGetDouble(np,(double*)v);
1941
         break;
1956
         break;
1942
 
1957
 
1943
       case kStrDtId:
1958
       case kStrDtId:
1944
-        rc = cmDataGetStr(np,(char**)v);
1959
+        rc0 = cmDataGetStr(np,(char**)v);
1945
         break;
1960
         break;
1946
 
1961
 
1947
       case kConstStrDtId:
1962
       case kConstStrDtId:
1948
-        rc = cmDataGetConstStr(np,(const char**)v);        
1963
+        rc0 = cmDataGetConstStr(np,(const char**)v);        
1949
         break;
1964
         break;
1950
 
1965
 
1951
       case kUCharPtrDtId: 
1966
       case kUCharPtrDtId: 
1952
-        rc = cmDataGetUCharPtr(np,(unsigned char**)v);
1967
+        rc0 = cmDataGetUCharPtr(np,(unsigned char**)v);
1953
         break;
1968
         break;
1954
 
1969
 
1955
       case kCharPtrDtId:
1970
       case kCharPtrDtId:
1956
-        rc = cmDataGetCharPtr(np,(char**)v);
1971
+        rc0 = cmDataGetCharPtr(np,(char**)v);
1957
         break;
1972
         break;
1958
 
1973
 
1959
       case kUShortPtrDtId:
1974
       case kUShortPtrDtId:
1960
-        rc = cmDataGetUShortPtr(np,(unsigned short**)v);
1975
+        rc0 = cmDataGetUShortPtr(np,(unsigned short**)v);
1961
         break;
1976
         break;
1962
 
1977
 
1963
       case kShortPtrDtId:
1978
       case kShortPtrDtId:
1964
-        rc = cmDataGetShortPtr(np,(short**)v);
1979
+        rc0 = cmDataGetShortPtr(np,(short**)v);
1965
         break;
1980
         break;
1966
 
1981
 
1967
       case kUIntPtrDtId:
1982
       case kUIntPtrDtId:
1968
-        rc = cmDataGetUIntPtr(np,(unsigned int**)v);        
1983
+        rc0 = cmDataGetUIntPtr(np,(unsigned int**)v);        
1969
         break;
1984
         break;
1970
 
1985
 
1971
       case kIntPtrDtId:
1986
       case kIntPtrDtId:
1972
-        rc = cmDataGetIntPtr(np,(int**)v);
1987
+        rc0 = cmDataGetIntPtr(np,(int**)v);
1973
         break;
1988
         break;
1974
 
1989
 
1975
       case kULongPtrDtId:
1990
       case kULongPtrDtId:
1976
-        rc = cmDataGetULongPtr(np,(unsigned long**)v);
1991
+        rc0 = cmDataGetULongPtr(np,(unsigned long**)v);
1977
         break;
1992
         break;
1978
 
1993
 
1979
       case kLongPtrDtId:
1994
       case kLongPtrDtId:
1980
-        rc = cmDataGetLongPtr(np,(long**)v);
1995
+        rc0 = cmDataGetLongPtr(np,(long**)v);
1981
         break;
1996
         break;
1982
 
1997
 
1983
       case kFloatPtrDtId:
1998
       case kFloatPtrDtId:
1984
-        rc = cmDataGetFloatPtr(np,(float**)v);
1999
+        rc0 = cmDataGetFloatPtr(np,(float**)v);
1985
         break;
2000
         break;
1986
 
2001
 
1987
       case kDoublePtrDtId:
2002
       case kDoublePtrDtId:
1988
-        rc = cmDataGetDoublePtr(np,(double**)v);
2003
+        rc0 = cmDataGetDoublePtr(np,(double**)v);
1989
         break;
2004
         break;
1990
 
2005
 
1991
       case kVoidPtrDtId:
2006
       case kVoidPtrDtId:
1992
-        rc = cmDataGetVoidPtr(np,(void**)v);
2007
+        rc0 = cmDataGetVoidPtr(np,(void**)v);
1993
         break;
2008
         break;
1994
 
2009
 
1995
       case kListDtId:
2010
       case kListDtId:
1996
       case kPairDtId:
2011
       case kPairDtId:
1997
       case kRecordDtId:
2012
       case kRecordDtId:
1998
         if( np->tid != typeId )
2013
         if( np->tid != typeId )
1999
-         _cmDataSetError(kCvtErrDtRC);
2014
+         rc0 = _cmDataSetError(kCvtErrDtRC);
2000
         else
2015
         else
2001
           *(cmData_t**)v = np;
2016
           *(cmData_t**)v = np;
2002
         break;
2017
         break;
2003
 
2018
 
2004
       default:
2019
       default:
2005
-        _cmDataSetError(kVarArgErrDtRC);
2020
+        rc0 = _cmDataSetError(kVarArgErrDtRC);
2006
         assert(0);
2021
         assert(0);
2007
     }
2022
     }
2008
-    
2023
+
2024
+    if( rc0 != kOkDtRC && err!=NULL)
2025
+    {
2026
+      if( idFl ) 
2027
+        cmErrMsg(err,errRC,"Unable to convert field (id=%i) to requested type.",id);
2028
+      else
2029
+        cmErrMsg(err,errRC,"Unable to convert field '%s' to requisted type.",cmStringNullGuard(label));
2030
+
2031
+      rc = rc0;
2032
+    }
2009
   }
2033
   }
2010
 
2034
 
2011
   return rc;
2035
   return rc;
2012
 }
2036
 }
2013
 
2037
 
2014
-cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, va_list vl )
2015
-{ return _cmDataRecdParseV(p,false,err,vl); }
2038
+  cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl )
2039
+  { return _cmDataRecdParseV(p,false,err,errRC,vl); }
2016
 
2040
 
2017
-cmDtRC_t cmDataRecdParseLabel(cmData_t* p, cmErr_t* err, ... )
2041
+cmDtRC_t cmDataRecdParseLabel(cmData_t* p, cmErr_t* err, unsigned errRC, ... )
2018
 {
2042
 {
2019
   va_list vl;
2043
   va_list vl;
2020
-  va_start(vl,err);
2021
-  cmDtRC_t rc = cmDataRecdParseLabelV(p,err,vl);
2044
+  va_start(vl,errRC);
2045
+  cmDtRC_t rc = cmDataRecdParseLabelV(p,err,errRC,vl);
2022
   va_end(vl);
2046
   va_end(vl);
2023
   return rc;
2047
   return rc;
2024
 }
2048
 }
2025
 
2049
 
2026
-cmDtRC_t cmDataRecdParseIdV(cmData_t* p, cmErr_t* err, va_list vl )
2027
-{ return _cmDataRecdParseV(p,true,err,vl); }
2050
+cmDtRC_t cmDataRecdParseIdV(cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl )
2051
+{ return _cmDataRecdParseV(p,true,err,errRC,vl); }
2028
 
2052
 
2029
-cmDtRC_t cmDataRecdParseId(cmData_t* p, cmErr_t* err, ... )
2053
+cmDtRC_t cmDataRecdParseId(cmData_t* p, cmErr_t* err, unsigned errRC, ... )
2030
 {
2054
 {
2031
   va_list vl;
2055
   va_list vl;
2032
-  va_start(vl,err);
2033
-  cmDtRC_t rc = cmDataRecdParseIdV(p,err,vl);
2056
+  va_start(vl,errRC);
2057
+  cmDtRC_t rc = cmDataRecdParseIdV(p,err,errRC,vl);
2034
   va_end(vl);
2058
   va_end(vl);
2035
   return rc;
2059
   return rc;
2036
 }
2060
 }
2038
 
2062
 
2039
 
2063
 
2040
 //----------------------------------------------------------------------------  
2064
 //----------------------------------------------------------------------------  
2065
+unsigned _cmDataSerializeNodeByteCount( const cmData_t* p )
2066
+{
2067
+  unsigned n = 0;
2068
+
2069
+  // all serialized data ele's begin with a cmDataFmtId_t
2070
+  n += sizeof(cmDataFmtId_t);  
2071
+
2072
+  // arrays then have a count of bytes and structures have a child count
2073
+  if( cmDataIsPtr(p) || cmDataIsStruct(p) )
2074
+    n += sizeof(unsigned);
2075
+
2076
+  // then the data itself takes a variable number of bytes
2077
+  n += _cmDataByteCount(p);
2078
+
2079
+  return n;
2080
+}
2081
+
2041
 unsigned cmDataSerializeByteCount( const cmData_t* p )
2082
 unsigned cmDataSerializeByteCount( const cmData_t* p )
2042
 {
2083
 {
2043
   unsigned bn = 0;
2084
   unsigned bn = 0;
2051
   for(; dp != NULL; dp=dp->sibling )
2092
   for(; dp != NULL; dp=dp->sibling )
2052
     bn += cmDataSerializeByteCount(dp->sibling);
2093
     bn += cmDataSerializeByteCount(dp->sibling);
2053
     
2094
     
2095
+
2054
   // 
2096
   // 
2055
-  return  _cmDataByteCount(p) + bn;
2097
+  return  bn + _cmDataSerializeNodeByteCount(p);
2098
+}
2099
+
2100
+char* _cmDataSerializeWriteArray( cmData_t* np, char* dp, const char* ep )
2101
+{
2102
+  unsigned byteCnt = _cmDataByteCount(np);
2103
+
2104
+  *((unsigned*)dp) = byteCnt;
2105
+  dp += sizeof(unsigned);
2106
+
2107
+  memcpy(dp,np->u.vp,byteCnt);
2108
+  dp += byteCnt;
2109
+
2110
+  return dp;
2056
 }
2111
 }
2057
 
2112
 
2113
+char* _cmDataSerializeWriteStruct( cmData_t* np, char* dp, const char* ep )
2114
+{
2115
+  *((unsigned*)dp) = cmDataChildCount(np);
2116
+  dp += sizeof(unsigned);
2058
 
2117
 
2118
+  return dp;
2119
+}
2120
+
2121
+
2122
+char* _cmDataSerializeWrite( cmData_t* np, char* dp, const char* ep )
2123
+{
2124
+  assert( dp + _cmDataSerializeNodeByteCount(np) <= ep );
2125
+
2126
+  *((cmDataFmtId_t*)dp) = np->tid;
2127
+  dp += sizeof(cmDataFmtId_t);
2128
+
2129
+  switch( np->tid )
2130
+  {
2131
+    case kNullDtId:   break;
2132
+    case kUCharDtId:  *((unsigned char*)dp)  = cmDataUChar(np);  dp+=sizeof(unsigned char);  break;
2133
+    case kCharDtId:   *((char*)dp)           = cmDataChar(np);   dp+=sizeof(char);           break;
2134
+    case kUShortDtId: *((unsigned short*)dp) = cmDataUShort(np); dp+=sizeof(unsigned short); break;
2135
+    case kShortDtId:  *((short*)dp)          = cmDataShort(np);  dp+=sizeof(short);          break;
2136
+    case kUIntDtId:   *((unsigned int*)dp)   = cmDataUInt(np);   dp+=sizeof(unsigned int);   break;
2137
+    case kIntDtId:    *((int*)dp)            = cmDataInt(np);    dp+=sizeof(int);            break;
2138
+    case kULongDtId:  *((unsigned long*)dp)  = cmDataULong(np);  dp+=sizeof(unsigned long);  break;
2139
+    case kLongDtId:   *((long*)dp)           = cmDataLong(np);   dp+=sizeof(long);           break;
2140
+    case kFloatDtId:  *((float*)dp)          = cmDataFloat(np);  dp+=sizeof(float);          break;
2141
+    case kDoubleDtId: *((double*)dp)         = cmDataDouble(np); dp+=sizeof(double);         break;
2142
+    case kStrDtId:       dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2143
+    case kConstStrDtId:  dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2144
+    case kUCharPtrDtId:  dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2145
+    case kCharPtrDtId:   dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2146
+    case kUShortPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2147
+    case kShortPtrDtId:  dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2148
+    case kUIntPtrDtId:   dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2149
+    case kIntPtrDtId:    dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2150
+    case kULongPtrDtId:  dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2151
+    case kLongPtrDtId:   dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2152
+    case kFloatPtrDtId:  dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2153
+    case kDoublePtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2154
+    case kVoidPtrDtId:   dp = _cmDataSerializeWriteArray(np,dp,ep); break;
2155
+    case kListDtId:      dp = _cmDataSerializeWriteStruct(np,dp,ep); break;
2156
+    case kPairDtId:      dp = _cmDataSerializeWriteStruct(np,dp,ep); break;
2157
+    case kRecordDtId:    dp = _cmDataSerializeWriteStruct(np,dp,ep); break;
2158
+    default:
2159
+      { assert(0); }
2160
+  }
2161
+  return dp;
2162
+}
2059
 
2163
 
2060
 cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt )
2164
 cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt )
2061
 {
2165
 {
2166
+  
2167
+
2062
   return kOkDtRC;
2168
   return kOkDtRC;
2063
 }
2169
 }
2064
 
2170
 

+ 32
- 18
cmData.h View File

10
     kOkDtRC = cmOkRC,
10
     kOkDtRC = cmOkRC,
11
     kCvtErrDtRC,
11
     kCvtErrDtRC,
12
     kVarArgErrDtRC,
12
     kVarArgErrDtRC,
13
+    kMissingFieldDtRC,
13
     kEolDtRC
14
     kEolDtRC
14
   };
15
   };
15
 
16
 
32
     kMinValDtId,
33
     kMinValDtId,
33
 
34
 
34
     kNullDtId = kMinValDtId,
35
     kNullDtId = kMinValDtId,
35
-
36
     kUCharDtId,
36
     kUCharDtId,
37
     kCharDtId,
37
     kCharDtId,
38
     kUShortDtId,
38
     kUShortDtId,
66
     kListDtId = kMinStructDtId, // children nodes are array elements, cnt=child count
66
     kListDtId = kMinStructDtId, // children nodes are array elements, cnt=child count
67
     kPairDtId,                  // key/value pairs, cnt=2, first child is key, second is value
67
     kPairDtId,                  // key/value pairs, cnt=2, first child is key, second is value
68
     kRecordDtId,                // children nodes are pairs, cnt=pair count
68
     kRecordDtId,                // children nodes are pairs, cnt=pair count
69
-    kMaxStructDtId
69
+    kMaxStructDtId,
70
 
70
 
71
+    kOptArgDtFl = 0x80000000
71
   } cmDataFmtId_t;
72
   } cmDataFmtId_t;
72
 
73
 
73
   enum
74
   enum
232
   cmDtRC_t cmDataGetDoublePtr( const cmData_t* p, double** v );
233
   cmDtRC_t cmDataGetDoublePtr( const cmData_t* p, double** v );
233
 
234
 
234
 
235
 
235
-  // Set the value of an existing scalar data object.
236
-  cmData_t* cmDataSetNull(       cmData_t* p );
236
+  // Set the value and type of an existing scalar object. 
237
+  // These functions begin by releasing any resources held by *p
238
+  // prior to resetting the type and value of the object.
239
+  cmData_t* cmDataSetNull(      cmData_t* p );
237
   cmData_t* cmDataSetChar(      cmData_t* p, char v );
240
   cmData_t* cmDataSetChar(      cmData_t* p, char v );
238
   cmData_t* cmDataSetUChar(     cmData_t* p, unsigned char v );
241
   cmData_t* cmDataSetUChar(     cmData_t* p, unsigned char v );
239
   cmData_t* cmDataSetShort(     cmData_t* p, short v );
242
   cmData_t* cmDataSetShort(     cmData_t* p, short v );
247
   cmData_t* cmDataSetStr(       cmData_t* p, cmChar_t* s );
250
   cmData_t* cmDataSetStr(       cmData_t* p, cmChar_t* s );
248
   cmData_t* cmDataSetConstStr(  cmData_t* p, const cmChar_t* s );
251
   cmData_t* cmDataSetConstStr(  cmData_t* p, const cmChar_t* s );
249
 
252
 
250
-  // Set the value of an existing data object to an external array.
251
-  // 'vp' is assigned as the data space for the object and therefore must remain
253
+  // Set the type and value of an existing data object to an external array.
254
+  // These functions begin by releasing any resources help by *p.
255
+  // The array pointed to by 'vp' is not copied or duplicated.
256
+  // 'vp' is simply assigned as the data space for the object and therefore must remain
252
   // valid for the life of the object.
257
   // valid for the life of the object.
253
   cmData_t* cmDataSetVoidPtr(   cmData_t* p, void* vp,           unsigned cnt );
258
   cmData_t* cmDataSetVoidPtr(   cmData_t* p, void* vp,           unsigned cnt );
254
   cmData_t* cmDataSetCharPtr(   cmData_t* p, char* vp,           unsigned cnt );
259
   cmData_t* cmDataSetCharPtr(   cmData_t* p, char* vp,           unsigned cnt );
263
   cmData_t* cmDataSetDoublePtr( cmData_t* p, double* vp,         unsigned cnt );
268
   cmData_t* cmDataSetDoublePtr( cmData_t* p, double* vp,         unsigned cnt );
264
 
269
 
265
   // Set the value of an existing array based data object. 
270
   // Set the value of an existing array based data object. 
266
-  // Dynamically allocate the internal array and copy the array data into it.
271
+  // These functions begin by releasing any resources help by *p
272
+  // and then dynamically allocate the internal array and copy 
273
+  // the array data into it.
267
   cmData_t* cmDataSetStrAlloc(       cmData_t* p, const cmChar_t* s );
274
   cmData_t* cmDataSetStrAlloc(       cmData_t* p, const cmChar_t* s );
268
   cmData_t* cmDataSetConstStrAlloc(  cmData_t* p, const cmChar_t* s );
275
   cmData_t* cmDataSetConstStrAlloc(  cmData_t* p, const cmChar_t* s );
269
   cmData_t* cmDataSetVoidAllocPtr(   cmData_t* p, const void* vp,           unsigned cnt );
276
   cmData_t* cmDataSetVoidAllocPtr(   cmData_t* p, const void* vp,           unsigned cnt );
393
   cmData_t*       cmDataPairKey(      cmData_t* p );
400
   cmData_t*       cmDataPairKey(      cmData_t* p );
394
   unsigned        cmDataPairKeyId(    cmData_t* p );
401
   unsigned        cmDataPairKeyId(    cmData_t* p );
395
   const cmChar_t* cmDataPairKeyLabel( cmData_t* p );
402
   const cmChar_t* cmDataPairKeyLabel( cmData_t* p );
396
-
397
   cmData_t*       cmDataPairValue(    cmData_t* p );
403
   cmData_t*       cmDataPairValue(    cmData_t* p );
398
   
404
   
399
   // Set the value of an existing pair node. 
405
   // Set the value of an existing pair node. 
404
   cmData_t* cmDataPairSetValue(     cmData_t* p, cmData_t* value );
410
   cmData_t* cmDataPairSetValue(     cmData_t* p, cmData_t* value );
405
 
411
 
406
   // Set the key of an existing pair node.
412
   // Set the key of an existing pair node.
407
-  // 
408
-  // Returns 'p'.
413
+  // The previous key is unlinked and freed.
409
   cmData_t* cmDataPairSetKey(       cmData_t* p, cmData_t* key );
414
   cmData_t* cmDataPairSetKey(       cmData_t* p, cmData_t* key );
410
   cmData_t* cmDataPairSetKeyId(     cmData_t* p, unsigned id );
415
   cmData_t* cmDataPairSetKeyId(     cmData_t* p, unsigned id );
411
   // The data space for the 'label' string is dynamically allocated.
416
   // The data space for the 'label' string is dynamically allocated.
491
   cmData_t*       cmRecdAppendPair( cmData_t* p, cmData_t* pair );
496
   cmData_t*       cmRecdAppendPair( cmData_t* p, cmData_t* pair );
492
 
497
 
493
 
498
 
494
-  // Var-args fmt:
499
+  // Var-args format:
495
   // <label|id> <typeId>  <value> {<cnt>}
500
   // <label|id> <typeId>  <value> {<cnt>}
496
   // scalar types: <value> is literal,<cnt> is not included
501
   // scalar types: <value> is literal,<cnt> is not included
497
-  // null   type  has no <value> or <cnt>
502
+  // null   type: has no <value> or <cnt>
498
   // ptr    types: <value> is pointer,  <cnt> is element count
503
   // ptr    types: <value> is pointer,  <cnt> is element count
499
   // struct types: <value> is cmData_t, <cnt> is not included
504
   // struct types: <value> is cmData_t, <cnt> is not included
500
   // Indicate the end of argument list by setting  <typeId> to kInvalidDtId. 
505
   // Indicate the end of argument list by setting  <typeId> to kInvalidDtId. 
506
   cmData_t*       cmDataRecdAllocIdA( cmData_t* parent, ... );
511
   cmData_t*       cmDataRecdAllocIdA( cmData_t* parent, ... );
507
   
512
   
508
   // Extract the data in a record to C variables.
513
   // Extract the data in a record to C variables.
509
-  // <label|id> <typeId> <pointer>
510
-  cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, va_list vl );
511
-  cmDtRC_t cmDataRecdParseLabel( cmData_t* p, cmErr_t* err, ... );
512
-  cmDtRC_t cmDataRecdParseIdV(   cmData_t* p, cmErr_t* err, va_list vl );
513
-  cmDtRC_t cmDataRecdParseId(    cmData_t* p, cmErr_t* err, ... );
514
+  // The var-args list must be NULL terminated.
515
+  // The <'id' | 'label'> identify a pair.  
516
+  // The <typeId> indicates the C type of 'pointer'.
517
+  // The actual field type must be convertable into this pointer type or the
518
+  // function will fail.
519
+  // 'err' is an application supplied error object to be used if a required
520
+  // field is missing.  'errRC' is the client result code to be passed with 
521
+  // the error report. See cmErrMsg().  Both 'err' and 'errRC' are optional.
522
+  // Set kOptArgDtFl on 'typeId' to indicate that a field is optional.
523
+  // <label|id> (<typeId> | kOptArgDtFl)  <pointer>
524
+  cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl );
525
+  cmDtRC_t cmDataRecdParseLabel( cmData_t* p, cmErr_t* err, unsigned errRC, ... );
526
+  cmDtRC_t cmDataRecdParseIdV(   cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl );
527
+  cmDtRC_t cmDataRecdParseId(    cmData_t* p, cmErr_t* err, unsigned errRC, ... );
514
   
528
   
515
   unsigned cmDataSerializeByteCount( const cmData_t* p );
529
   unsigned cmDataSerializeByteCount( const cmData_t* p );
516
-  cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt );
530
+  cmDtRC_t cmDataSerialize(   const cmData_t* p, void* buf, unsigned bufByteCnt );
517
   cmDtRC_t cmDataDeserialize( const void* buf, unsigned bufByteCnt, cmData_t** pp );
531
   cmDtRC_t cmDataDeserialize( const void* buf, unsigned bufByteCnt, cmData_t** pp );
518
   
532
   
519
   void     cmDataPrint( const cmData_t* p, cmRpt_t* rpt );
533
   void     cmDataPrint( const cmData_t* p, cmRpt_t* rpt );

Loading…
Cancel
Save