libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmData.h 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543
  1. #ifndef cmData_h
  2. #define cmData_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. enum
  7. {
  8. kOkDtRC = cmOkRC,
  9. kCvtErrDtRC,
  10. kVarArgErrDtRC,
  11. kMissingFieldDtRC,
  12. kEolDtRC
  13. };
  14. enum
  15. {
  16. kInvalidDtChar = 0xff,
  17. kInvalidDtUChar = 0xff,
  18. kInvalidDtShort = 0xffff,
  19. kInvalidDtUShort = 0xffff,
  20. kInvalidDtInt = 0xffffffff,
  21. kInvalidDtUInt = 0xffffffff,
  22. kInvalidDtLong = 0xffffffff,
  23. kInvalidDtULong = 0xffffffff,
  24. };
  25. typedef enum
  26. {
  27. kInvalidDtId,
  28. kMinValDtId,
  29. kNullDtId = kMinValDtId,
  30. kUCharDtId,
  31. kCharDtId,
  32. kUShortDtId,
  33. kShortDtId,
  34. kUIntDtId,
  35. kIntDtId,
  36. kULongDtId,
  37. kLongDtId,
  38. kFloatDtId,
  39. kDoubleDtId,
  40. kStrDtId,
  41. kConstStrDtId,
  42. kMaxValDtId = kConstStrDtId,
  43. kMinPtrDtId,
  44. kUCharPtrDtId = kMinPtrDtId, // cnt=array element count
  45. kCharPtrDtId,
  46. kUShortPtrDtId,
  47. kShortPtrDtId,
  48. kUIntPtrDtId,
  49. kIntPtrDtId,
  50. kULongPtrDtId,
  51. kLongPtrDtId,
  52. kFloatPtrDtId,
  53. kDoublePtrDtId,
  54. kVoidPtrDtId,
  55. kMaxPtrDtId = kVoidPtrDtId,
  56. kMinStructDtId,
  57. kListDtId = kMinStructDtId, // children nodes are array elements, cnt=child count
  58. kPairDtId, // key/value pairs, cnt=2, first child is key, second is value
  59. kRecordDtId, // children nodes are pairs, cnt=pair count
  60. kMaxStructDtId,
  61. kOptArgDtFl = 0x80000000
  62. } cmDataFmtId_t;
  63. enum
  64. {
  65. kDynObjDtFl = 0x01, // object was dynamically allocated
  66. kDynPtrDtFl = 0x02 // ptr array was dynamically allocated
  67. };
  68. typedef struct cmData_str
  69. {
  70. cmDataFmtId_t tid; // data format id
  71. unsigned flags; //
  72. struct cmData_str* parent; // this childs parent
  73. struct cmData_str* sibling; // this childs left sibling
  74. unsigned cnt; // array ele count
  75. union
  76. {
  77. char c;
  78. unsigned char uc;
  79. short s;
  80. unsigned short us;
  81. int i;
  82. unsigned int ui;
  83. long l;
  84. unsigned long ul;
  85. float f;
  86. double d;
  87. cmChar_t* z;
  88. const cmChar_t* cz;
  89. void* vp;
  90. char* cp;
  91. unsigned char* ucp;
  92. short* sp;
  93. unsigned short* usp;
  94. int* ip;
  95. unsigned int* uip;
  96. long* lp;
  97. unsigned long* ulp;
  98. float* fp;
  99. double* dp;
  100. struct cmData_str* child; // first child (array,record,pair)
  101. } u;
  102. } cmData_t;
  103. typedef unsigned cmDtRC_t;
  104. extern cmData_t cmDataNull;
  105. bool cmDataIsValue( const cmData_t* p );
  106. bool cmDataIsPtr( const cmData_t* p );
  107. bool cmDataIsStruct( const cmData_t* p ); // is a pair,list or record
  108. /*
  109. TODO:
  110. 0) Figure out a error handling scheme that does not rely on
  111. a global errno. This is not useful in multi-thread environments.
  112. It might be ok to go with an 'all errors are fatal' model
  113. (except in the var-args functions).
  114. Consider the use of a context object for use with functions
  115. that can have runtime errors or need to allocate memory.
  116. 1) Implement the canConvert and willTruncate functions.
  117. 2) Make a set of cmDataAllocXXXPtr() functions which take
  118. a flag indicating whether or not to dynamically allocate
  119. the array space. This will allow dynamic allocattion to
  120. occur at runtime. Make var args functions for list and
  121. record objects which also take this flag.
  122. Where ever a function may be implemented using
  123. static/dynamic allocation this flag should be present.
  124. (e.g. string allocation for pair labels)
  125. This choice is common enough that it may be worth
  126. suffixing function names with a capital letter to
  127. be clear what the functions memory policy is.
  128. 3) Come up with a var-args format which allows a
  129. hierchy of records to be defined in one line.
  130. 4) Implement the serialization functions.
  131. 5) Implement an ascii string/parse format for writing/reading.
  132. 6) Implement fast lookup of record fields.
  133. 7) Allow for user defined types. For example a 'matrix'
  134. data type. This might be as simple as adding an extra 'user_tid'
  135. field to cmData_t.
  136. 8) Implement type specific cmDataGetRecordValueXXX() functions.
  137. 9) Implement cmDataIsEqual(), cmDataIsLtE(), ...
  138. */
  139. bool canConvertType( cmDataFmtId_t srcId, cmDataFmtId_t dstId );
  140. bool willTruncate( cmDataFmtId_t srcId, cmDataFmtId_t dstId );
  141. bool canConvertObj( const cmData_t* srcObj, cmData_t* dstObj );
  142. bool willTruncateObj(const cmData_t* srcObj, cmData_t* dstObj );
  143. // Get the value of an object without conversion.
  144. // The data type id must match the return type or the
  145. // conversion must be an automatic C conversion.
  146. char cmDataChar( const cmData_t* p );
  147. unsigned char cmDataUChar( const cmData_t* p );
  148. short cmDataShort( const cmData_t* p );
  149. unsigned short cmDataUShort( const cmData_t* p );
  150. int cmDataInt( const cmData_t* p );
  151. unsigned int cmDataUInt( const cmData_t* p );
  152. long cmDataLong( const cmData_t* p );
  153. unsigned long cmDataULong( const cmData_t* p );
  154. float cmDataFloat( const cmData_t* p );
  155. double cmDataDouble( const cmData_t* p );
  156. cmChar_t* cmDataStr( const cmData_t* p );
  157. const cmChar_t* cmDataConstStr( const cmData_t* p );
  158. void* cmDataVoidPtr( const cmData_t* p );
  159. char* cmDataCharPtr( const cmData_t* p );
  160. unsigned char* cmDataUCharPtr( const cmData_t* p );
  161. short* cmDataShortPtr( const cmData_t* p );
  162. unsigned short* cmDataUShortPtr( const cmData_t* p );
  163. int* cmDataIntPtr( const cmData_t* p );
  164. unsigned int* cmDataUIntPtr( const cmData_t* p );
  165. long* cmDataLongPtr( const cmData_t* p );
  166. unsigned long* cmDataULongPtr( const cmData_t* p );
  167. float* cmDataFloatPtr( const cmData_t* p );
  168. double* cmDataDoublePtr( const cmData_t* p );
  169. // Get the value of an object with conversion.
  170. cmDtRC_t cmDataGetChar( const cmData_t* p, char* v );
  171. cmDtRC_t cmDataGetUChar( const cmData_t* p, unsigned char* v );
  172. cmDtRC_t cmDataGetShort( const cmData_t* p, short* v );
  173. cmDtRC_t cmDataGetUShort( const cmData_t* p, unsigned short* v );
  174. cmDtRC_t cmDataGetInt( const cmData_t* p, int* v );
  175. cmDtRC_t cmDataGetUInt( const cmData_t* p, unsigned int* v );
  176. cmDtRC_t cmDataGetLong( const cmData_t* p, long* v );
  177. cmDtRC_t cmDataGetULong( const cmData_t* p, unsigned long* v );
  178. cmDtRC_t cmDataGetFloat( const cmData_t* p, float* v );
  179. cmDtRC_t cmDataGetDouble( const cmData_t* p, double* v );
  180. // Returns the pointer - does not copy the data.
  181. cmDtRC_t cmDataGetStr( const cmData_t* p, char** v );
  182. cmDtRC_t cmDataGetConstStr( const cmData_t* p, const char** v );
  183. cmDtRC_t cmDataGetVoidPtr( const cmData_t* p, void** v );
  184. cmDtRC_t cmDataGetCharPtr( const cmData_t* p, char** v );
  185. cmDtRC_t cmDataGetUCharPtr( const cmData_t* p, unsigned char** v );
  186. cmDtRC_t cmDataGetShortPtr( const cmData_t* p, short** v );
  187. cmDtRC_t cmDataGetUShortPtr( const cmData_t* p, unsigned short** v );
  188. cmDtRC_t cmDataGetIntPtr( const cmData_t* p, int** v );
  189. cmDtRC_t cmDataGetUIntPtr( const cmData_t* p, unsigned int** v );
  190. cmDtRC_t cmDataGetLongPtr( const cmData_t* p, long** v );
  191. cmDtRC_t cmDataGetULongPtr( const cmData_t* p, unsigned long** v );
  192. cmDtRC_t cmDataGetFloatPtr( const cmData_t* p, float** v );
  193. cmDtRC_t cmDataGetDoublePtr( const cmData_t* p, double** v );
  194. // Set the value and type of an existing scalar object.
  195. // These functions begin by releasing any resources held by *p
  196. // prior to resetting the type and value of the object.
  197. cmData_t* cmDataSetNull( cmData_t* p );
  198. cmData_t* cmDataSetChar( cmData_t* p, char v );
  199. cmData_t* cmDataSetUChar( cmData_t* p, unsigned char v );
  200. cmData_t* cmDataSetShort( cmData_t* p, short v );
  201. cmData_t* cmDataSetUShort( cmData_t* p, unsigned short v );
  202. cmData_t* cmDataSetInt( cmData_t* p, int v );
  203. cmData_t* cmDataSetUInt( cmData_t* p, unsigned int v );
  204. cmData_t* cmDataSetLong( cmData_t* p, long v );
  205. cmData_t* cmDataSetULong( cmData_t* p, unsigned long v );
  206. cmData_t* cmDataSetFloat( cmData_t* p, float v );
  207. cmData_t* cmDataSetDouble( cmData_t* p, double v );
  208. cmData_t* cmDataSetStr( cmData_t* p, cmChar_t* s );
  209. cmData_t* cmDataSetConstStr( cmData_t* p, const cmChar_t* s );
  210. // Set the type and value of an existing data object to an external array.
  211. // These functions begin by releasing any resources help by *p.
  212. // The array pointed to by 'vp' is not copied or duplicated.
  213. // 'vp' is simply assigned as the data space for the object and therefore must remain
  214. // valid for the life of the object.
  215. cmData_t* cmDataSetVoidPtr( cmData_t* p, void* vp, unsigned cnt );
  216. cmData_t* cmDataSetCharPtr( cmData_t* p, char* vp, unsigned cnt );
  217. cmData_t* cmDataSetUCharPtr( cmData_t* p, unsigned char* vp, unsigned cnt );
  218. cmData_t* cmDataSetShortPtr( cmData_t* p, short* vp, unsigned cnt );
  219. cmData_t* cmDataSetUShortPtr( cmData_t* p, unsigned short* vp, unsigned cnt );
  220. cmData_t* cmDataSetIntPtr( cmData_t* p, int* vp, unsigned cnt );
  221. cmData_t* cmDataSetUIntPtr( cmData_t* p, unsigned int* vp, unsigned cnt );
  222. cmData_t* cmDataSetLongPtr( cmData_t* p, long* vp, unsigned cnt );
  223. cmData_t* cmDataSetULongPtr( cmData_t* p, unsigned long* vp, unsigned cnt );
  224. cmData_t* cmDataSetFloatPtr( cmData_t* p, float* vp, unsigned cnt );
  225. cmData_t* cmDataSetDoublePtr( cmData_t* p, double* vp, unsigned cnt );
  226. // Set the value of an existing array based data object.
  227. // These functions begin by releasing any resources help by *p
  228. // and then dynamically allocate the internal array and copy
  229. // the array data into it.
  230. cmData_t* cmDataSetStrAlloc( cmData_t* p, const cmChar_t* s );
  231. cmData_t* cmDataSetConstStrAlloc( cmData_t* p, const cmChar_t* s );
  232. cmData_t* cmDataSetVoidAllocPtr( cmData_t* p, const void* vp, unsigned cnt );
  233. cmData_t* cmDataSetCharAllocPtr( cmData_t* p, const char* vp, unsigned cnt );
  234. cmData_t* cmDataSetUCharAllocPtr( cmData_t* p, const unsigned char* vp, unsigned cnt );
  235. cmData_t* cmDataSetShortAllocPtr( cmData_t* p, const short* vp, unsigned cnt );
  236. cmData_t* cmDataSetUShortAllocPtr( cmData_t* p, const unsigned short* vp, unsigned cnt );
  237. cmData_t* cmDataSetIntAllocPtr( cmData_t* p, const int* vp, unsigned cnt );
  238. cmData_t* cmDataSetUIntAllocPtr( cmData_t* p, const unsigned int* vp, unsigned cnt );
  239. cmData_t* cmDataSetLongAllocPtr( cmData_t* p, const long* vp, unsigned cnt );
  240. cmData_t* cmDataSetULongAllocPtr( cmData_t* p, const unsigned long* vp, unsigned cnt );
  241. cmData_t* cmDataSetFloatAllocPtr( cmData_t* p, const float* vp, unsigned cnt );
  242. cmData_t* cmDataSetDoubleAllocPtr( cmData_t* p, const double* vp, unsigned cnt );
  243. // Dynamically allocate a data object and set it's value.
  244. cmData_t* cmDataAllocNull( cmData_t* parent );
  245. cmData_t* cmDataAllocChar( cmData_t* parent, char v );
  246. cmData_t* cmDataAllocUChar( cmData_t* parent, unsigned char v );
  247. cmData_t* cmDataAllocShort( cmData_t* parent, short v );
  248. cmData_t* cmDataAllocUShort( cmData_t* parent, unsigned short v );
  249. cmData_t* cmDataAllocInt( cmData_t* parent, int v );
  250. cmData_t* cmDataAllocUInt( cmData_t* parent, unsigned int v );
  251. cmData_t* cmDataAllocLong( cmData_t* parent, long v );
  252. cmData_t* cmDataAllocULong( cmData_t* parent, unsigned long v );
  253. cmData_t* cmDataAllocFloat( cmData_t* parent, float v );
  254. cmData_t* cmDataAllocDouble( cmData_t* parent, double v );
  255. // Dynamically allocate a data object and set its array value to an external
  256. // array. v[cnt] is assigned as the internal data space for the object and
  257. // therefore must remain valid for the life of the object.
  258. // See the cmDataXXXAlocPtr() for equivalent functions which dynamically
  259. // allocate the intenal data space.
  260. cmData_t* cmDataAllocStr( cmData_t* parent, cmChar_t* str );
  261. cmData_t* cmDataAllocConstStr( cmData_t* parent, const cmChar_t* str );
  262. cmData_t* cmDataAllocCharPtr( cmData_t* parent, char* v, unsigned cnt );
  263. cmData_t* cmDataAllocUCharPtr( cmData_t* parent, unsigned char* v, unsigned cnt );
  264. cmData_t* cmDataAllocShortPtr( cmData_t* parent, short* v, unsigned cnt );
  265. cmData_t* cmDataAllocUShortPtr( cmData_t* parent, unsigned short* v, unsigned cnt );
  266. cmData_t* cmDataAllocIntPtr( cmData_t* parent, int* v, unsigned cnt );
  267. cmData_t* cmDataAllocUIntPtr( cmData_t* parent, unsigned int* v, unsigned cnt );
  268. cmData_t* cmDataAllocLongPtr( cmData_t* parent, long* v, unsigned cnt );
  269. cmData_t* cmDataAllocULongPtr( cmData_t* parent, unsigned long* v, unsigned cnt );
  270. cmData_t* cmDataAllocFloatPtr( cmData_t* parent, float* v, unsigned cnt );
  271. cmData_t* cmDataAllocDoublePtr( cmData_t* parent, double* v, unsigned cnt );
  272. cmData_t* cmDataAllocVoidPtr( cmData_t* parent, void* v, unsigned cnt );
  273. // Dynamically allocate a data object and its array value.
  274. // These functions dynamically allocate the internal array data space
  275. // and copy v[cnt] into it.
  276. cmData_t* cmDataStrAlloc( cmData_t* parent, cmChar_t* str );
  277. cmData_t* cmDataConstStrAlloc( cmData_t* parent, const cmChar_t* str );
  278. cmData_t* cmDataCharAllocPtr( cmData_t* parent, const char* v, unsigned cnt );
  279. cmData_t* cmDataUCharAllocPtr( cmData_t* parent, const unsigned char* v, unsigned cnt );
  280. cmData_t* cmDataShortAllocPtr( cmData_t* parent, const short* v, unsigned cnt );
  281. cmData_t* cmDataUShortAllocPtr( cmData_t* parent, const unsigned short* v, unsigned cnt );
  282. cmData_t* cmDataIntAllocPtr( cmData_t* parent, const int* v, unsigned cnt );
  283. cmData_t* cmDataUIntAllocPtr( cmData_t* parent, const unsigned int* v, unsigned cnt );
  284. cmData_t* cmDataLongAllocPtr( cmData_t* parent, const long* v, unsigned cnt );
  285. cmData_t* cmDataULongAllocPtr( cmData_t* parent, const unsigned long* v, unsigned cnt );
  286. cmData_t* cmDataFloatAllocPtr( cmData_t* parent, const float* v, unsigned cnt );
  287. cmData_t* cmDataDoubleAllocPtr( cmData_t* parent, const double* v, unsigned cnt );
  288. cmData_t* cmDataVoidAllocPtr( cmData_t* parent, const void* v, unsigned cnt );
  289. //----------------------------------------------------------------------------
  290. // Structure related functions
  291. //
  292. // Release an object and any resources held by it.
  293. // Note the this function does not unlink the object
  294. // from it's parent. Use cmDataUnlinkAndFree()
  295. // to remove a object from it's parent list prior
  296. // to releasing it.
  297. void cmDataFree( cmData_t* p );
  298. // Unlink 'p' from its parents and siblings.
  299. // Asserts if parent is not a structure.
  300. // Returns 'p'.
  301. cmData_t* cmDataUnlink( cmData_t* p );
  302. // Wrapper function to cmDataUnlink() and cmDataFree().
  303. void cmDataUnlinkAndFree( cmData_t* p );
  304. // Replace the 'dst' node with the 'src' node and
  305. // return 'src'. This operation does not duplicate
  306. // 'src' it simply links in 'src' at the location of
  307. // 'dst' and then unlinks and free's 'dst'.
  308. cmData_t* cmDataReplace( cmData_t* dst, cmData_t* src );
  309. // Return the count of child nodes.
  310. // 1. Array nodes have one child per array element.
  311. // 2. List nodes have one child pair.
  312. // 3. Pair nodes have two children.
  313. // 4. Leaf nodes have 0 children.
  314. unsigned cmDataChildCount( const cmData_t* p );
  315. // Returns the ith child of 'p'.
  316. // Returns NULL if p has no children or index is invalid.
  317. cmData_t* cmDataChild( cmData_t* p, unsigned index );
  318. // Prepend 'p' to 'parents' child list.
  319. // The source node 'p' is not duplicated it is simply linked in.
  320. // 'p' is automatically unlinked prior to being prepended.
  321. // Returns 'p'.
  322. cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p );
  323. // Append 'p' to the end of 'parent' child list.
  324. // The source node 'p' is not duplicated it is simply linked in.
  325. // 'p' is automatically unlinked prior to being appended.
  326. // Returns 'p'.
  327. cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p );
  328. // Insert 'p' at index. Index must be in the range:
  329. // 0 to cmDataChildCount(parent).
  330. // The source node 'p' is not duplicated it is simply linked in.
  331. // 'p' is automatically unlinked prior to being inserted.
  332. // Returns 'p'.
  333. cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p );
  334. //----------------------------------------------------------------------------
  335. // Pair related functions
  336. //
  337. // Get the key/value of a pair
  338. cmData_t* cmDataPairKey( cmData_t* p );
  339. unsigned cmDataPairKeyId( cmData_t* p );
  340. const cmChar_t* cmDataPairKeyLabel( cmData_t* p );
  341. cmData_t* cmDataPairValue( cmData_t* p );
  342. // Set the value of an existing pair node.
  343. // 'value' is not duplicated it is simply linked in place of the
  344. // previous pair value node. The previous pair value node is
  345. // unlinked and freed.
  346. // Returns 'p'.
  347. cmData_t* cmDataPairSetValue( cmData_t* p, cmData_t* value );
  348. // Set the key of an existing pair node.
  349. // The previous key is unlinked and freed.
  350. cmData_t* cmDataPairSetKey( cmData_t* p, cmData_t* key );
  351. cmData_t* cmDataPairSetKeyId( cmData_t* p, unsigned id );
  352. // The data space for the 'label' string is dynamically allocated.
  353. cmData_t* cmDataPairSetKeyLabel( cmData_t* p, const cmChar_t* label );
  354. // Create a pair value by assigning a key and value to 'p'.
  355. // 'p' is unlinked and freed prior to the key value assignment.
  356. // 'key' and 'value' are simply linked in they are not duplicated or reallocated.
  357. cmData_t* cmDataMakePair( cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t* value );
  358. // Dynamically allocate a pair node. Both the key and value nodes are reallocated.
  359. cmData_t* cmDataAllocPair( cmData_t* parent, const cmData_t* key, const cmData_t* value );
  360. // Dynamically allocate the id but link (w/o realloc) the value.
  361. cmData_t* cmDataAllocPairId( cmData_t* parent, unsigned keyId, cmData_t* value );
  362. // Dynamically allocate the label but link (w/o realloc) the value.
  363. cmData_t* cmDataAllocPairLabel( cmData_t* parent, const cmChar_t* label, cmData_t* value );
  364. //----------------------------------------------------------------------------
  365. // List related functions
  366. //
  367. // Return the count of ele's in the list.
  368. unsigned cmDataListCount( const cmData_t* p );
  369. // Return the ith element in the list.
  370. cmData_t* cmDataListEle( cmData_t* p, unsigned index );
  371. cmData_t* cmDataListMake( cmData_t* parent, cmData_t* p );
  372. cmData_t* cmDataListAlloc( cmData_t* parent);
  373. // Var-args fmt:
  374. // <typeId> <value> {<cnt>}
  375. // scalar types: <value> is literal,<cnt> is not included
  376. // null has no <value> or <cnt>
  377. // ptr types: <value> is pointer,<cnt> is element count
  378. // struct types: <value> is cmData_t, <cnt> is not included
  379. // Indicate the end of argument list by setting <typeId> to kInvalidDtId.
  380. // The memory for array based data types is dynamically allocated.
  381. cmData_t* cmDataListAllocV(cmData_t* parent, va_list vl );
  382. cmData_t* cmDataListAllocA(cmData_t* parent, ... );
  383. // Returns a ptr to 'ele'.
  384. cmData_t* cmDataListAppendEle( cmData_t* p, cmData_t* ele );
  385. cmDtRC_t cmDataListAppendV( cmData_t* p, va_list vl );
  386. cmDtRC_t cmDataListAppend( cmData_t* p, ... );
  387. // Return 'p'.
  388. cmData_t* cmDataListInsertEle( cmData_t* p, unsigned index, cmData_t* ele );
  389. cmData_t* cmDataListInsertEleN(cmData_t* p, unsigned index, cmData_t* ele[], unsigned n );
  390. cmData_t* cmDataListUnlink( cmData_t* p, unsigned index );
  391. cmData_t* cmDataListFree( cmData_t* p, unsigned index );
  392. //----------------------------------------------------------------------------
  393. // Record related functions
  394. //
  395. // Return count of pairs.
  396. unsigned cmDataRecdCount( const cmData_t* p );
  397. // Return the ith pair.
  398. cmData_t* cmDataRecdEle( cmData_t* p, unsigned index );
  399. // Return the ith value.
  400. cmData_t* cmDataRecdValueFromIndex( cmData_t* p, unsigned index );
  401. cmData_t* cmDataRecdValueFromId( cmData_t* p, unsigned id );
  402. cmData_t* cmDataRecdValueFromLabel( cmData_t* p, const cmChar_t* label );
  403. // Return the ith key
  404. cmData_t* cmDataRecdKey( cmData_t* p, unsigned index );
  405. unsigned cmDataRecdKeyId( cmData_t* p, unsigned index );
  406. const cmChar_t* cmDataRecdKeyLabel( cmData_t* p, unsigned index );
  407. cmData_t* cmRecdMake( cmData_t* parent, cmData_t* p );
  408. cmData_t* cmRecdAlloc( cmData_t* parent );
  409. // Append a pair node by linking the pair node 'pair' to the record node 'p'.
  410. // 'pair' is simply linked to 'p' via cmDataAppendChild() no
  411. // reallocation or duplicattion takes place.
  412. cmData_t* cmRecdAppendPair( cmData_t* p, cmData_t* pair );
  413. // Var-args format:
  414. // <label|id> <typeId> <value> {<cnt>}
  415. // scalar types: <value> is literal,<cnt> is not included
  416. // null type: has no <value> or <cnt>
  417. // ptr types: <value> is pointer, <cnt> is element count
  418. // struct types: <value> is cmData_t, <cnt> is not included
  419. // Indicate the end of argument list by setting <typeId> to kInvalidDtId.
  420. // The memory for array based data types is dynamically allocated.
  421. cmData_t* cmDataRecdAllocLabelV( cmData_t* parent, va_list vl );
  422. cmData_t* cmDataRecdAllocLabelA( cmData_t* parent, ... );
  423. cmData_t* cmDataRecdAllocIdV( cmData_t* parent, va_list vl );
  424. cmData_t* cmDataRecdAllocIdA( cmData_t* parent, ... );
  425. // Extract the data in a record to C variables.
  426. // The var-args list must be NULL terminated.
  427. // The <'id' | 'label'> identify a pair.
  428. // The <typeId> indicates the C type of 'pointer'.
  429. // The actual field type must be convertable into this pointer type or the
  430. // function will fail.
  431. // 'err' is an application supplied error object to be used if a required
  432. // field is missing. 'errRC' is the client result code to be passed with
  433. // the error report. See cmErrMsg(). Both 'err' and 'errRC' are optional.
  434. // Set kOptArgDtFl on 'typeId' to indicate that a field is optional.
  435. // <label|id> (<typeId> | kOptArgDtFl) <pointer>
  436. cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl );
  437. cmDtRC_t cmDataRecdParseLabel( cmData_t* p, cmErr_t* err, unsigned errRC, ... );
  438. cmDtRC_t cmDataRecdParseIdV( cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl );
  439. cmDtRC_t cmDataRecdParseId( cmData_t* p, cmErr_t* err, unsigned errRC, ... );
  440. unsigned cmDataSerializeByteCount( const cmData_t* p );
  441. cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt );
  442. cmDtRC_t cmDataDeserialize( const void* buf, unsigned bufByteCnt, cmData_t** pp );
  443. void cmDataPrint( const cmData_t* p, cmRpt_t* rpt );
  444. void cmDataTest( cmCtx_t* ctx );
  445. #ifdef __cplusplus
  446. }
  447. #endif
  448. #endif