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

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