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 24KB

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