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.

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