libcm is a C development framework with an emphasis on audio signal processing applications.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

cmData.h 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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. kStructDtId // 14 node is a pair,list, or recd
  65. } cmDataTypeId_t;
  66. typedef enum
  67. {
  68. kInvalidCntDtId, // 0
  69. kScalarDtId, // 1
  70. kArrayDtId, // 2
  71. kPairDtId, // 3
  72. kListDtId, // 4
  73. kRecordDtId // 5
  74. } cmDataContainerId_t;
  75. enum
  76. {
  77. kNoFlagsDtFl = 0x00,
  78. // Indicate that the memory used by the data object
  79. // was dynamically allocated and should be released
  80. // by cmDataFree().
  81. kFreeObjDtFl = 0x01,
  82. // Indicate that the memory used by strings, blobs
  83. // and arrays should be freed by cmDataFree().
  84. kFreeValueDtFl = 0x02,
  85. // Indicate that the value of the object cannot be changed.
  86. // (but the object could be reassigned as a new type).
  87. kConstValueDtFl = 0x04,
  88. // Indicate that the type of the object cannot be changed.
  89. // (but the value may be changed).
  90. kConstObjDtFl = 0x08,
  91. // Indicate that the array or string should not be
  92. // internally reallocated but rather the source pointer
  93. // should be taken as the new value of the object.
  94. kNoCopyDtFl = 0x10,
  95. };
  96. typedef struct cmData_str
  97. {
  98. cmDataTypeId_t tid; // data format id
  99. cmDataContainerId_t cid; // container id
  100. unsigned flags; //
  101. struct cmData_str* parent; // this childs parent
  102. struct cmData_str* sibling; // this childs left sibling
  103. unsigned cnt; // byte cnt for strings/blobs and ele count for arrays
  104. union
  105. {
  106. char c;
  107. unsigned char uc;
  108. short s;
  109. unsigned short us;
  110. int i;
  111. unsigned int ui;
  112. long l;
  113. unsigned long ul;
  114. float f;
  115. double d;
  116. cmChar_t* z;
  117. void* vp;
  118. char* cp;
  119. unsigned char* ucp;
  120. short* sp;
  121. unsigned short* usp;
  122. int* ip;
  123. unsigned int* uip;
  124. long* lp;
  125. unsigned long* ulp;
  126. float* fp;
  127. double* dp;
  128. struct cmData_str* child; // first child (list,record,pair)
  129. } u;
  130. } cmData_t;
  131. extern cmData_t cmDataNull;
  132. const cmChar_t* cmDataTypeToLabel( cmDataTypeId_t tid );
  133. cmDataTypeId_t cmDataLabelToType( const cmChar_t* typeLabelStr );
  134. // Returns 1 for kStrDtId.
  135. // Returns cmInvalidCnt if tid is not recognized.
  136. unsigned dmDataByteWidth( cmDataTypeId_t tid );
  137. const cmChar_t* cmDataContainerIdToLabel( cmDataContainerId_t tid );
  138. cmDataContainerId_t cmDataLabelToContainerId( const cmChar_t* contLabelStr );
  139. bool cmDataIsConstObj( const cmData_t* d );
  140. void cmDataEnableConstObj( cmData_t* d, bool enaFl );
  141. bool cmDataIsConstValue( const cmData_t* d );
  142. void cmDataEnableConstValue( cmData_t* d, bool enaFl );
  143. bool cmDataIsFreeValue( const cmData_t* d );
  144. void cmDataEnableFreeValue( cmData_t* d, bool enaFl );
  145. // Returns true if this is a scalar or array node.
  146. bool cmDataIsLeaf( const cmData_t* d);
  147. // Return true if this is NOT a scalar or array node.
  148. bool cmDataIsStruct( const cmData_t* d );
  149. //----------------------------------------------------------------------------
  150. // Scalar related functions
  151. //
  152. // Dynamically allocate a scalar object and set it's value.
  153. // The 'flags' argument may include kConstValueDtFl and kConstObjDtFl.
  154. // The string and blob constructors may also use the
  155. // kNoCopyDtFl and the kFreeValueDtFl.
  156. // Generic:
  157. // 'byteCnt' is ignored for all types other than strings and blobs.
  158. cmDtRC_t cmDataNewScalar( cmData_t* parent, cmDataTypeId_t tid, unsigned flags, void* vp, unsigned byteCnt, cmData_t** ref );
  159. // Type specific
  160. cmDtRC_t cmDataNewNull( cmData_t* parent, unsigned flags, cmData_t** ref );
  161. cmDtRC_t cmDataNewChar( cmData_t* parent, unsigned flags, char v, cmData_t** ref );
  162. cmDtRC_t cmDataNewUChar( cmData_t* parent, unsigned flags, unsigned char v, cmData_t** ref );
  163. cmDtRC_t cmDataNewShort( cmData_t* parent, unsigned flags, short v, cmData_t** ref );
  164. cmDtRC_t cmDataNewUShort( cmData_t* parent, unsigned flags, unsigned short v, cmData_t** ref );
  165. cmDtRC_t cmDataNewInt( cmData_t* parent, unsigned flags, int v, cmData_t** ref );
  166. cmDtRC_t cmDataNewUInt( cmData_t* parent, unsigned flags, unsigned int v, cmData_t** ref );
  167. cmDtRC_t cmDataNewLong( cmData_t* parent, unsigned flags, long v, cmData_t** ref );
  168. cmDtRC_t cmDataNewULong( cmData_t* parent, unsigned flags, unsigned long v, cmData_t** ref );
  169. cmDtRC_t cmDataNewFloat( cmData_t* parent, unsigned flags, float v, cmData_t** ref );
  170. cmDtRC_t cmDataNewDouble( cmData_t* parent, unsigned flags, double v, cmData_t** ref );
  171. cmDtRC_t cmDataNewStr( cmData_t* parent, unsigned flags, cmChar_t* str, cmData_t** ref );
  172. cmDtRC_t cmDataNewConstStr( cmData_t* parent, unsigned flags, const cmChar_t* str, cmData_t** ref );
  173. cmDtRC_t cmDataNewStrN( cmData_t* parent, unsigned flags, cmChar_t* str, unsigned charCnt, cmData_t** ref );
  174. cmDtRC_t cmDataNewConstStrN(cmData_t* parent, unsigned flags, const cmChar_t* str, unsigned charCnt, cmData_t** ref );
  175. cmDtRC_t cmDataNewBlob( cmData_t* parent, unsigned flags, void* vp, unsigned byteCnt, cmData_t** ref );
  176. cmDtRC_t cmDataNewConstBlob(cmData_t* parent, unsigned flags, const void* vp, unsigned byteCnt, cmData_t** ref );
  177. // Set the value and type of an existing scalar object.
  178. // These functions begin by releasing any resources held by *p
  179. // prior to resetting the type and value of the object.
  180. // The 'flags' argument to cmDataSetStr() and cmDataSetConstStr()
  181. // may use the kNoCopyDtFl and the kFreeValueDtFl
  182. cmDtRC_t cmDataSetScalarValue( cmData_t* d, cmDataTypeId_t tid, void* vp, unsigned byteCnt, unsigned flags );
  183. cmDtRC_t cmDataSetNull( cmData_t* p );
  184. cmDtRC_t cmDataSetChar( cmData_t* p, char v );
  185. cmDtRC_t cmDataSetUChar( cmData_t* p, unsigned char v );
  186. cmDtRC_t cmDataSetShort( cmData_t* p, short v );
  187. cmDtRC_t cmDataSetUShort( cmData_t* p, unsigned short v );
  188. cmDtRC_t cmDataSetInt( cmData_t* p, int v );
  189. cmDtRC_t cmDataSetUInt( cmData_t* p, unsigned int v );
  190. cmDtRC_t cmDataSetLong( cmData_t* p, long v );
  191. cmDtRC_t cmDataSetULong( cmData_t* p, unsigned long v );
  192. cmDtRC_t cmDataSetFloat( cmData_t* p, float v );
  193. cmDtRC_t cmDataSetDouble( cmData_t* p, double v );
  194. cmDtRC_t cmDataSetStr( cmData_t* p, unsigned flags, cmChar_t* s );
  195. cmDtRC_t cmDataSetConstStr( cmData_t* p, unsigned flags, const cmChar_t* s );
  196. cmDtRC_t cmDataSetStrN( cmData_t* p, unsigned flags, cmChar_t* s, unsigned charCnt );
  197. cmDtRC_t cmDataSetConstStrN( cmData_t* p, unsigned flags, const cmChar_t* s, unsigned charCnt );
  198. cmDtRC_t cmDataSetBlob( cmData_t* p, unsigned flags, void* v, unsigned byteCnt );
  199. cmDtRC_t cmDataSetConstBlob( cmData_t* p, unsigned flags, const void* v, unsigned byteCnt );
  200. // Get the value of an object. No conversion is applied the
  201. // type must match exactly or an error is generated.
  202. cmDtRC_t cmDataChar( const cmData_t* p, char* v );
  203. cmDtRC_t cmDataUChar( const cmData_t* p, unsigned char* v );
  204. cmDtRC_t cmDataShort( const cmData_t* p, short* v );
  205. cmDtRC_t cmDataUShort( const cmData_t* p, unsigned short* v );
  206. cmDtRC_t cmDataInt( const cmData_t* p, int* v );
  207. cmDtRC_t cmDataUInt( const cmData_t* p, unsigned int* v );
  208. cmDtRC_t cmDataLong( const cmData_t* p, long* v );
  209. cmDtRC_t cmDataULong( const cmData_t* p, unsigned long* v );
  210. cmDtRC_t cmDataFloat( const cmData_t* p, float* v );
  211. cmDtRC_t cmDataDouble( const cmData_t* p, double* v );
  212. cmDtRC_t cmDataStr( const cmData_t* p, cmChar_t** v );
  213. cmDtRC_t cmDataConstStr( const cmData_t* p, const cmChar_t** v );
  214. cmDtRC_t cmDataBlob( const cmData_t* p, cmChar_t** v, unsigned* byteCntRef );
  215. cmDtRC_t cmDataConstBlob( const cmData_t* p, const cmChar_t** v, unsigned* byteCntRef );
  216. // Get the value of an object with conversion.
  217. cmDtRC_t cmDataGetChar( const cmData_t* p, char* v );
  218. cmDtRC_t cmDataGetUChar( const cmData_t* p, unsigned char* v );
  219. cmDtRC_t cmDataGetShort( const cmData_t* p, short* v );
  220. cmDtRC_t cmDataGetUShort( const cmData_t* p, unsigned short* v );
  221. cmDtRC_t cmDataGetInt( const cmData_t* p, int* v );
  222. cmDtRC_t cmDataGetUInt( const cmData_t* p, unsigned int* v );
  223. cmDtRC_t cmDataGetLong( const cmData_t* p, long* v );
  224. cmDtRC_t cmDataGetULong( const cmData_t* p, unsigned long* v );
  225. cmDtRC_t cmDataGetFloat( const cmData_t* p, float* v );
  226. cmDtRC_t cmDataGetDouble( const cmData_t* p, double* v );
  227. //----------------------------------------------------------------------------
  228. // Array related functions
  229. //
  230. // Notes:
  231. // 1) string arrays are arrays of string pointers.
  232. // 2) blob arrays (array of void pointers) are not supported because
  233. // there is no direct way to determine the length of each blob
  234. // and therefore they cannot be internally duplicated - a special scheme
  235. // could be devised (length goes in first 4 bytes) to make this
  236. // work but we will defer that until the need arises.
  237. //
  238. // Dynamically allocate a new array data object.
  239. //
  240. // eleCnt referes to the number of elements in the array pointed
  241. // to by 'vp'. The number of bytes pointed to by 'vp' is then
  242. // cmDataByteWidth(tid)*eleCnt.
  243. //
  244. // If no flags are set then the array pointed to by 'vp' is reallocated
  245. // and kDataFreeDtFl is set.
  246. //
  247. // If kFreeValueDtFl is set then the object will take responsibility for
  248. // releasing the memory pointed to by 'vp' when the object is destroyed
  249. // or the array is reassigned.
  250. //
  251. // If kNoCopyDtFl is set then 'vp' becomes the internal array
  252. // value (vp[cnt]) is NOT reallocated). In this case the client is
  253. // responsibile for eventually releasing the associated memory - when
  254. // the data object is no longer valid.
  255. cmDtRC_t cmDataNewArray( cmData_t* parent, cmDataTypeId_t tid, void* vp, unsigned eleCnt, unsigned flags, cmData_t** ref );
  256. cmDtRC_t cmDataNewCharArray( cmData_t* parent, char* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  257. cmDtRC_t cmDataNewUCharArray( cmData_t* parent, unsigned char* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  258. cmDtRC_t cmDataNewShortArray( cmData_t* parent, short* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  259. cmDtRC_t cmDataNewUShortArray( cmData_t* parent, unsigned short* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  260. cmDtRC_t cmDataNewIntArray( cmData_t* parent, int* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  261. cmDtRC_t cmDataNewUIntArray( cmData_t* parent, unsigned int* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  262. cmDtRC_t cmDataNewLongArray( cmData_t* parent, long* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  263. cmDtRC_t cmDataNewULongArray( cmData_t* parent, unsigned long* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  264. cmDtRC_t cmDataNewFloatArray( cmData_t* parent, float* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  265. cmDtRC_t cmDataNewDoubleArray( cmData_t* parent, double* v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  266. cmDtRC_t cmDataNewStrArray( cmData_t* parent, cmChar_t** v, unsigned eleCnt, unsigned flags, cmData_t** ref );
  267. cmDtRC_t cmDataNewConstStrArray( cmData_t* parent, const cmChar_t** v,unsigned eleCnt, unsigned flags, cmData_t** ref );
  268. // Set the value and type of an existing scalar object.
  269. //
  270. // These functions begin by releasing any resources held by *p
  271. // prior to resetting the type and value of the object.
  272. // The 'flags' argument may include kConstValueDtFl, kConstObjDtFl,
  273. // kNoCopyDtFl and the kFreeValueDtFl.
  274. // Generic set array functions. 'vp' is assumed to point to an array
  275. // of the type defined by 'tid'.
  276. cmDtRC_t cmDataSetArrayValue( cmData_t* dt, cmDataTypeId_t tid, void* vp, unsigned eleCnt, unsigned flags );
  277. // Type sepctific set array functions.
  278. cmDtRC_t cmDataSetCharArray( cmData_t* d, char* v, unsigned eleCnt, unsigned flags );
  279. cmDtRC_t cmDataSetUCharArray( cmData_t* d, unsigned char* v, unsigned eleCnt, unsigned flags );
  280. cmDtRC_t cmDataSetShortArray( cmData_t* d, short* v, unsigned eleCnt, unsigned flags );
  281. cmDtRC_t cmDataSetUShortArray( cmData_t* d, unsigned short* v, unsigned eleCnt, unsigned flags );
  282. cmDtRC_t cmDataSetIntArray( cmData_t* d, int* v, unsigned eleCnt, unsigned flags );
  283. cmDtRC_t cmDataSetUIntArray( cmData_t* d, unsigned int* v, unsigned eleCnt, unsigned flags );
  284. cmDtRC_t cmDataSetLongArray( cmData_t* d, long* v, unsigned eleCnt, unsigned flags );
  285. cmDtRC_t cmDataSetULongArray( cmData_t* d, unsigned long* v, unsigned eleCnt, unsigned flags );
  286. cmDtRC_t cmDataSetFloatArray( cmData_t* d, float* v, unsigned eleCnt, unsigned flags );
  287. cmDtRC_t cmDataSetDoubleArray( cmData_t* d, double* v, unsigned eleCnt, unsigned flags );
  288. cmDtRC_t cmDataSetStrArray( cmData_t* d, cmChar_t** v, unsigned eleCnt, unsigned flags );
  289. cmDtRC_t cmDataSetConstStrArray(cmData_t* d,const cmChar_t** v,unsigned eleCnt, unsigned flags );
  290. // Return the count of elements in a n array.
  291. unsigned cmDataArrayEleCount( const cmData_t* d );
  292. // Get a pointer to the base of an array.
  293. // The type must match exactly or an error is generated.
  294. // Use cmDataEleCount() to determine the number of elements in the array.
  295. cmDtRC_t cmDataCharArray( const cmData_t* d, char** v );
  296. cmDtRC_t cmDataUCharArray( const cmData_t* d, unsigned char** v );
  297. cmDtRC_t cmDataShortArray( const cmData_t* d, short** v );
  298. cmDtRC_t cmDataUShortArray( const cmData_t* d, unsigned short** v );
  299. cmDtRC_t cmDataIntArray( const cmData_t* d, int** v );
  300. cmDtRC_t cmDataUIntArray( const cmData_t* d, unsigned int** v );
  301. cmDtRC_t cmDataLongArray( const cmData_t* d, long** v );
  302. cmDtRC_t cmDataULongArray( const cmData_t* d, unsigned long** v );
  303. cmDtRC_t cmDataFloatArray( const cmData_t* d, float** v );
  304. cmDtRC_t cmDataDoubleArray( const cmData_t* d, double** v );
  305. cmDtRC_t cmDataStrArray( const cmData_t* d, cmChar_t*** v );
  306. cmDtRC_t cmDataConstStrArray( const cmData_t* d, const cmChar_t*** v );
  307. //----------------------------------------------------------------------------
  308. // Structure related functions
  309. //
  310. // Release an object and any resources held by it.
  311. // Note the this function does not unlink the object
  312. // from it's parent. Use cmDataUnlinkAndFree()
  313. // to remove a object from it's parent list prior
  314. // to releasing it.
  315. void cmDataFree( cmData_t* p );
  316. // Unlink 'p' from its parents and siblings.
  317. // Asserts if parent is not a structure.
  318. // Returns 'p'.
  319. cmData_t* cmDataUnlink( cmData_t* p );
  320. // Wrapper function to cmDataUnlink() and cmDataFree().
  321. void cmDataUnlinkAndFree( cmData_t* p );
  322. // Replace the 'dst' node with the 'src' node and
  323. // return 'src'. This operation does not duplicate
  324. // 'src' it simply links in 'src' at the location of
  325. // 'dst' and then unlinks and free's 'dst'.
  326. cmData_t* cmDataReplace( cmData_t* dst, cmData_t* src );
  327. // Return the count of child nodes.
  328. // 1. Array nodes have one child per array element.
  329. // 2. List nodes have one child pair.
  330. // 3. Pair nodes have two children.
  331. // 4. Leaf nodes have 0 children.
  332. unsigned cmDataChildCount( const cmData_t* p );
  333. // Returns the ith child of 'p'.
  334. // Returns NULL if p has no children or index is invalid.
  335. cmData_t* cmDataChild( cmData_t* p, unsigned index );
  336. // Prepend 'p' to 'parents' child list.
  337. // The source node 'p' is not duplicated it is simply linked in.
  338. // 'p' is automatically unlinked prior to being prepended.
  339. // Returns 'p'.
  340. cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p );
  341. // Append 'p' to the end of 'parent' child list.
  342. // The source node 'p' is not duplicated it is simply linked in.
  343. // 'p' is automatically unlinked prior to being appended.
  344. // Returns 'p'.
  345. cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p );
  346. // Insert 'p' at index. Index must be in the range:
  347. // 0 to cmDataChildCount(parent).
  348. // The source node 'p' is not duplicated it is simply linked in.
  349. // 'p' is automatically unlinked prior to being inserted.
  350. // Returns 'p'.
  351. cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p );
  352. //----------------------------------------------------------------------------
  353. // Pair related functions
  354. //
  355. // Get the key/value of a pair
  356. cmData_t* cmDataPairKey( cmData_t* p );
  357. unsigned cmDataPairKeyId( cmData_t* p );
  358. const cmChar_t* cmDataPairKeyLabel( cmData_t* p );
  359. cmData_t* cmDataPairValue( cmData_t* p );
  360. // Set the value of an existing pair node.
  361. // 'value' is not duplicated it is simply linked in place of the
  362. // previous pair value node. The previous pair value node is
  363. // unlinked and freed.
  364. // Returns 'p'.
  365. cmData_t* cmDataPairSetValue( cmData_t* p, cmData_t* value );
  366. // Set the key of an existing pair node.
  367. // The previous key is unlinked and freed.
  368. cmData_t* cmDataPairSetKey( cmData_t* p, cmData_t* key );
  369. cmData_t* cmDataPairSetKeyId( cmData_t* p, unsigned id );
  370. // The data space for the 'label' string is dynamically allocated.
  371. cmData_t* cmDataPairSetKeyLabel( cmData_t* p, const cmChar_t* label );
  372. // Create a pair value by assigning a key and value to 'p'.
  373. // 'p' is unlinked and freed prior to the key value assignment.
  374. // 'key' and 'value' are simply linked in they are not duplicated or reallocated.
  375. cmData_t* cmDataMakePair( cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t* value );
  376. // Dynamically allocate a pair node. Both the key and value nodes are reallocated.
  377. cmData_t* cmDataAllocPair( cmData_t* parent, const cmData_t* key, const cmData_t* value );
  378. // Dynamically allocate the id but link (w/o realloc) the value.
  379. cmData_t* cmDataAllocPairId( cmData_t* parent, unsigned keyId, cmData_t* value );
  380. // Dynamically allocate the label but link (w/o realloc) the value.
  381. cmData_t* cmDataAllocPairLabelN(cmData_t* parent, const cmChar_t* label, unsigned charCnt, cmData_t* value);
  382. cmData_t* cmDataAllocPairLabel( cmData_t* parent, const cmChar_t* label, cmData_t* value );
  383. //----------------------------------------------------------------------------
  384. // List related functions
  385. //
  386. // Return the count of ele's in the list.
  387. unsigned cmDataListCount( const cmData_t* p );
  388. // Return the ith element in the list.
  389. cmData_t* cmDataListEle( cmData_t* p, unsigned index );
  390. cmData_t* cmDataListMake( cmData_t* parent, cmData_t* p );
  391. cmData_t* cmDataListAlloc( cmData_t* parent);
  392. // Var-args fmt:
  393. // <contId> {<typeId>} <value> {<cnt>}
  394. // scalar types: <value> is literal,<cnt> is not included
  395. // null has no <value> or <cnt>
  396. // array types: <value> is pointer,<cnt> is element count
  397. // struct types: <value> is cmData_t, <typeId> and <cnt> is not included
  398. // Indicate the end of argument list by setting <typeId> to kInvalidDtId.
  399. // The memory for array based data types is dynamically allocated.
  400. cmRC_t cmDataListAllocV(cmData_t* parent, cmData_t** ref, va_list vl );
  401. cmRC_t cmDataListAllocA(cmData_t* parent, cmData_t** ref, ... );
  402. // Returns a ptr to 'ele'.
  403. cmData_t* cmDataListAppendEle( cmData_t* p, cmData_t* ele );
  404. cmDtRC_t cmDataListAppendV( cmData_t* p, va_list vl );
  405. cmDtRC_t cmDataListAppend( cmData_t* p, ... );
  406. // Return 'p'.
  407. cmData_t* cmDataListInsertEle( cmData_t* p, unsigned index, cmData_t* ele );
  408. cmData_t* cmDataListInsertEleN(cmData_t* p, unsigned index, cmData_t* ele[], unsigned n );
  409. //----------------------------------------------------------------------------
  410. // Record related functions
  411. //
  412. // Return count of pairs.
  413. unsigned cmDataRecdCount( const cmData_t* p );
  414. // Return the ith pair.
  415. cmData_t* cmDataRecdEle( cmData_t* p, unsigned index );
  416. // Return the ith value.
  417. cmData_t* cmDataRecdValueFromIndex( cmData_t* p, unsigned index );
  418. cmData_t* cmDataRecdValueFromId( cmData_t* p, unsigned id );
  419. cmData_t* cmDataRecdValueFromLabel( cmData_t* p, const cmChar_t* label );
  420. // Return the ith key
  421. cmData_t* cmDataRecdKey( cmData_t* p, unsigned index );
  422. unsigned cmDataRecdKeyId( cmData_t* p, unsigned index );
  423. const cmChar_t* cmDataRecdKeyLabel( cmData_t* p, unsigned index );
  424. cmData_t* cmDataRecdMake( cmData_t* parent, cmData_t* p );
  425. cmData_t* cmDataRecdAlloc( cmData_t* parent );
  426. // Append a pair node by linking the pair node 'pair' to the record node 'p'.
  427. // 'pair' is simply linked to 'p' via cmDataAppendChild() no
  428. // reallocation or duplicattion takes place.
  429. cmData_t* cmDataRecdAppendPair( cmData_t* p, cmData_t* pair );
  430. // Var-args format:
  431. // <label|id> {<cid>} <typeId> <value> {<cnt>}
  432. // scalar types: <value> is literal,<cnt> is not included
  433. // null type: has no <value> or <cnt>
  434. // ptr types: <value> is pointer, <cnt> is element count
  435. // struct types: <value> is cmData_t, <cnt> is not included
  436. // Indicate the end of argument list by setting <typeId> to kInvalidDtId.
  437. // The memory for array based data types is dynamically allocated.
  438. cmData_t* cmDataRecdAllocLabelV( cmData_t* parent, va_list vl );
  439. cmData_t* cmDataRecdAllocLabelA( cmData_t* parent, ... );
  440. cmData_t* cmDataRecdAllocIdV( cmData_t* parent, va_list vl );
  441. cmData_t* cmDataRecdAllocIdA( cmData_t* parent, ... );
  442. // Extract the data in a record to C variables.
  443. // The var-args list must be NULL terminated.
  444. // The <'id' | 'label'> identify a pair.
  445. // The <typeId> indicates the C type of 'pointer'.
  446. // The actual field type must be convertable into this pointer type or the
  447. // function will fail.
  448. // 'err' is an application supplied error object to be used if a required
  449. // field is missing. 'errRC' is the client result code to be passed with
  450. // the error report. See cmErrMsg(). Both 'err' and 'errRC' are optional.
  451. // Set kOptArgDtFl on 'typeId' to indicate that a field is optional.
  452. // <label|id> (<typeId> | kOptArgDtFl) <pointer>
  453. cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl );
  454. cmDtRC_t cmDataRecdParseLabel( cmData_t* p, cmErr_t* err, unsigned errRC, ... );
  455. cmDtRC_t cmDataRecdParseIdV( cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl );
  456. cmDtRC_t cmDataRecdParseId( cmData_t* p, cmErr_t* err, unsigned errRC, ... );
  457. unsigned cmDataSerializeByteCount( const cmData_t* p );
  458. cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt );
  459. cmDtRC_t cmDataDeserialize( const void* buf, unsigned bufByteCnt, cmData_t** pp );
  460. //-----------------------------------------------------------------------------
  461. typedef cmHandle_t cmDataParserH_t;
  462. //static cmDataParserH_t cmDataParserNullHandle;
  463. cmDtRC_t cmDataParserCreate( cmCtx_t* ctx, cmDataParserH_t* hp );
  464. cmDtRC_t cmDataParserDestroy( cmDataParserH_t* hp );
  465. bool cmDataParserIsValid( cmDataParserH_t h );
  466. // Parse a text representation into a 'record' type.
  467. // Note that the text is wrapped with implied curly braces
  468. // (e.g. "{ text }"). The contents of the text should therefore
  469. // fit the record syntax (e.g. the first token should be a
  470. // 'pair' label.
  471. cmDtRC_t cmDataParserExec( cmDataParserH_t h, const cmChar_t* text, cmData_t** pp );
  472. //-----------------------------------------------------------------------------
  473. void cmDataPrint( const cmData_t* p, cmRpt_t* rpt );
  474. void cmDataTest( cmCtx_t* ctx );
  475. #ifdef __cplusplus
  476. }
  477. #endif
  478. #endif