Selaa lähdekoodia

cmData.h/c: Initial rewrite of cmData to include the concept of homogeneous arrays as containers and leaf nodes.

master
kpl 11 vuotta sitten
vanhempi
commit
b74e24a46b
2 muutettua tiedostoa jossa 1730 lisäystä ja 56 poistoa
  1. 1313
    1
      cmData.c
  2. 417
    55
      cmData.h

+ 1313
- 1
cmData.c
File diff suppressed because it is too large
Näytä tiedosto


+ 417
- 55
cmData.h Näytä tiedosto

@@ -5,30 +5,433 @@
5 5
 extern "C" {
6 6
 #endif
7 7
 
8
+  /*
9
+    TODO:
10
+    0) Figure out a error handling scheme that does not rely on
11
+    a global errno.  This is not useful in multi-thread environments.
12
+    It might be ok to go with an 'all errors are fatal' model
13
+    (except in the var-args functions).
14
+    Consider the use of a context object for use with functions 
15
+    that can have runtime errors or need to allocate memory.
16
+
17
+    1) Implement the canConvert and willTruncate functions.
18
+
19
+    2) Make a set of cmDataAllocXXXPtr() functions which take
20
+    a flag indicating whether or not to dynamically allocate
21
+    the array space. This will allow dynamic allocattion to
22
+    occur at runtime.  Make var args functions for list and
23
+    record objects which also take this flag.
24
+    Whereever a function may be implemented using 
25
+    static/dynamic allocation this flag should be present.
26
+    (e.g. string allocation for pair labels)
27
+    This choice is common enough that it may be worth
28
+    suffixing function names with a capital letter to
29
+    be clear what the functions memory policy is.
30
+
31
+    3) Come up with a var-args format which allows a 
32
+    hierchy of records to be defined in one line.
33
+
34
+    4) Implement the serialization functions.
35
+
36
+    5) Implement an ascii string/parse format for writing/reading.
37
+
38
+    6) Implement fast lookup of record fields.
39
+
40
+    7) Allow for user defined types.  For example a 'matrix'
41
+    data type. This might be as simple as adding an extra 'user_tid' 
42
+    field to cmData_t.
43
+
44
+    8) Implement type specific cmDataGetRecordValueXXX() functions.
45
+
46
+    9) Implement cmDataIsEqual(), cmDataIsLtE(), ...
47
+
48
+   */
49
+
8 50
   enum
9 51
   {
10 52
     kOkDtRC = cmOkRC,
53
+    kAssertErrDtRC,
54
+    kConstErrDtRC,
11 55
     kCvtErrDtRC,
12
-    kVarArgErrDtRC,
13
-    kMissingFieldDtRC,
14
-    kLexFailDtRC,
15
-    kParseStackFailDtRC,
16
-    kSyntaxErrDtRC,
56
+    kInvalidContDtRC,
57
+    kInvalidTypeDtRC,
17 58
     kEolDtRC
18 59
   };
19 60
 
61
+  typedef unsigned cmDtRC_t;
62
+
63
+  typedef enum
64
+  {
65
+    kInvalidTypeDtId,// 0
66
+    kNullDtId,       // 1 the data object exists but it has no data
67
+    kUCharDtId,      // 2
68
+    kCharDtId,       // 3
69
+    kUShortDtId,     // 4 
70
+    kShortDtId,      // 5
71
+    kUIntDtId,       // 6
72
+    kIntDtId,        // 7
73
+    kULongDtId,      // 8
74
+    kLongDtId,       // 9
75
+    kFloatDtId,      // 10 
76
+    kDoubleDtId,     // 11 
77
+    kStrDtId,        // 12 zero terminated string
78
+    kBlobDtId        // 13 application defined raw memory object
79
+  } cmDataTypeId_t;
80
+
81
+
82
+  typedef enum
83
+  {
84
+    kInvalidCntDtId, // 0 
85
+    kScalarDtId,     // 1
86
+    kArrayDtId,      // 2
87
+    kPairDtId,       // 3
88
+    kListDtId,       // 4
89
+    kRecordDtId      // 5
90
+  } cmDataContainerId_t;
91
+
20 92
   enum
21 93
   {
22
-    kInvalidDtChar   = 0xff,
23
-    kInvalidDtUChar  = 0xff,
24
-    kInvalidDtShort  = 0xffff,
25
-    kInvalidDtUShort = 0xffff,
26
-    kInvalidDtInt    = 0xffffffff,
27
-    kInvalidDtUInt   = 0xffffffff,
28
-    kInvalidDtLong   = 0xffffffff,
29
-    kInvalidDtULong  = 0xffffffff,    
94
+    kNoFlagsDtFl = 0x00,
95
+
96
+    // Indicate that the memory used by the data object
97
+    // was dynamically allocated and should be released
98
+    // by cmDataFree().
99
+    kFreeObjDtFl   = 0x01,
100
+
101
+    // Indicate that the memory used by strings, blobs 
102
+    // and arrays should be freed by cmDataFree().
103
+    kFreeValueDtFl = 0x02, 
104
+
105
+    // Indicate that the value of the object cannot be changed.
106
+    // (but the object could be reassigned as a new type).
107
+    kConstValueDtFl = 0x04,
108
+
109
+    // Indicate that the type of the object cannot be changed.
110
+    // (but the value may be changed).
111
+    kConstObjDtFl  = 0x08,
112
+
113
+    // Indicate that the array or string should not be 
114
+    // internally reallocated but rather the source pointer
115
+    // should be taken as the new value of the object.
116
+    kNoCopyDtFl = 0x10, 
117
+
118
+
30 119
   };
31 120
 
121
+
122
+  typedef struct cmData_str
123
+  {
124
+    cmDataTypeId_t      tid;       // data format id
125
+    cmDataContainerId_t cid;       // container id
126
+    unsigned            flags;     // 
127
+    struct cmData_str*  parent;    // this childs parent
128
+    struct cmData_str*  sibling;   // this childs left sibling
129
+    unsigned            cnt;    // byte cnt for strings/blobs and ele count for arrays
130
+
131
+    union
132
+    {
133
+      char              c;
134
+      unsigned char    uc;
135
+      short             s;
136
+      unsigned short   us;
137
+      int               i;
138
+      unsigned int     ui;
139
+      long              l;
140
+      unsigned long    ul;
141
+      float             f;
142
+      double            d;
143
+
144
+      cmChar_t*         z;
145
+
146
+      void*             vp;
147
+
148
+      char*             cp;
149
+      unsigned char*   ucp;
150
+      short*            sp;
151
+      unsigned short*  usp;
152
+      int*              ip;
153
+      unsigned int*    uip;
154
+      long*             lp;
155
+      unsigned long*   ulp;
156
+      float*            fp;
157
+      double*           dp;
158
+
159
+
160
+      struct cmData_str* child; // first child (list,record,pair)
161
+    } u;
162
+  
163
+  } cmData_t;
164
+
165
+  extern cmData_t cmDataNull;
166
+
167
+  const cmChar_t*  cmDataTypeToLabel( cmDataTypeId_t tid );
168
+  cmDataTypeId_t   cmDataLabelToType( const cmChar_t* typeLabelStr );
169
+
170
+  // Returns 1 for kStrDtId.
171
+  // Returns cmInvalidCnt if tid is not recognized.
172
+  unsigned         dmDataByteWidth( cmDataTypeId_t tid );
173
+
174
+  const cmChar_t*      cmDataContainerIdToLabel( cmDataContainerId_t tid );
175
+  cmDataContainerId_t  cmDataLabelToContainerId( const cmChar_t* contLabelStr );
176
+
177
+  bool cmDataIsConstObj( const cmData_t* d );
178
+  void cmDataEnableConstObj( cmData_t* d, bool enaFl );
179
+
180
+  bool cmDataIsConstValue( const cmData_t* d );
181
+  void cmDataEnableConstValue( cmData_t* d, bool enaFl );
182
+
183
+  bool cmDataIsFreeValue( const cmData_t* d );
184
+  void cmDataEnableFreeValue( cmData_t* d, bool enaFl );
185
+
186
+  // Returns true if this is a scalar or array node.
187
+  bool cmDataIsLeaf( const cmData_t* d);
188
+
189
+  // Return true if this is NOT a scalar or array node.
190
+  bool cmDataIsStruct( const cmData_t* d );
191
+  
192
+  
193
+
194
+  //----------------------------------------------------------------------------
195
+  // Scalar related functions
196
+  //
197
+
198
+  // Dynamically allocate a scalar object and set it's value.
199
+  // The 'flags' argument may include kConstValueDtFl and kConstObjDtFl.
200
+  // The string and blob constructors may also use the
201
+  // kNoCopyDtFl and the kFreeValueDtFl.
202
+
203
+  // Generic:
204
+  // 'byteCnt' is ignored for all types other than strings and blobs.
205
+  cmDtRC_t cmDataNewScalar( cmData_t* parent, cmDataTypeId_t tid, unsigned flags, void* vp, unsigned byteCnt, cmData_t** ref );
206
+
207
+  // Type specific
208
+  cmDtRC_t cmDataNewNull(     cmData_t* parent, unsigned flags,                   cmData_t** ref );
209
+  cmDtRC_t cmDataNewChar(     cmData_t* parent, unsigned flags, char v,           cmData_t** ref );
210
+  cmDtRC_t cmDataNewUChar(    cmData_t* parent, unsigned flags, unsigned char v,  cmData_t** ref );
211
+  cmDtRC_t cmDataNewShort(    cmData_t* parent, unsigned flags, short v,          cmData_t** ref );
212
+  cmDtRC_t cmDataNewUShort(   cmData_t* parent, unsigned flags, unsigned short v, cmData_t** ref );
213
+  cmDtRC_t cmDataNewInt(      cmData_t* parent, unsigned flags, int v,            cmData_t** ref );
214
+  cmDtRC_t cmDataNewUInt(     cmData_t* parent, unsigned flags, unsigned int v,   cmData_t** ref );
215
+  cmDtRC_t cmDataNewLong(     cmData_t* parent, unsigned flags, long v,           cmData_t** ref );
216
+  cmDtRC_t cmDataNewULong(    cmData_t* parent, unsigned flags, unsigned long v,  cmData_t** ref );
217
+  cmDtRC_t cmDataNewFloat(    cmData_t* parent, unsigned flags, float v,          cmData_t** ref );
218
+  cmDtRC_t cmDataNewDouble(   cmData_t* parent, unsigned flags, double v,         cmData_t** ref );
219
+  cmDtRC_t cmDataNewStr(      cmData_t* parent, unsigned flags, cmChar_t* str,       cmData_t** ref );
220
+  cmDtRC_t cmDataNewConstStr( cmData_t* parent, unsigned flags, const cmChar_t* str, cmData_t** ref );
221
+  cmDtRC_t cmDataNewStrN(     cmData_t* parent, unsigned flags, cmChar_t* str,       unsigned charCnt, cmData_t** ref );
222
+  cmDtRC_t cmDataNewConstStrN(cmData_t* parent, unsigned flags, const cmChar_t* str, unsigned charCnt, cmData_t** ref );
223
+  cmDtRC_t cmDataNewBlob(     cmData_t* parent, unsigned flags, void* vp,            unsigned byteCnt, cmData_t** ref );
224
+  cmDtRC_t cmDataNewConstBlob(cmData_t* parent, unsigned flags, const void* vp,      unsigned byteCnt, cmData_t** ref );
225
+ 
226
+
227
+
228
+  // Set the value and type of an existing scalar object.
229
+  // These functions begin by releasing any resources held by *p
230
+  // prior to resetting the type and value of the object.
231
+  // The 'flags' argument to cmDataSetStr() and cmDataSetConstStr() 
232
+  // may use the kNoCopyDtFl and the kFreeValueDtFl
233
+  cmDtRC_t  cmDataSetScalarValue( cmData_t* d, cmDataTypeId_t tid, void* vp, unsigned byteCnt, unsigned flags );
234
+  
235
+  cmDtRC_t cmDataSetNull(      cmData_t* p );
236
+  cmDtRC_t cmDataSetChar(      cmData_t* p, char v );
237
+  cmDtRC_t cmDataSetUChar(     cmData_t* p, unsigned char v );
238
+  cmDtRC_t cmDataSetShort(     cmData_t* p, short v );
239
+  cmDtRC_t cmDataSetUShort(    cmData_t* p, unsigned short v );
240
+  cmDtRC_t cmDataSetInt(       cmData_t* p, int v );
241
+  cmDtRC_t cmDataSetUInt(      cmData_t* p, unsigned int v );
242
+  cmDtRC_t cmDataSetLong(      cmData_t* p, long v );
243
+  cmDtRC_t cmDataSetULong(     cmData_t* p, unsigned long v );
244
+  cmDtRC_t cmDataSetFloat(     cmData_t* p, float v );
245
+  cmDtRC_t cmDataSetDouble(    cmData_t* p, double v );
246
+  cmDtRC_t cmDataSetStr(       cmData_t* p, unsigned flags, cmChar_t* s );
247
+  cmDtRC_t cmDataSetConstStr(  cmData_t* p, unsigned flags, const cmChar_t* s );
248
+  cmDtRC_t cmDataSetStrN(      cmData_t* p, unsigned flags, cmChar_t* s, unsigned charCnt );
249
+  cmDtRC_t cmDataSetConstStrN( cmData_t* p, unsigned flags, const cmChar_t* s, unsigned charCnt );
250
+  cmDtRC_t cmDataSetBlob(      cmData_t* p, unsigned flags, void* v, unsigned byteCnt );
251
+  cmDtRC_t cmDataSetConstBlob( cmData_t* p, unsigned flags, const void* v, unsigned byteCnt );
252
+
253
+  // Get the value of an object. No conversion is applied the
254
+  // type must match exactly or an error is generated.
255
+  cmDtRC_t cmDataChar(      const cmData_t* p, char* v );
256
+  cmDtRC_t cmDataUChar(     const cmData_t* p, unsigned char* v );
257
+  cmDtRC_t cmDataShort(     const cmData_t* p, short* v );
258
+  cmDtRC_t cmDataUShort(    const cmData_t* p, unsigned short* v );
259
+  cmDtRC_t cmDataInt(       const cmData_t* p, int* v );
260
+  cmDtRC_t cmDataUInt(      const cmData_t* p, unsigned int* v );
261
+  cmDtRC_t cmDataLong(      const cmData_t* p, long* v );
262
+  cmDtRC_t cmDataULong(     const cmData_t* p, unsigned long* v );
263
+  cmDtRC_t cmDataFloat(     const cmData_t* p, float* v );
264
+  cmDtRC_t cmDataDouble(    const cmData_t* p, double* v );
265
+  cmDtRC_t cmDataStr(       const cmData_t* p, cmChar_t** v );
266
+  cmDtRC_t cmDataConstStr(  const cmData_t* p, const cmChar_t** v );
267
+  cmDtRC_t cmDataBlob(      const cmData_t* p, cmChar_t** v, unsigned* byteCntRef );
268
+  cmDtRC_t cmDataConstBlob( const cmData_t* p, const cmChar_t** v, unsigned* byteCntRef );
269
+
270
+  // Get the value of an object with conversion.
271
+  cmDtRC_t cmDataGetChar(      const cmData_t* p, char* v );
272
+  cmDtRC_t cmDataGetUChar(     const cmData_t* p, unsigned char* v );
273
+  cmDtRC_t cmDataGetShort(     const cmData_t* p, short* v );
274
+  cmDtRC_t cmDataGetUShort(    const cmData_t* p, unsigned short* v );
275
+  cmDtRC_t cmDataGetInt(       const cmData_t* p, int* v );
276
+  cmDtRC_t cmDataGetUInt(      const cmData_t* p, unsigned int* v );
277
+  cmDtRC_t cmDataGetLong(      const cmData_t* p, long* v );
278
+  cmDtRC_t cmDataGetULong(     const cmData_t* p, unsigned long* v );
279
+  cmDtRC_t cmDataGetFloat(     const cmData_t* p, float* v );
280
+  cmDtRC_t cmDataGetDouble(    const cmData_t* p, double* v );
281
+
282
+
283
+  //----------------------------------------------------------------------------
284
+  // Array related functions
285
+  //
286
+
287
+  // Notes:
288
+  // 1) string arrays are arrays of string pointers.
289
+  // 2) blob arrays (array of void pointers) are not supported because
290
+  //    there is no direct way to determine the length of each blob
291
+  //    and therefore they cannot be internally duplicated - a special scheme
292
+  //    could be devised (length goes in first 4 bytes) to make this 
293
+  //    work but we will defer that until the need arises.
294
+
295
+  //
296
+  // Dynamically allocate a new array data object.
297
+  //
298
+  // eleCnt referes to the number of elements in the array pointed
299
+  // to by 'vp'.  The number of bytes pointed to by 'vp' is then
300
+  // cmDataByteWidth(tid)*eleCnt.
301
+  //
302
+  // If no flags are set then the array pointed to by 'vp' is reallocated
303
+  // and kDataFreeDtFl is set.
304
+  //
305
+  // If kFreeValueDtFl is set then the object will take responsibility for
306
+  // releasing the memory pointed to by 'vp' when the object is destroyed
307
+  // or the array is reassigned.  
308
+  //
309
+  // If kNoCopyDtFl is set then 'vp' becomes the internal array
310
+  // value (vp[cnt]) is NOT reallocated). In this case the client is
311
+  // responsibile for eventually releasing the associated memory - when
312
+  // the data object is no longer valid.
313
+  cmDtRC_t cmDataNewArray(  cmData_t* parent, cmDataTypeId_t tid, void* vp, unsigned eleCnt, unsigned flags, cmData_t** ref );
314
+
315
+  cmDtRC_t cmDataNewCharArray(     cmData_t* parent, char* v,           unsigned eleCnt, unsigned flags, cmData_t** ref );
316
+  cmDtRC_t cmDataNewUCharArray(    cmData_t* parent, unsigned char* v,  unsigned eleCnt, unsigned flags, cmData_t** ref );
317
+  cmDtRC_t cmDataNewShortArray(    cmData_t* parent, short* v,          unsigned eleCnt, unsigned flags, cmData_t** ref );
318
+  cmDtRC_t cmDataNewUShortArray(   cmData_t* parent, unsigned short* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
319
+  cmDtRC_t cmDataNewIntArray(      cmData_t* parent, int* v,            unsigned eleCnt, unsigned flags, cmData_t** ref );
320
+  cmDtRC_t cmDataNewUIntArray(     cmData_t* parent, unsigned int* v,   unsigned eleCnt, unsigned flags, cmData_t** ref );
321
+  cmDtRC_t cmDataNewLongArray(     cmData_t* parent, long* v,           unsigned eleCnt, unsigned flags, cmData_t** ref );
322
+  cmDtRC_t cmDataNewULongArray(    cmData_t* parent, unsigned long* v,  unsigned eleCnt, unsigned flags, cmData_t** ref );
323
+  cmDtRC_t cmDataNewFloatArray(    cmData_t* parent, float* v,          unsigned eleCnt, unsigned flags, cmData_t** ref );
324
+  cmDtRC_t cmDataNewDoubleArray(   cmData_t* parent, double* v,         unsigned eleCnt, unsigned flags, cmData_t** ref );
325
+  cmDtRC_t cmDataNewStrArray(      cmData_t* parent, cmChar_t** v,      unsigned eleCnt, unsigned flags, cmData_t** ref );
326
+  cmDtRC_t cmDataNewConstStrArray( cmData_t* parent, const cmChar_t** v,unsigned eleCnt, unsigned flags, cmData_t** ref );
327
+
328
+  // Set the value and type of an existing scalar object.
329
+  //
330
+  // These functions begin by releasing any resources held by *p
331
+  // prior to resetting the type and value of the object.
332
+  // The 'flags' argument may include kConstValueDtFl, kConstObjDtFl,
333
+  // kNoCopyDtFl and the kFreeValueDtFl.
334
+
335
+  // Generic set array functions. 'vp' is assumed to point to an array 
336
+  // of the type defined by 'tid'.
337
+  cmDtRC_t cmDataSetArrayValue(  cmData_t* dt, cmDataTypeId_t tid, void* vp, unsigned eleCnt, unsigned flags );
338
+
339
+  // Type sepctific set array functions.
340
+  cmDtRC_t cmDataSetCharArray(   cmData_t* d, char* v,           unsigned eleCnt, unsigned flags );
341
+  cmDtRC_t cmDataSetUCharArray(  cmData_t* d, unsigned char* v,  unsigned eleCnt, unsigned flags );
342
+  cmDtRC_t cmDataSetShortArray(  cmData_t* d, short* v,          unsigned eleCnt, unsigned flags );
343
+  cmDtRC_t cmDataSetUShortArray( cmData_t* d, unsigned short* v, unsigned eleCnt, unsigned flags );
344
+  cmDtRC_t cmDataSetIntArray(    cmData_t* d, int* v,            unsigned eleCnt, unsigned flags );
345
+  cmDtRC_t cmDataSetUIntArray(   cmData_t* d, unsigned int* v,   unsigned eleCnt, unsigned flags );
346
+  cmDtRC_t cmDataSetLongArray(   cmData_t* d, long* v,           unsigned eleCnt, unsigned flags );
347
+  cmDtRC_t cmDataSetULongArray(  cmData_t* d, unsigned long* v,  unsigned eleCnt, unsigned flags );
348
+  cmDtRC_t cmDataSetFloatArray(  cmData_t* d, float* v,          unsigned eleCnt, unsigned flags );
349
+  cmDtRC_t cmDataSetDoubleArray( cmData_t* d, double* v,         unsigned eleCnt, unsigned flags );
350
+  cmDtRC_t cmDataSetStrArray(    cmData_t* d, cmChar_t** v,      unsigned eleCnt, unsigned flags );
351
+  cmDtRC_t cmDataSetConstStrArray(cmData_t* d,const cmChar_t** v,unsigned eleCnt, unsigned flags );
352
+
353
+  // Return the count of elements in a n array.
354
+  unsigned cmDataArrayEleCount( const cmData_t* d );
355
+
356
+  // Get a pointer to the base of an array. 
357
+  // The type must match exactly or an error is generated.
358
+  // Use cmDataEleCount() to determine the number of elements in the array.
359
+  cmDtRC_t cmDataCharArray(      const cmData_t* d, char** v );
360
+  cmDtRC_t cmDataUCharArray(     const cmData_t* d, unsigned char** v );
361
+  cmDtRC_t cmDataShortArray(     const cmData_t* d, short** v );
362
+  cmDtRC_t cmDataUShortArray(    const cmData_t* d, unsigned short** v );
363
+  cmDtRC_t cmDataIntArray(       const cmData_t* d, int** v );
364
+  cmDtRC_t cmDataUIntArray(      const cmData_t* d, unsigned int** v );
365
+  cmDtRC_t cmDataLongArray(      const cmData_t* d, long** v );
366
+  cmDtRC_t cmDataULongArray(     const cmData_t* d, unsigned long** v );
367
+  cmDtRC_t cmDataFloatArray(     const cmData_t* d, float** v );
368
+  cmDtRC_t cmDataDoubleArray(    const cmData_t* d, double** v );
369
+  cmDtRC_t cmDataStrArray(       const cmData_t* d, cmChar_t*** v );
370
+  cmDtRC_t cmDataConstStrArray(  const cmData_t* d, const cmChar_t*** v );
371
+  
372
+  //----------------------------------------------------------------------------
373
+  // Structure related functions
374
+  //
375
+
376
+  // Release an object and any resources held by it.
377
+  // Note the this function does not unlink the object
378
+  // from it's parent.  Use cmDataUnlinkAndFree()
379
+  // to remove a object from it's parent list prior
380
+  // to releasing it.
381
+  void      cmDataFree( cmData_t* p );
382
+
383
+  // Unlink 'p' from its parents and siblings.
384
+  // Asserts if parent is not a structure. 
385
+  // Returns 'p'.
386
+  cmData_t* cmDataUnlink( cmData_t* p );
387
+
388
+  // Wrapper function to cmDataUnlink() and cmDataFree().
389
+  void      cmDataUnlinkAndFree( cmData_t* p );
390
+
391
+  // Replace the 'dst' node with the 'src' node and
392
+  // return 'src'.  This operation does not duplicate
393
+  // 'src' it simply links in 'src' at the location of
394
+  // 'dst' and then unlinks and free's 'dst'.
395
+  cmData_t* cmDataReplace( cmData_t* dst, cmData_t* src );
396
+
397
+  // Return the count of child nodes.
398
+  // 1. Array nodes have one child per array element.
399
+  // 2. List nodes have one child pair.
400
+  // 3. Pair nodes have two children.
401
+  // 4. Leaf nodes have 0 children.
402
+  unsigned  cmDataChildCount( const cmData_t* p );
403
+
404
+  // Returns the ith child of 'p'.
405
+  // Returns NULL if p has no children or index is invalid.
406
+  cmData_t* cmDataChild( cmData_t* p, unsigned index );
407
+
408
+  // Prepend 'p' to 'parents' child list.
409
+  // The source node 'p' is not duplicated  it is simply linked in.
410
+  // 'p' is automatically unlinked prior to being prepended.
411
+  // Returns 'p'. 
412
+  cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p );
413
+
414
+  // Append 'p' to the end of 'parent' child list.
415
+  // The source node 'p' is not duplicated it is simply linked in.
416
+  // 'p' is automatically unlinked prior to being appended.
417
+  // Returns 'p'. 
418
+  cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p );
419
+
420
+  // Insert 'p' at index.  Index must be in the range: 
421
+  // 0 to cmDataChildCount(parent).
422
+  // The source node 'p' is not duplicated it is simply linked in.
423
+  // 'p' is automatically unlinked prior to being inserted.
424
+  // Returns 'p'.
425
+  cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p );
426
+
427
+
428
+
429
+////////////////////////////////////////////////////////////////////////////////////////////////
430
+////////////////////////////////////////////////////////////////////////////////////////////////
431
+////////////////////////////////////////////////////////////////////////////////////////////////
432
+////////////////////////////////////////////////////////////////////////////////////////////////
433
+
434
+#ifdef NOT_DEF
32 435
   typedef enum
33 436
   {
34 437
     kInvalidDtId,
@@ -131,47 +534,6 @@ extern "C" {
131 534
   bool cmDataIsPtr(    const cmData_t* p );
132 535
   bool cmDataIsStruct( const cmData_t* p ); // is a pair,list or record
133 536
 
134
-  /*
135
-    TODO:
136
-    0) Figure out a error handling scheme that does not rely on
137
-    a global errno.  This is not useful in multi-thread environments.
138
-    It might be ok to go with an 'all errors are fatal' model
139
-    (except in the var-args functions).
140
-    Consider the use of a context object for use with functions 
141
-    that can have runtime errors or need to allocate memory.
142
-
143
-    1) Implement the canConvert and willTruncate functions.
144
-
145
-    2) Make a set of cmDataAllocXXXPtr() functions which take
146
-    a flag indicating whether or not to dynamically allocate
147
-    the array space. This will allow dynamic allocattion to
148
-    occur at runtime.  Make var args functions for list and
149
-    record objects which also take this flag.
150
-    Where ever a function may be implemented using 
151
-    static/dynamic allocation this flag should be present.
152
-    (e.g. string allocation for pair labels)
153
-    This choice is common enough that it may be worth
154
-    suffixing function names with a capital letter to
155
-    be clear what the functions memory policy is.
156
-
157
-    3) Come up with a var-args format which allows a 
158
-    hierchy of records to be defined in one line.
159
-
160
-    4) Implement the serialization functions.
161
-
162
-    5) Implement an ascii string/parse format for writing/reading.
163
-
164
-    6) Implement fast lookup of record fields.
165
-
166
-    7) Allow for user defined types.  For example a 'matrix'
167
-    data type. This might be as simple as adding an extra 'user_tid' 
168
-    field to cmData_t.
169
-
170
-    8) Implement type specific cmDataGetRecordValueXXX() functions.
171
-
172
-    9) Implement cmDataIsEqual(), cmDataIsLtE(), ...
173
-
174
-   */
175 537
 
176 538
   bool canConvertType( cmDataFmtId_t srcId, cmDataFmtId_t dstId );
177 539
   bool willTruncate(   cmDataFmtId_t srcId, cmDataFmtId_t dstId );
@@ -556,7 +918,7 @@ extern "C" {
556 918
   void     cmDataPrint( const cmData_t* p, cmRpt_t* rpt );
557 919
   
558 920
   void     cmDataTest( cmCtx_t* ctx );
559
-
921
+#endif
560 922
 
561 923
 
562 924
 #ifdef __cplusplus

Loading…
Peruuta
Tallenna