libcm is a C development framework with an emphasis on audio signal processing applications.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cmData.h 26KB

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