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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928
  1. #ifndef cmData_h
  2. #define cmData_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /*
  7. TODO:
  8. 0) Figure out a error handling scheme that does not rely on
  9. a global errno. This is not useful in multi-thread environments.
  10. It might be ok to go with an 'all errors are fatal' model
  11. (except in the var-args functions).
  12. Consider the use of a context object for use with functions
  13. that can have runtime errors or need to allocate memory.
  14. 1) Implement the canConvert and willTruncate functions.
  15. 2) Make a set of cmDataAllocXXXPtr() functions which take
  16. a flag indicating whether or not to dynamically allocate
  17. the array space. This will allow dynamic allocattion to
  18. occur at runtime. Make var args functions for list and
  19. record objects which also take this flag.
  20. Whereever a function may be implemented using
  21. static/dynamic allocation this flag should be present.
  22. (e.g. string allocation for pair labels)
  23. This choice is common enough that it may be worth
  24. suffixing function names with a capital letter to
  25. be clear what the functions memory policy is.
  26. 3) Come up with a var-args format which allows a
  27. hierchy of records to be defined in one line.
  28. 4) Implement the serialization functions.
  29. 5) Implement an ascii string/parse format for writing/reading.
  30. 6) Implement fast lookup of record fields.
  31. 7) Allow for user defined types. For example a 'matrix'
  32. data type. This might be as simple as adding an extra 'user_tid'
  33. field to cmData_t.
  34. 8) Implement type specific cmDataGetRecordValueXXX() functions.
  35. 9) Implement cmDataIsEqual(), cmDataIsLtE(), ...
  36. */
  37. enum
  38. {
  39. kOkDtRC = cmOkRC,
  40. kAssertErrDtRC,
  41. kConstErrDtRC,
  42. kCvtErrDtRC,
  43. kInvalidContDtRC,
  44. kInvalidTypeDtRC,
  45. kEolDtRC
  46. };
  47. typedef unsigned cmDtRC_t;
  48. typedef enum
  49. {
  50. kInvalidTypeDtId,// 0
  51. kNullDtId, // 1 the data object exists but it has no data
  52. kUCharDtId, // 2
  53. kCharDtId, // 3
  54. kUShortDtId, // 4
  55. kShortDtId, // 5
  56. kUIntDtId, // 6
  57. kIntDtId, // 7
  58. kULongDtId, // 8
  59. kLongDtId, // 9
  60. kFloatDtId, // 10
  61. kDoubleDtId, // 11
  62. kStrDtId, // 12 zero terminated string
  63. kBlobDtId // 13 application defined raw memory object
  64. } cmDataTypeId_t;
  65. typedef enum
  66. {
  67. kInvalidCntDtId, // 0
  68. kScalarDtId, // 1
  69. kArrayDtId, // 2
  70. kPairDtId, // 3
  71. kListDtId, // 4
  72. kRecordDtId // 5
  73. } cmDataContainerId_t;
  74. enum
  75. {
  76. kNoFlagsDtFl = 0x00,
  77. // Indicate that the memory used by the data object
  78. // was dynamically allocated and should be released
  79. // by cmDataFree().
  80. kFreeObjDtFl = 0x01,
  81. // Indicate that the memory used by strings, blobs
  82. // and arrays should be freed by cmDataFree().
  83. kFreeValueDtFl = 0x02,
  84. // Indicate that the value of the object cannot be changed.
  85. // (but the object could be reassigned as a new type).
  86. kConstValueDtFl = 0x04,
  87. // Indicate that the type of the object cannot be changed.
  88. // (but the value may be changed).
  89. kConstObjDtFl = 0x08,
  90. // Indicate that the array or string should not be
  91. // internally reallocated but rather the source pointer
  92. // should be taken as the new value of the object.
  93. kNoCopyDtFl = 0x10,
  94. };
  95. typedef struct cmData_str
  96. {
  97. cmDataTypeId_t tid; // data format id
  98. cmDataContainerId_t cid; // container id
  99. unsigned flags; //
  100. struct cmData_str* parent; // this childs parent
  101. struct cmData_str* sibling; // this childs left sibling
  102. unsigned cnt; // byte cnt for strings/blobs and ele count for arrays
  103. union
  104. {
  105. char c;
  106. unsigned char uc;
  107. short s;
  108. unsigned short us;
  109. int i;
  110. unsigned int ui;
  111. long l;
  112. unsigned long ul;
  113. float f;
  114. double d;
  115. cmChar_t* z;
  116. void* vp;
  117. char* cp;
  118. unsigned char* ucp;
  119. short* sp;
  120. unsigned short* usp;
  121. int* ip;
  122. unsigned int* uip;
  123. long* lp;
  124. unsigned long* ulp;
  125. float* fp;
  126. double* dp;
  127. struct cmData_str* child; // first child (list,record,pair)
  128. } u;
  129. } cmData_t;
  130. extern cmData_t cmDataNull;
  131. const cmChar_t* cmDataTypeToLabel( cmDataTypeId_t tid );
  132. cmDataTypeId_t cmDataLabelToType( const cmChar_t* typeLabelStr );
  133. // Returns 1 for kStrDtId.
  134. // Returns cmInvalidCnt if tid is not recognized.
  135. unsigned dmDataByteWidth( cmDataTypeId_t tid );
  136. const cmChar_t* cmDataContainerIdToLabel( cmDataContainerId_t tid );
  137. cmDataContainerId_t cmDataLabelToContainerId( const cmChar_t* contLabelStr );
  138. bool cmDataIsConstObj( const cmData_t* d );
  139. void cmDataEnableConstObj( cmData_t* d, bool enaFl );
  140. bool cmDataIsConstValue( const cmData_t* d );
  141. void cmDataEnableConstValue( cmData_t* d, bool enaFl );
  142. bool cmDataIsFreeValue( const cmData_t* d );
  143. void cmDataEnableFreeValue( cmData_t* d, bool enaFl );
  144. // Returns true if this is a scalar or array node.
  145. bool cmDataIsLeaf( const cmData_t* d);
  146. // Return true if this is NOT a scalar or array node.
  147. bool cmDataIsStruct( const cmData_t* d );
  148. //----------------------------------------------------------------------------
  149. // Scalar related functions
  150. //
  151. // Dynamically allocate a scalar object and set it's value.
  152. // The 'flags' argument may include kConstValueDtFl and kConstObjDtFl.
  153. // The string and blob constructors may also use the
  154. // kNoCopyDtFl and the kFreeValueDtFl.
  155. // Generic:
  156. // 'byteCnt' is ignored for all types other than strings and blobs.
  157. cmDtRC_t cmDataNewScalar( cmData_t* parent, cmDataTypeId_t tid, unsigned flags, void* vp, unsigned byteCnt, cmData_t** ref );
  158. // Type specific
  159. cmDtRC_t cmDataNewNull( cmData_t* parent, unsigned flags, cmData_t** ref );
  160. cmDtRC_t cmDataNewChar( cmData_t* parent, unsigned flags, char v, cmData_t** ref );
  161. cmDtRC_t cmDataNewUChar( cmData_t* parent, unsigned flags, unsigned char v, cmData_t** ref );
  162. cmDtRC_t cmDataNewShort( cmData_t* parent, unsigned flags, short v, cmData_t** ref );
  163. cmDtRC_t cmDataNewUShort( cmData_t* parent, unsigned flags, unsigned short v, cmData_t** ref );
  164. cmDtRC_t cmDataNewInt( cmData_t* parent, unsigned flags, int v, cmData_t** ref );
  165. cmDtRC_t cmDataNewUInt( cmData_t* parent, unsigned flags, unsigned int v, cmData_t** ref );
  166. cmDtRC_t cmDataNewLong( cmData_t* parent, unsigned flags, long v, cmData_t** ref );
  167. cmDtRC_t cmDataNewULong( cmData_t* parent, unsigned flags, unsigned long v, cmData_t** ref );
  168. cmDtRC_t cmDataNewFloat( cmData_t* parent, unsigned flags, float v, cmData_t** ref );
  169. cmDtRC_t cmDataNewDouble( cmData_t* parent, unsigned flags, double v, cmData_t** ref );
  170. cmDtRC_t cmDataNewStr( cmData_t* parent, unsigned flags, cmChar_t* str, cmData_t** ref );
  171. cmDtRC_t cmDataNewConstStr( cmData_t* parent, unsigned flags, const cmChar_t* str, cmData_t** ref );
  172. cmDtRC_t cmDataNewStrN( cmData_t* parent, unsigned flags, cmChar_t* str, unsigned charCnt, cmData_t** ref );
  173. cmDtRC_t cmDataNewConstStrN(cmData_t* parent, unsigned flags, const cmChar_t* str, unsigned charCnt, cmData_t** ref );
  174. cmDtRC_t cmDataNewBlob( cmData_t* parent, unsigned flags, void* vp, unsigned byteCnt, cmData_t** ref );
  175. cmDtRC_t cmDataNewConstBlob(cmData_t* parent, unsigned flags, const void* vp, unsigned byteCnt, cmData_t** ref );
  176. // Set the value and type of an existing scalar object.
  177. // These functions begin by releasing any resources held by *p
  178. // prior to resetting the type and value of the object.
  179. // The 'flags' argument to cmDataSetStr() and cmDataSetConstStr()
  180. // may use the kNoCopyDtFl and the kFreeValueDtFl
  181. cmDtRC_t cmDataSetScalarValue( cmData_t* d, cmDataTypeId_t tid, void* vp, unsigned byteCnt, unsigned flags );
  182. cmDtRC_t cmDataSetNull( cmData_t* p );
  183. cmDtRC_t cmDataSetChar( cmData_t* p, char v );
  184. cmDtRC_t cmDataSetUChar( cmData_t* p, unsigned char v );
  185. cmDtRC_t cmDataSetShort( cmData_t* p, short v );
  186. cmDtRC_t cmDataSetUShort( cmData_t* p, unsigned short v );
  187. cmDtRC_t cmDataSetInt( cmData_t* p, int v );
  188. cmDtRC_t cmDataSetUInt( cmData_t* p, unsigned int v );
  189. cmDtRC_t cmDataSetLong( cmData_t* p, long v );
  190. cmDtRC_t cmDataSetULong( cmData_t* p, unsigned long v );
  191. cmDtRC_t cmDataSetFloat( cmData_t* p, float v );
  192. cmDtRC_t cmDataSetDouble( cmData_t* p, double v );
  193. cmDtRC_t cmDataSetStr( cmData_t* p, unsigned flags, cmChar_t* s );
  194. cmDtRC_t cmDataSetConstStr( cmData_t* p, unsigned flags, const cmChar_t* s );
  195. cmDtRC_t cmDataSetStrN( cmData_t* p, unsigned flags, cmChar_t* s, unsigned charCnt );
  196. cmDtRC_t cmDataSetConstStrN( cmData_t* p, unsigned flags, const cmChar_t* s, unsigned charCnt );
  197. cmDtRC_t cmDataSetBlob( cmData_t* p, unsigned flags, void* v, unsigned byteCnt );
  198. cmDtRC_t cmDataSetConstBlob( cmData_t* p, unsigned flags, const void* v, unsigned byteCnt );
  199. // Get the value of an object. No conversion is applied the
  200. // type must match exactly or an error is generated.
  201. cmDtRC_t cmDataChar( const cmData_t* p, char* v );
  202. cmDtRC_t cmDataUChar( const cmData_t* p, unsigned char* v );
  203. cmDtRC_t cmDataShort( const cmData_t* p, short* v );
  204. cmDtRC_t cmDataUShort( const cmData_t* p, unsigned short* v );
  205. cmDtRC_t cmDataInt( const cmData_t* p, int* v );
  206. cmDtRC_t cmDataUInt( const cmData_t* p, unsigned int* v );
  207. cmDtRC_t cmDataLong( const cmData_t* p, long* v );
  208. cmDtRC_t cmDataULong( const cmData_t* p, unsigned long* v );
  209. cmDtRC_t cmDataFloat( const cmData_t* p, float* v );
  210. cmDtRC_t cmDataDouble( const cmData_t* p, double* v );
  211. cmDtRC_t cmDataStr( const cmData_t* p, cmChar_t** v );
  212. cmDtRC_t cmDataConstStr( const cmData_t* p, const cmChar_t** v );
  213. cmDtRC_t cmDataBlob( const cmData_t* p, cmChar_t** v, unsigned* byteCntRef );
  214. cmDtRC_t cmDataConstBlob( const cmData_t* p, const cmChar_t** v, unsigned* byteCntRef );
  215. // Get the value of an object with conversion.
  216. cmDtRC_t cmDataGetChar( const cmData_t* p, char* v );
  217. cmDtRC_t cmDataGetUChar( const cmData_t* p, unsigned char* v );
  218. cmDtRC_t cmDataGetShort( const cmData_t* p, short* v );
  219. cmDtRC_t cmDataGetUShort( const cmData_t* p, unsigned short* v );
  220. cmDtRC_t cmDataGetInt( const cmData_t* p, int* v );
  221. cmDtRC_t cmDataGetUInt( const cmData_t* p, unsigned int* v );
  222. cmDtRC_t cmDataGetLong( const cmData_t* p, long* v );
  223. cmDtRC_t cmDataGetULong( const cmData_t* p, unsigned long* v );
  224. cmDtRC_t cmDataGetFloat( const cmData_t* p, float* v );
  225. cmDtRC_t cmDataGetDouble( const cmData_t* p, double* v );
  226. //----------------------------------------------------------------------------
  227. // Array related functions
  228. //
  229. // Notes:
  230. // 1) string arrays are arrays of string pointers.
  231. // 2) blob arrays (array of void pointers) are not supported because
  232. // there is no direct way to determine the length of each blob
  233. // and therefore they cannot be internally duplicated - a special scheme
  234. // could be devised (length goes in first 4 bytes) to make this
  235. // work but we will defer that until the need arises.
  236. //
  237. // Dynamically allocate a new array data object.
  238. //
  239. // eleCnt referes to the number of elements in the array pointed
  240. // to by 'vp'. The number of bytes pointed to by 'vp' is then
  241. // cmDataByteWidth(tid)*eleCnt.
  242. //
  243. // If no flags are set then the array pointed to by 'vp' is reallocated
  244. // and kDataFreeDtFl is set.
  245. //
  246. // If kFreeValueDtFl is set then the object will take responsibility for
  247. // releasing the memory pointed to by 'vp' when the object is destroyed
  248. // or the array is reassigned.
  249. //
  250. // If kNoCopyDtFl is set then 'vp' becomes the internal array
  251. // value (vp[cnt]) is NOT reallocated). In this case the client is
  252. // responsibile for eventually releasing the associated memory - when
  253. // the data object is no longer valid.
  254. cmDtRC_t cmDataNewArray( cmData_t* parent, cmDataTypeId_t tid, void* vp, unsigned eleCnt, unsigned flags, cmData_t** ref );
  255. cmDtRC_t cmDataNewCharArray( cmData_t* parent, char* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  256. cmDtRC_t cmDataNewUCharArray( cmData_t* parent, unsigned char* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  257. cmDtRC_t cmDataNewShortArray( cmData_t* parent, short* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  258. cmDtRC_t cmDataNewUShortArray( cmData_t* parent, unsigned short* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  259. cmDtRC_t cmDataNewIntArray( cmData_t* parent, int* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  260. cmDtRC_t cmDataNewUIntArray( cmData_t* parent, unsigned int* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  261. cmDtRC_t cmDataNewLongArray( cmData_t* parent, long* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  262. cmDtRC_t cmDataNewULongArray( cmData_t* parent, unsigned long* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  263. cmDtRC_t cmDataNewFloatArray( cmData_t* parent, float* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  264. cmDtRC_t cmDataNewDoubleArray( cmData_t* parent, double* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  265. cmDtRC_t cmDataNewStrArray( cmData_t* parent, cmChar_t** v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  266. cmDtRC_t cmDataNewConstStrArray( cmData_t* parent, const cmChar_t** v,unsigned eleCnt, unsigned flags, cmData_t** ref );
  267. // Set the value and type of an existing scalar object.
  268. //
  269. // These functions begin by releasing any resources held by *p
  270. // prior to resetting the type and value of the object.
  271. // The 'flags' argument may include kConstValueDtFl, kConstObjDtFl,
  272. // kNoCopyDtFl and the kFreeValueDtFl.
  273. // Generic set array functions. 'vp' is assumed to point to an array
  274. // of the type defined by 'tid'.
  275. cmDtRC_t cmDataSetArrayValue( cmData_t* dt, cmDataTypeId_t tid, void* vp, unsigned eleCnt, unsigned flags );
  276. // Type sepctific set array functions.
  277. cmDtRC_t cmDataSetCharArray( cmData_t* d, char* v, unsigned eleCnt, unsigned flags );
  278. cmDtRC_t cmDataSetUCharArray( cmData_t* d, unsigned char* v, unsigned eleCnt, unsigned flags );
  279. cmDtRC_t cmDataSetShortArray( cmData_t* d, short* v, unsigned eleCnt, unsigned flags );
  280. cmDtRC_t cmDataSetUShortArray( cmData_t* d, unsigned short* v, unsigned eleCnt, unsigned flags );
  281. cmDtRC_t cmDataSetIntArray( cmData_t* d, int* v, unsigned eleCnt, unsigned flags );
  282. cmDtRC_t cmDataSetUIntArray( cmData_t* d, unsigned int* v, unsigned eleCnt, unsigned flags );
  283. cmDtRC_t cmDataSetLongArray( cmData_t* d, long* v, unsigned eleCnt, unsigned flags );
  284. cmDtRC_t cmDataSetULongArray( cmData_t* d, unsigned long* v, unsigned eleCnt, unsigned flags );
  285. cmDtRC_t cmDataSetFloatArray( cmData_t* d, float* v, unsigned eleCnt, unsigned flags );
  286. cmDtRC_t cmDataSetDoubleArray( cmData_t* d, double* v, unsigned eleCnt, unsigned flags );
  287. cmDtRC_t cmDataSetStrArray( cmData_t* d, cmChar_t** v, unsigned eleCnt, unsigned flags );
  288. cmDtRC_t cmDataSetConstStrArray(cmData_t* d,const cmChar_t** v,unsigned eleCnt, unsigned flags );
  289. // Return the count of elements in a n array.
  290. unsigned cmDataArrayEleCount( const cmData_t* d );
  291. // Get a pointer to the base of an array.
  292. // The type must match exactly or an error is generated.
  293. // Use cmDataEleCount() to determine the number of elements in the array.
  294. cmDtRC_t cmDataCharArray( const cmData_t* d, char** v );
  295. cmDtRC_t cmDataUCharArray( const cmData_t* d, unsigned char** v );
  296. cmDtRC_t cmDataShortArray( const cmData_t* d, short** v );
  297. cmDtRC_t cmDataUShortArray( const cmData_t* d, unsigned short** v );
  298. cmDtRC_t cmDataIntArray( const cmData_t* d, int** v );
  299. cmDtRC_t cmDataUIntArray( const cmData_t* d, unsigned int** v );
  300. cmDtRC_t cmDataLongArray( const cmData_t* d, long** v );
  301. cmDtRC_t cmDataULongArray( const cmData_t* d, unsigned long** v );
  302. cmDtRC_t cmDataFloatArray( const cmData_t* d, float** v );
  303. cmDtRC_t cmDataDoubleArray( const cmData_t* d, double** v );
  304. cmDtRC_t cmDataStrArray( const cmData_t* d, cmChar_t*** v );
  305. cmDtRC_t cmDataConstStrArray( const cmData_t* d, const cmChar_t*** v );
  306. //----------------------------------------------------------------------------
  307. // Structure related functions
  308. //
  309. // Release an object and any resources held by it.
  310. // Note the this function does not unlink the object
  311. // from it's parent. Use cmDataUnlinkAndFree()
  312. // to remove a object from it's parent list prior
  313. // to releasing it.
  314. void cmDataFree( cmData_t* p );
  315. // Unlink 'p' from its parents and siblings.
  316. // Asserts if parent is not a structure.
  317. // Returns 'p'.
  318. cmData_t* cmDataUnlink( cmData_t* p );
  319. // Wrapper function to cmDataUnlink() and cmDataFree().
  320. void cmDataUnlinkAndFree( cmData_t* p );
  321. // Replace the 'dst' node with the 'src' node and
  322. // return 'src'. This operation does not duplicate
  323. // 'src' it simply links in 'src' at the location of
  324. // 'dst' and then unlinks and free's 'dst'.
  325. cmData_t* cmDataReplace( cmData_t* dst, cmData_t* src );
  326. // Return the count of child nodes.
  327. // 1. Array nodes have one child per array element.
  328. // 2. List nodes have one child pair.
  329. // 3. Pair nodes have two children.
  330. // 4. Leaf nodes have 0 children.
  331. unsigned cmDataChildCount( const cmData_t* p );
  332. // Returns the ith child of 'p'.
  333. // Returns NULL if p has no children or index is invalid.
  334. cmData_t* cmDataChild( cmData_t* p, unsigned index );
  335. // Prepend 'p' to 'parents' child list.
  336. // The source node 'p' is not duplicated it is simply linked in.
  337. // 'p' is automatically unlinked prior to being prepended.
  338. // Returns 'p'.
  339. cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p );
  340. // Append 'p' to the end of 'parent' child list.
  341. // The source node 'p' is not duplicated it is simply linked in.
  342. // 'p' is automatically unlinked prior to being appended.
  343. // Returns 'p'.
  344. cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p );
  345. // Insert 'p' at index. Index must be in the range:
  346. // 0 to cmDataChildCount(parent).
  347. // The source node 'p' is not duplicated it is simply linked in.
  348. // 'p' is automatically unlinked prior to being inserted.
  349. // Returns 'p'.
  350. cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p );
  351. ////////////////////////////////////////////////////////////////////////////////////////////////
  352. ////////////////////////////////////////////////////////////////////////////////////////////////
  353. ////////////////////////////////////////////////////////////////////////////////////////////////
  354. ////////////////////////////////////////////////////////////////////////////////////////////////
  355. #ifdef NOT_DEF
  356. typedef enum
  357. {
  358. kInvalidDtId,
  359. kMinValDtId,
  360. kNullDtId = kMinValDtId,
  361. kUCharDtId,
  362. kCharDtId,
  363. kUShortDtId,
  364. kShortDtId,
  365. kUIntDtId,
  366. kIntDtId,
  367. kULongDtId,
  368. kLongDtId,
  369. kFloatDtId,
  370. kDoubleDtId,
  371. kStrDtId,
  372. kConstStrDtId,
  373. kMaxValDtId = kConstStrDtId,
  374. kMinPtrDtId,
  375. kUCharPtrDtId = kMinPtrDtId, // cnt=array element count
  376. kCharPtrDtId,
  377. kUShortPtrDtId,
  378. kShortPtrDtId,
  379. kUIntPtrDtId,
  380. kIntPtrDtId,
  381. kULongPtrDtId,
  382. kLongPtrDtId,
  383. kFloatPtrDtId,
  384. kDoublePtrDtId,
  385. kVoidPtrDtId,
  386. kMaxPtrDtId = kVoidPtrDtId,
  387. kMinStructDtId,
  388. kListDtId = kMinStructDtId, // children nodes are array elements, cnt=child count
  389. kPairDtId, // key/value pairs, cnt=2, first child is key, second is value
  390. kRecordDtId, // children nodes are pairs, cnt=pair count
  391. kMaxStructDtId,
  392. kOptArgDtFl = 0x80000000
  393. } cmDataFmtId_t;
  394. enum
  395. {
  396. kDynObjDtFl = 0x01, // object was dynamically allocated
  397. kDynPtrDtFl = 0x02 // ptr array was dynamically allocated
  398. };
  399. typedef struct cmData_str
  400. {
  401. cmDataFmtId_t tid; // data format id
  402. unsigned flags; //
  403. struct cmData_str* parent; // this childs parent
  404. struct cmData_str* sibling; // this childs left sibling
  405. unsigned cnt; // array ele count
  406. union
  407. {
  408. char c;
  409. unsigned char uc;
  410. short s;
  411. unsigned short us;
  412. int i;
  413. unsigned int ui;
  414. long l;
  415. unsigned long ul;
  416. float f;
  417. double d;
  418. cmChar_t* z;
  419. const cmChar_t* cz;
  420. void* vp;
  421. char* cp;
  422. unsigned char* ucp;
  423. short* sp;
  424. unsigned short* usp;
  425. int* ip;
  426. unsigned int* uip;
  427. long* lp;
  428. unsigned long* ulp;
  429. float* fp;
  430. double* dp;
  431. struct cmData_str* child; // first child (array,record,pair)
  432. } u;
  433. } cmData_t;
  434. typedef unsigned cmDtRC_t;
  435. extern cmData_t cmDataNull;
  436. bool cmDataIsValue( const cmData_t* p );
  437. bool cmDataIsPtr( const cmData_t* p );
  438. bool cmDataIsStruct( const cmData_t* p ); // is a pair,list or record
  439. bool canConvertType( cmDataFmtId_t srcId, cmDataFmtId_t dstId );
  440. bool willTruncate( cmDataFmtId_t srcId, cmDataFmtId_t dstId );
  441. bool canConvertObj( const cmData_t* srcObj, cmData_t* dstObj );
  442. bool willTruncateObj(const cmData_t* srcObj, cmData_t* dstObj );
  443. // Get the value of an object without conversion.
  444. // The data type id must match the return type or the
  445. // conversion must be an automatic C conversion.
  446. char cmDataChar( const cmData_t* p );
  447. unsigned char cmDataUChar( const cmData_t* p );
  448. short cmDataShort( const cmData_t* p );
  449. unsigned short cmDataUShort( const cmData_t* p );
  450. int cmDataInt( const cmData_t* p );
  451. unsigned int cmDataUInt( const cmData_t* p );
  452. long cmDataLong( const cmData_t* p );
  453. unsigned long cmDataULong( const cmData_t* p );
  454. float cmDataFloat( const cmData_t* p );
  455. double cmDataDouble( const cmData_t* p );
  456. cmChar_t* cmDataStr( const cmData_t* p );
  457. const cmChar_t* cmDataConstStr( const cmData_t* p );
  458. void* cmDataVoidPtr( const cmData_t* p );
  459. char* cmDataCharPtr( const cmData_t* p );
  460. unsigned char* cmDataUCharPtr( const cmData_t* p );
  461. short* cmDataShortPtr( const cmData_t* p );
  462. unsigned short* cmDataUShortPtr( const cmData_t* p );
  463. int* cmDataIntPtr( const cmData_t* p );
  464. unsigned int* cmDataUIntPtr( const cmData_t* p );
  465. long* cmDataLongPtr( const cmData_t* p );
  466. unsigned long* cmDataULongPtr( const cmData_t* p );
  467. float* cmDataFloatPtr( const cmData_t* p );
  468. double* cmDataDoublePtr( const cmData_t* p );
  469. // Get the value of an object with conversion.
  470. cmDtRC_t cmDataGetChar( const cmData_t* p, char* v );
  471. cmDtRC_t cmDataGetUChar( const cmData_t* p, unsigned char* v );
  472. cmDtRC_t cmDataGetShort( const cmData_t* p, short* v );
  473. cmDtRC_t cmDataGetUShort( const cmData_t* p, unsigned short* v );
  474. cmDtRC_t cmDataGetInt( const cmData_t* p, int* v );
  475. cmDtRC_t cmDataGetUInt( const cmData_t* p, unsigned int* v );
  476. cmDtRC_t cmDataGetLong( const cmData_t* p, long* v );
  477. cmDtRC_t cmDataGetULong( const cmData_t* p, unsigned long* v );
  478. cmDtRC_t cmDataGetFloat( const cmData_t* p, float* v );
  479. cmDtRC_t cmDataGetDouble( const cmData_t* p, double* v );
  480. // Returns the pointer - does not copy the data.
  481. cmDtRC_t cmDataGetStr( const cmData_t* p, char** v );
  482. cmDtRC_t cmDataGetConstStr( const cmData_t* p, const char** v );
  483. cmDtRC_t cmDataGetVoidPtr( const cmData_t* p, void** v );
  484. cmDtRC_t cmDataGetCharPtr( const cmData_t* p, char** v );
  485. cmDtRC_t cmDataGetUCharPtr( const cmData_t* p, unsigned char** v );
  486. cmDtRC_t cmDataGetShortPtr( const cmData_t* p, short** v );
  487. cmDtRC_t cmDataGetUShortPtr( const cmData_t* p, unsigned short** v );
  488. cmDtRC_t cmDataGetIntPtr( const cmData_t* p, int** v );
  489. cmDtRC_t cmDataGetUIntPtr( const cmData_t* p, unsigned int** v );
  490. cmDtRC_t cmDataGetLongPtr( const cmData_t* p, long** v );
  491. cmDtRC_t cmDataGetULongPtr( const cmData_t* p, unsigned long** v );
  492. cmDtRC_t cmDataGetFloatPtr( const cmData_t* p, float** v );
  493. cmDtRC_t cmDataGetDoublePtr( const cmData_t* p, double** v );
  494. // Set the value and type of an existing scalar object.
  495. // These functions begin by releasing any resources held by *p
  496. // prior to resetting the type and value of the object.
  497. cmData_t* cmDataSetNull( cmData_t* p );
  498. cmData_t* cmDataSetChar( cmData_t* p, char v );
  499. cmData_t* cmDataSetUChar( cmData_t* p, unsigned char v );
  500. cmData_t* cmDataSetShort( cmData_t* p, short v );
  501. cmData_t* cmDataSetUShort( cmData_t* p, unsigned short v );
  502. cmData_t* cmDataSetInt( cmData_t* p, int v );
  503. cmData_t* cmDataSetUInt( cmData_t* p, unsigned int v );
  504. cmData_t* cmDataSetLong( cmData_t* p, long v );
  505. cmData_t* cmDataSetULong( cmData_t* p, unsigned long v );
  506. cmData_t* cmDataSetFloat( cmData_t* p, float v );
  507. cmData_t* cmDataSetDouble( cmData_t* p, double v );
  508. cmData_t* cmDataSetStr( cmData_t* p, cmChar_t* s );
  509. cmData_t* cmDataSetConstStr( cmData_t* p, const cmChar_t* s );
  510. // Set the type and value of an existing data object to an external array.
  511. // These functions begin by releasing any resources help by *p.
  512. // The array pointed to by 'vp' is not copied or duplicated.
  513. // 'vp' is simply assigned as the data space for the object and therefore must remain
  514. // valid for the life of the object.
  515. cmData_t* cmDataSetVoidPtr( cmData_t* p, void* vp, unsigned cnt );
  516. cmData_t* cmDataSetCharPtr( cmData_t* p, char* vp, unsigned cnt );
  517. cmData_t* cmDataSetUCharPtr( cmData_t* p, unsigned char* vp, unsigned cnt );
  518. cmData_t* cmDataSetShortPtr( cmData_t* p, short* vp, unsigned cnt );
  519. cmData_t* cmDataSetUShortPtr( cmData_t* p, unsigned short* vp, unsigned cnt );
  520. cmData_t* cmDataSetIntPtr( cmData_t* p, int* vp, unsigned cnt );
  521. cmData_t* cmDataSetUIntPtr( cmData_t* p, unsigned int* vp, unsigned cnt );
  522. cmData_t* cmDataSetLongPtr( cmData_t* p, long* vp, unsigned cnt );
  523. cmData_t* cmDataSetULongPtr( cmData_t* p, unsigned long* vp, unsigned cnt );
  524. cmData_t* cmDataSetFloatPtr( cmData_t* p, float* vp, unsigned cnt );
  525. cmData_t* cmDataSetDoublePtr( cmData_t* p, double* vp, unsigned cnt );
  526. // Set the value of an existing array based data object.
  527. // These functions begin by releasing any resources help by *p
  528. // and then dynamically allocate the internal array and copy
  529. // the array data into it.
  530. cmData_t* cmDataSetStrAllocN( cmData_t* p, const cmChar_t* s, unsigned charCnt );
  531. cmData_t* cmDataSetStrAlloc( cmData_t* p, const cmChar_t* s );
  532. cmData_t* cmDataSetConstStrAllocN( cmData_t* p, const cmChar_t* s, unsigned charCnt );
  533. cmData_t* cmDataSetConstStrAlloc( cmData_t* p, const cmChar_t* s );
  534. cmData_t* cmDataSetVoidAllocPtr( cmData_t* p, const void* vp, unsigned cnt );
  535. cmData_t* cmDataSetCharAllocPtr( cmData_t* p, const char* vp, unsigned cnt );
  536. cmData_t* cmDataSetUCharAllocPtr( cmData_t* p, const unsigned char* vp, unsigned cnt );
  537. cmData_t* cmDataSetShortAllocPtr( cmData_t* p, const short* vp, unsigned cnt );
  538. cmData_t* cmDataSetUShortAllocPtr( cmData_t* p, const unsigned short* vp, unsigned cnt );
  539. cmData_t* cmDataSetIntAllocPtr( cmData_t* p, const int* vp, unsigned cnt );
  540. cmData_t* cmDataSetUIntAllocPtr( cmData_t* p, const unsigned int* vp, unsigned cnt );
  541. cmData_t* cmDataSetLongAllocPtr( cmData_t* p, const long* vp, unsigned cnt );
  542. cmData_t* cmDataSetULongAllocPtr( cmData_t* p, const unsigned long* vp, unsigned cnt );
  543. cmData_t* cmDataSetFloatAllocPtr( cmData_t* p, const float* vp, unsigned cnt );
  544. cmData_t* cmDataSetDoubleAllocPtr( cmData_t* p, const double* vp, unsigned cnt );
  545. // Dynamically allocate a data object and set it's value.
  546. cmData_t* cmDataAllocNull( cmData_t* parent );
  547. cmData_t* cmDataAllocChar( cmData_t* parent, char v );
  548. cmData_t* cmDataAllocUChar( cmData_t* parent, unsigned char v );
  549. cmData_t* cmDataAllocShort( cmData_t* parent, short v );
  550. cmData_t* cmDataAllocUShort( cmData_t* parent, unsigned short v );
  551. cmData_t* cmDataAllocInt( cmData_t* parent, int v );
  552. cmData_t* cmDataAllocUInt( cmData_t* parent, unsigned int v );
  553. cmData_t* cmDataAllocLong( cmData_t* parent, long v );
  554. cmData_t* cmDataAllocULong( cmData_t* parent, unsigned long v );
  555. cmData_t* cmDataAllocFloat( cmData_t* parent, float v );
  556. cmData_t* cmDataAllocDouble( cmData_t* parent, double v );
  557. // Dynamically allocate a data object and set its array value to an external
  558. // array. v[cnt] is assigned as the internal data space for the object and
  559. // therefore must remain valid for the life of the object.
  560. // See the cmDataXXXAlocPtr() for equivalent functions which dynamically
  561. // allocate the intenal data space.
  562. cmData_t* cmDataAllocStr( cmData_t* parent, cmChar_t* str );
  563. cmData_t* cmDataAllocConstStr( cmData_t* parent, const cmChar_t* str );
  564. cmData_t* cmDataAllocCharPtr( cmData_t* parent, char* v, unsigned cnt );
  565. cmData_t* cmDataAllocUCharPtr( cmData_t* parent, unsigned char* v, unsigned cnt );
  566. cmData_t* cmDataAllocShortPtr( cmData_t* parent, short* v, unsigned cnt );
  567. cmData_t* cmDataAllocUShortPtr( cmData_t* parent, unsigned short* v, unsigned cnt );
  568. cmData_t* cmDataAllocIntPtr( cmData_t* parent, int* v, unsigned cnt );
  569. cmData_t* cmDataAllocUIntPtr( cmData_t* parent, unsigned int* v, unsigned cnt );
  570. cmData_t* cmDataAllocLongPtr( cmData_t* parent, long* v, unsigned cnt );
  571. cmData_t* cmDataAllocULongPtr( cmData_t* parent, unsigned long* v, unsigned cnt );
  572. cmData_t* cmDataAllocFloatPtr( cmData_t* parent, float* v, unsigned cnt );
  573. cmData_t* cmDataAllocDoublePtr( cmData_t* parent, double* v, unsigned cnt );
  574. cmData_t* cmDataAllocVoidPtr( cmData_t* parent, void* v, unsigned cnt );
  575. // Dynamically allocate a data object and its array value.
  576. // These functions dynamically allocate the internal array data space
  577. // and copy v[cnt] into it.
  578. cmData_t* cmDataStrAlloc( cmData_t* parent, cmChar_t* str );
  579. cmData_t* cmDataConstStrAlloc( cmData_t* parent, const cmChar_t* str );
  580. cmData_t* cmDataConstStrAllocN( cmData_t* parent, const cmChar_t* str, unsigned charCnt );
  581. cmData_t* cmDataCharAllocPtr( cmData_t* parent, const char* v, unsigned cnt );
  582. cmData_t* cmDataUCharAllocPtr( cmData_t* parent, const unsigned char* v, unsigned cnt );
  583. cmData_t* cmDataShortAllocPtr( cmData_t* parent, const short* v, unsigned cnt );
  584. cmData_t* cmDataUShortAllocPtr( cmData_t* parent, const unsigned short* v, unsigned cnt );
  585. cmData_t* cmDataIntAllocPtr( cmData_t* parent, const int* v, unsigned cnt );
  586. cmData_t* cmDataUIntAllocPtr( cmData_t* parent, const unsigned int* v, unsigned cnt );
  587. cmData_t* cmDataLongAllocPtr( cmData_t* parent, const long* v, unsigned cnt );
  588. cmData_t* cmDataULongAllocPtr( cmData_t* parent, const unsigned long* v, unsigned cnt );
  589. cmData_t* cmDataFloatAllocPtr( cmData_t* parent, const float* v, unsigned cnt );
  590. cmData_t* cmDataDoubleAllocPtr( cmData_t* parent, const double* v, unsigned cnt );
  591. cmData_t* cmDataVoidAllocPtr( cmData_t* parent, const void* v, unsigned cnt );
  592. //----------------------------------------------------------------------------
  593. // Structure related functions
  594. //
  595. // Release an object and any resources held by it.
  596. // Note the this function does not unlink the object
  597. // from it's parent. Use cmDataUnlinkAndFree()
  598. // to remove a object from it's parent list prior
  599. // to releasing it.
  600. void cmDataFree( cmData_t* p );
  601. // Unlink 'p' from its parents and siblings.
  602. // Asserts if parent is not a structure.
  603. // Returns 'p'.
  604. cmData_t* cmDataUnlink( cmData_t* p );
  605. // Wrapper function to cmDataUnlink() and cmDataFree().
  606. void cmDataUnlinkAndFree( cmData_t* p );
  607. // Replace the 'dst' node with the 'src' node and
  608. // return 'src'. This operation does not duplicate
  609. // 'src' it simply links in 'src' at the location of
  610. // 'dst' and then unlinks and free's 'dst'.
  611. cmData_t* cmDataReplace( cmData_t* dst, cmData_t* src );
  612. // Return the count of child nodes.
  613. // 1. Array nodes have one child per array element.
  614. // 2. List nodes have one child pair.
  615. // 3. Pair nodes have two children.
  616. // 4. Leaf nodes have 0 children.
  617. unsigned cmDataChildCount( const cmData_t* p );
  618. // Returns the ith child of 'p'.
  619. // Returns NULL if p has no children or index is invalid.
  620. cmData_t* cmDataChild( cmData_t* p, unsigned index );
  621. // Prepend 'p' to 'parents' child list.
  622. // The source node 'p' is not duplicated it is simply linked in.
  623. // 'p' is automatically unlinked prior to being prepended.
  624. // Returns 'p'.
  625. cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p );
  626. // Append 'p' to the end of 'parent' child list.
  627. // The source node 'p' is not duplicated it is simply linked in.
  628. // 'p' is automatically unlinked prior to being appended.
  629. // Returns 'p'.
  630. cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p );
  631. // Insert 'p' at index. Index must be in the range:
  632. // 0 to cmDataChildCount(parent).
  633. // The source node 'p' is not duplicated it is simply linked in.
  634. // 'p' is automatically unlinked prior to being inserted.
  635. // Returns 'p'.
  636. cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p );
  637. //----------------------------------------------------------------------------
  638. // Pair related functions
  639. //
  640. // Get the key/value of a pair
  641. cmData_t* cmDataPairKey( cmData_t* p );
  642. unsigned cmDataPairKeyId( cmData_t* p );
  643. const cmChar_t* cmDataPairKeyLabel( cmData_t* p );
  644. cmData_t* cmDataPairValue( cmData_t* p );
  645. // Set the value of an existing pair node.
  646. // 'value' is not duplicated it is simply linked in place of the
  647. // previous pair value node. The previous pair value node is
  648. // unlinked and freed.
  649. // Returns 'p'.
  650. cmData_t* cmDataPairSetValue( cmData_t* p, cmData_t* value );
  651. // Set the key of an existing pair node.
  652. // The previous key is unlinked and freed.
  653. cmData_t* cmDataPairSetKey( cmData_t* p, cmData_t* key );
  654. cmData_t* cmDataPairSetKeyId( cmData_t* p, unsigned id );
  655. // The data space for the 'label' string is dynamically allocated.
  656. cmData_t* cmDataPairSetKeyLabel( cmData_t* p, const cmChar_t* label );
  657. // Create a pair value by assigning a key and value to 'p'.
  658. // 'p' is unlinked and freed prior to the key value assignment.
  659. // 'key' and 'value' are simply linked in they are not duplicated or reallocated.
  660. cmData_t* cmDataMakePair( cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t* value );
  661. // Dynamically allocate a pair node. Both the key and value nodes are reallocated.
  662. cmData_t* cmDataAllocPair( cmData_t* parent, const cmData_t* key, const cmData_t* value );
  663. // Dynamically allocate the id but link (w/o realloc) the value.
  664. cmData_t* cmDataAllocPairId( cmData_t* parent, unsigned keyId, cmData_t* value );
  665. // Dynamically allocate the label but link (w/o realloc) the value.
  666. cmData_t* cmDataAllocPairLabelN(cmData_t* parent, const cmChar_t* label, unsigned charCnt, cmData_t* value);
  667. cmData_t* cmDataAllocPairLabel( cmData_t* parent, const cmChar_t* label, cmData_t* value );
  668. //----------------------------------------------------------------------------
  669. // List related functions
  670. //
  671. // Return the count of ele's in the list.
  672. unsigned cmDataListCount( const cmData_t* p );
  673. // Return the ith element in the list.
  674. cmData_t* cmDataListEle( cmData_t* p, unsigned index );
  675. cmData_t* cmDataListMake( cmData_t* parent, cmData_t* p );
  676. cmData_t* cmDataListAlloc( cmData_t* parent);
  677. // Var-args fmt:
  678. // <typeId> <value> {<cnt>}
  679. // scalar types: <value> is literal,<cnt> is not included
  680. // null has no <value> or <cnt>
  681. // ptr types: <value> is pointer,<cnt> is element count
  682. // struct types: <value> is cmData_t, <cnt> is not included
  683. // Indicate the end of argument list by setting <typeId> to kInvalidDtId.
  684. // The memory for array based data types is dynamically allocated.
  685. cmData_t* cmDataListAllocV(cmData_t* parent, va_list vl );
  686. cmData_t* cmDataListAllocA(cmData_t* parent, ... );
  687. // Returns a ptr to 'ele'.
  688. cmData_t* cmDataListAppendEle( cmData_t* p, cmData_t* ele );
  689. cmDtRC_t cmDataListAppendV( cmData_t* p, va_list vl );
  690. cmDtRC_t cmDataListAppend( cmData_t* p, ... );
  691. // Return 'p'.
  692. cmData_t* cmDataListInsertEle( cmData_t* p, unsigned index, cmData_t* ele );
  693. cmData_t* cmDataListInsertEleN(cmData_t* p, unsigned index, cmData_t* ele[], unsigned n );
  694. cmData_t* cmDataListUnlink( cmData_t* p, unsigned index );
  695. cmData_t* cmDataListFree( cmData_t* p, unsigned index );
  696. //----------------------------------------------------------------------------
  697. // Record related functions
  698. //
  699. // Return count of pairs.
  700. unsigned cmDataRecdCount( const cmData_t* p );
  701. // Return the ith pair.
  702. cmData_t* cmDataRecdEle( cmData_t* p, unsigned index );
  703. // Return the ith value.
  704. cmData_t* cmDataRecdValueFromIndex( cmData_t* p, unsigned index );
  705. cmData_t* cmDataRecdValueFromId( cmData_t* p, unsigned id );
  706. cmData_t* cmDataRecdValueFromLabel( cmData_t* p, const cmChar_t* label );
  707. // Return the ith key
  708. cmData_t* cmDataRecdKey( cmData_t* p, unsigned index );
  709. unsigned cmDataRecdKeyId( cmData_t* p, unsigned index );
  710. const cmChar_t* cmDataRecdKeyLabel( cmData_t* p, unsigned index );
  711. cmData_t* cmDataRecdMake( cmData_t* parent, cmData_t* p );
  712. cmData_t* cmDataRecdAlloc( cmData_t* parent );
  713. // Append a pair node by linking the pair node 'pair' to the record node 'p'.
  714. // 'pair' is simply linked to 'p' via cmDataAppendChild() no
  715. // reallocation or duplicattion takes place.
  716. cmData_t* cmDataRecdAppendPair( cmData_t* p, cmData_t* pair );
  717. // Var-args format:
  718. // <label|id> <typeId> <value> {<cnt>}
  719. // scalar types: <value> is literal,<cnt> is not included
  720. // null type: has no <value> or <cnt>
  721. // ptr types: <value> is pointer, <cnt> is element count
  722. // struct types: <value> is cmData_t, <cnt> is not included
  723. // Indicate the end of argument list by setting <typeId> to kInvalidDtId.
  724. // The memory for array based data types is dynamically allocated.
  725. cmData_t* cmDataRecdAllocLabelV( cmData_t* parent, va_list vl );
  726. cmData_t* cmDataRecdAllocLabelA( cmData_t* parent, ... );
  727. cmData_t* cmDataRecdAllocIdV( cmData_t* parent, va_list vl );
  728. cmData_t* cmDataRecdAllocIdA( cmData_t* parent, ... );
  729. // Extract the data in a record to C variables.
  730. // The var-args list must be NULL terminated.
  731. // The <'id' | 'label'> identify a pair.
  732. // The <typeId> indicates the C type of 'pointer'.
  733. // The actual field type must be convertable into this pointer type or the
  734. // function will fail.
  735. // 'err' is an application supplied error object to be used if a required
  736. // field is missing. 'errRC' is the client result code to be passed with
  737. // the error report. See cmErrMsg(). Both 'err' and 'errRC' are optional.
  738. // Set kOptArgDtFl on 'typeId' to indicate that a field is optional.
  739. // <label|id> (<typeId> | kOptArgDtFl) <pointer>
  740. cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl );
  741. cmDtRC_t cmDataRecdParseLabel( cmData_t* p, cmErr_t* err, unsigned errRC, ... );
  742. cmDtRC_t cmDataRecdParseIdV( cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl );
  743. cmDtRC_t cmDataRecdParseId( cmData_t* p, cmErr_t* err, unsigned errRC, ... );
  744. unsigned cmDataSerializeByteCount( const cmData_t* p );
  745. cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt );
  746. cmDtRC_t cmDataDeserialize( const void* buf, unsigned bufByteCnt, cmData_t** pp );
  747. //-----------------------------------------------------------------------------
  748. typedef cmHandle_t cmDataParserH_t;
  749. //static cmDataParserH_t cmDataParserNullHandle;
  750. cmDtRC_t cmDataParserCreate( cmCtx_t* ctx, cmDataParserH_t* hp );
  751. cmDtRC_t cmDataParserDestroy( cmDataParserH_t* hp );
  752. bool cmDataParserIsValid( cmDataParserH_t h );
  753. // Parse a text representation into a 'record' type.
  754. // Note that the text is wrapped with implied curly braces
  755. // (e.g. "{ text }"). The contents of the text should therefore
  756. // fit the record syntax (e.g. the first token should be a
  757. // 'pair' label.
  758. cmDtRC_t cmDataParserExec( cmDataParserH_t h, const cmChar_t* text, cmData_t** pp );
  759. //-----------------------------------------------------------------------------
  760. void cmDataPrint( const cmData_t* p, cmRpt_t* rpt );
  761. void cmDataTest( cmCtx_t* ctx );
  762. #endif
  763. #ifdef __cplusplus
  764. }
  765. #endif
  766. #endif