libcm is a C development framework with an emphasis on audio signal processing applications.
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

cmData.h 15KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. #ifndef cmData_h
  2. #define cmData_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. enum
  7. {
  8. kOkDtRC = cmOkRC,
  9. kCvtErrDtRC
  10. };
  11. enum
  12. {
  13. kInvalidDtChar = 0xff,
  14. kInvalidDtUChar = 0xff,
  15. kInvalidDtShort = 0xffff,
  16. kInvalidDtUShort = 0xffff,
  17. kInvalidDtInt = 0xffffffff,
  18. kInvalidDtUInt = 0xffffffff,
  19. kInvalidDtLong = 0xffffffff,
  20. kInvalidDtULong = 0xffffffff,
  21. };
  22. typedef enum
  23. {
  24. kInvalidDtId,
  25. kMinValDtId,
  26. kNullDtId = kMinValDtId,
  27. kUCharDtId,
  28. kCharDtId,
  29. kUShortDtId,
  30. kShortDtId,
  31. kUIntDtId,
  32. kIntDtId,
  33. kULongDtId,
  34. kLongDtId,
  35. kFloatDtId,
  36. kDoubleDtId,
  37. kStrDtId,
  38. kConstStrDtId,
  39. kMaxValDtId = kConstStrDtId,
  40. kMinPtrDtId,
  41. kUCharPtrDtId = kMinPtrDtId, // cnt=array element count
  42. kCharPtrDtId,
  43. kUShortPtrDtId,
  44. kShortPtrDtId,
  45. kUIntPtrDtId,
  46. kIntPtrDtId,
  47. kULongPtrDtId,
  48. kLongPtrDtId,
  49. kFloatPtrDtId,
  50. kDoublePtrDtId,
  51. kVoidPtrDtId,
  52. kMaxPtrDtId = kVoidPtrDtId,
  53. kMinStructDtId,
  54. kListDtId = kMinStructDtId, // children nodes are array elements, cnt=child count
  55. kPairDtId, // key/value pairs, cnt=2, first child is key, second is value
  56. kRecordDtId, // children nodes are pairs, cnt=pair count
  57. kMaxStructDtId
  58. } cmDataFmtId_t;
  59. enum
  60. {
  61. kDynObjDtFl = 0x01, // object was dynamically allocated
  62. kDynPtrDtFl = 0x02 // ptr array was dynamically allocated
  63. };
  64. typedef struct cmData_str
  65. {
  66. cmDataFmtId_t tid; // data format id
  67. unsigned flags; //
  68. struct cmData_str* parent; // this childs parent
  69. struct cmData_str* sibling; // this childs sibling
  70. unsigned allocCnt; // allocated count
  71. unsigned cnt; // actual count
  72. union
  73. {
  74. char c;
  75. unsigned char uc;
  76. short s;
  77. unsigned short us;
  78. int i;
  79. unsigned int ui;
  80. long l;
  81. unsigned long ul;
  82. float f;
  83. double d;
  84. cmChar_t* z;
  85. const cmChar_t* cz;
  86. void* vp;
  87. char* cp;
  88. unsigned char* ucp;
  89. short* sp;
  90. unsigned short* usp;
  91. int* ip;
  92. unsigned int* uip;
  93. long* lp;
  94. unsigned long* ulp;
  95. float* fp;
  96. double* dp;
  97. struct cmData_str* child; // first child (array,record,pair)
  98. } u;
  99. } cmData_t;
  100. typedef unsigned cmDtRC_t;
  101. bool cmDataIsValue( const cmData_t* p );
  102. bool cmDataIsPtr( const cmData_t* p );
  103. bool cmDataIsStruct( const cmData_t* p );
  104. // Get the value of an object without conversion.
  105. // The data type id must match the return type or the
  106. // conversion must be an automatic C conversion.
  107. char cmDataChar( const cmData_t* p );
  108. unsigned char cmDataUChar( const cmData_t* p );
  109. short cmDataShort( const cmData_t* p );
  110. unsigned short cmDataUShort( const cmData_t* p );
  111. int cmDataInt( const cmData_t* p );
  112. unsigned int cmDataUInt( const cmData_t* p );
  113. long cmDataLong( const cmData_t* p );
  114. unsigned long cmDataULong( const cmData_t* p );
  115. float cmDataFloat( const cmData_t* p );
  116. double cmDataDouble( const cmData_t* p );
  117. cmChar_t* cmDataStr( const cmData_t* p );
  118. const cmChar_t* cmDataConstStr( const cmData_t* p );
  119. void* cmDataVoidPtr( const cmData_t* p );
  120. char* cmDataCharPtr( const cmData_t* p );
  121. unsigned char* cmDataUCharPtr( const cmData_t* p );
  122. short* cmDataShortPtr( const cmData_t* p );
  123. unsigned short* cmDataUShortPtr( const cmData_t* p );
  124. int* cmDataIntPtr( const cmData_t* p );
  125. unsigned int* cmDataUIntPtr( const cmData_t* p );
  126. long* cmDataLongPtr( const cmData_t* p );
  127. unsigned long* cmDataULongPtr( const cmData_t* p );
  128. float* cmDataFloatPtr( const cmData_t* p );
  129. double* cmDataDoublePtr( const cmData_t* p );
  130. // Get the value of an object with conversion.
  131. char cmDataGetChar( const cmData_t* p );
  132. unsigned char cmDataGetUChar( const cmData_t* p );
  133. short cmDataGetShort( const cmData_t* p );
  134. unsigned short cmDataGetUShort( const cmData_t* p );
  135. int cmDataGetInt( const cmData_t* p );
  136. unsigned int cmDataGetUInt( const cmData_t* p );
  137. long cmDataGetLong( const cmData_t* p );
  138. unsigned long cmDataGetULong( const cmData_t* p );
  139. float cmDataGetFloat( const cmData_t* p );
  140. double cmDataGetDouble( const cmData_t* p );
  141. cmChar_t* cmDataGetStr( const cmData_t* p );
  142. const cmChar_t* cmDataGetConstStr( const cmData_t* p );
  143. void* cmDataGetVoidPtr( const cmData_t* p );
  144. char* cmDataGetCharPtr( const cmData_t* p );
  145. unsigned char* cmDataGetUCharPtr( const cmData_t* p );
  146. short* cmDataGetShortPtr( const cmData_t* p );
  147. unsigned short* cmDataGetUShortPtr( const cmData_t* p );
  148. int* cmDataGetIntPtr( const cmData_t* p );
  149. unsigned int* cmDataGetUIntPtr( const cmData_t* p );
  150. long* cmDataGetLongPtr( const cmData_t* p );
  151. unsigned long* cmDataGetULongPtr( const cmData_t* p );
  152. float* cmDataGetFloatPtr( const cmData_t* p );
  153. double* cmDataGetDoublePtr( const cmData_t* p );
  154. // Set the value of an existing data object.
  155. cmData_t* cmDataSetChar( cmData_t* p, char v );
  156. cmData_t* cmDataSetUChar( cmData_t* p, unsigned char v );
  157. cmData_t* cmDataSetShort( cmData_t* p, short v );
  158. cmData_t* cmDataSetUShort( cmData_t* p, unsigned short v );
  159. cmData_t* cmDataSetInt( cmData_t* p, int v );
  160. cmData_t* cmDataSetUInt( cmData_t* p, unsigned int v );
  161. cmData_t* cmDataSetLong( cmData_t* p, long v );
  162. cmData_t* cmDataSetULong( cmData_t* p, unsigned long v );
  163. cmData_t* cmDataSetFloat( cmData_t* p, float v );
  164. cmData_t* cmDataSetDouble( cmData_t* p, double v );
  165. cmData_t* cmDataSetStr( cmData_t* p, cmChar_t* s );
  166. cmData_t* cmDataSetConstStr( cmData_t* p, const cmChar_t* s );
  167. // Set the value of an existing data object to an external array.
  168. // The array is not copied.
  169. cmData_t* cmDataSetVoidPtr( cmData_t* p, void* vp, unsigned cnt );
  170. cmData_t* cmDataSetCharPtr( cmData_t* p, char* vp, unsigned cnt );
  171. cmData_t* cmDataSetUCharPtr( cmData_t* p, unsigned char* vp, unsigned cnt );
  172. cmData_t* cmDataSetShortPtr( cmData_t* p, short* vp, unsigned cnt );
  173. cmData_t* cmDataSetUShortPtr( cmData_t* p, unsigned short* vp, unsigned cnt );
  174. cmData_t* cmDataSetIntPtr( cmData_t* p, int* vp, unsigned cnt );
  175. cmData_t* cmDataSetUIntPtr( cmData_t* p, unsigned int* vp, unsigned cnt );
  176. cmData_t* cmDataSetLongPtr( cmData_t* p, long* vp, unsigned cnt );
  177. cmData_t* cmDataSetULongPtr( cmData_t* p, unsigned long* vp, unsigned cnt );
  178. cmData_t* cmDataSetFloatPtr( cmData_t* p, float* vp, unsigned cnt );
  179. cmData_t* cmDataSetDoublePtr( cmData_t* p, double* vp, unsigned cnt );
  180. // Set the value of an existing array based data object.
  181. // Allocate the internal array and copy the array into it.
  182. cmData_t* cmDataSetStrAlloc( cmData_t* p, const cmChar_t* s );
  183. cmData_t* cmDataSetConstStrAlloc( cmData_t* p, const cmChar_t* s );
  184. cmData_t* cmDataSetVoidAllocPtr( cmData_t* p, const void* vp, unsigned cnt );
  185. cmData_t* cmDataSetCharAllocPtr( cmData_t* p, const char* vp, unsigned cnt );
  186. cmData_t* cmDataSetUCharAllocPtr( cmData_t* p, const unsigned char* vp, unsigned cnt );
  187. cmData_t* cmDataSetShortAllocPtr( cmData_t* p, const short* vp, unsigned cnt );
  188. cmData_t* cmDataSetUShortAllocPtr( cmData_t* p, const unsigned short* vp, unsigned cnt );
  189. cmData_t* cmDataSetIntAllocPtr( cmData_t* p, const int* vp, unsigned cnt );
  190. cmData_t* cmDataSetUIntAllocPtr( cmData_t* p, const unsigned int* vp, unsigned cnt );
  191. cmData_t* cmDataSetLongAllocPtr( cmData_t* p, const long* vp, unsigned cnt );
  192. cmData_t* cmDataSetULongAllocPtr( cmData_t* p, const unsigned long* vp, unsigned cnt );
  193. cmData_t* cmDataSetFloatAllocPtr( cmData_t* p, const float* vp, unsigned cnt );
  194. cmData_t* cmDataSetDoubleAllocPtr( cmData_t* p, const double* vp, unsigned cnt );
  195. // Dynamically allocate a data object and set it's value.
  196. cmData_t* cmDataAllocChar( char v );
  197. cmData_t* cmDataAllocUChar( unsigned char v );
  198. cmData_t* cmDataAllocShort( short v );
  199. cmData_t* cmDataAllocUShort( unsigned short v );
  200. cmData_t* cmDataAllocInt( int v );
  201. cmData_t* cmDataAllocUInt( unsigned int v );
  202. cmData_t* cmDataAllocLong( long v );
  203. cmData_t* cmDataAllocULong( unsigned long v );
  204. cmData_t* cmDataAllocFloat( float v );
  205. cmData_t* cmDataAllocDouble( double v );
  206. cmData_t* cmDataAllocStr( cmChar_t* str );
  207. cmData_t* cmDataAllocConstStr( const cmChar_t* str );
  208. // Dynamically allocate a data object and set its array value to an external
  209. // array. The data is not copied.
  210. cmData_t* cmDataAllocVoidPtr( const void* v, unsigned cnt );
  211. cmData_t* cmDataAllocCharPtr( const char* v, unsigned cnt );
  212. cmData_t* cmDataAllocUCharPtr( const unsigned char* v, unsigned cnt );
  213. cmData_t* cmDataAllocShortPtr( const short* v, unsigned cnt );
  214. cmData_t* cmDataAllocUShortPtr( const unsigned short* v, unsigned cnt );
  215. cmData_t* cmDataAllocIntPtr( const int* v, unsigned cnt );
  216. cmData_t* cmDataAllocUIntPtr( const unsigned int* v, unsigned cnt );
  217. cmData_t* cmDataAllocLongPtr( const long* v, unsigned cnt );
  218. cmData_t* cmDataAllocULongPtr( const unsigned long* v, unsigned cnt );
  219. cmData_t* cmDataAllocFloatPtr( const float* v, unsigned cnt );
  220. cmData_t* cmDataAllocDoublePtr( const double* v, unsigned cnt );
  221. // Dynamically allocate a data object and its array value.
  222. // v[cnt] is copied into the allocated array.
  223. cmData_t* cmDataVoidAllocPtr( const void* v, unsigned cnt );
  224. cmData_t* cmDataCharAllocPtr( const char* v, unsigned cnt );
  225. cmData_t* cmDataUCharAllocPtr( const unsigned char* v, unsigned cnt );
  226. cmData_t* cmDataShortAllocPtr( const short* v, unsigned cnt );
  227. cmData_t* cmDataUShortAllocPtr( const unsigned short* v, unsigned cnt );
  228. cmData_t* cmDataIntAllocPtr( const int* v, unsigned cnt );
  229. cmData_t* cmDataUIntAllocPtr( const unsigned int* v, unsigned cnt );
  230. cmData_t* cmDataLongAllocPtr( const long* v, unsigned cnt );
  231. cmData_t* cmDataULongAllocPtr( const unsigned long* v, unsigned cnt );
  232. cmData_t* cmDataFloatAllocPtr( const float* v, unsigned cnt );
  233. cmData_t* cmDataDoubleAllocPtr( const double* v, unsigned cnt );
  234. //----------------------------------------------------------------------------
  235. // Structure related functions
  236. //
  237. // Unlink 'p' from its parents and siblings.
  238. // Asserts if parent is not a structure.
  239. // Returns 'p'.
  240. cmData_t* cmDataUnlink( cmData_t* p );
  241. unsigned cmDataChildCount( const cmData_t* p );
  242. // Returns NULL if p has no children or index is invalid.
  243. cmData_t* cmDataChild( cmData_t* p, unsigned index );
  244. // Prepend 'p' to 'parents' child list.
  245. cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p );
  246. // Append 'p' to the end of 'parent' child list.
  247. cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p );
  248. // Insert 'p' at index. Index must be in the range:
  249. // 0 to cmDataChildCount(parent).
  250. cmData_t* cmDataInsertChild( cmData_t* parent, cmData_t* p, unsigned index );
  251. //----------------------------------------------------------------------------
  252. // Pair related functions
  253. //
  254. // Get the key/value of a pair
  255. cmData_t* cmDataPairKey( cmData_t* p );
  256. cmData_t* cmDataPairValue( cmData_t* p );
  257. // Set the key or value of an existing pair node.
  258. cmData_t* cmDataPairSetValue( cmData_t* p, cmData_t* value );
  259. cmData_t* cmDataPairAllocValue( cmData_t* p, const cmData_t* value );
  260. cmData_t* cmDataPairSetKey( cmData_t* p, cmData_t* key );
  261. cmData_t* cmDataPairSetKeyId( cmData_t* p, unsigned id );
  262. cmData_t* cmDataPairSetKeyLabel( cmData_t* p, const cmChar_t* label );
  263. cmData_t* cmDataPairAllocKey( cmData_t* p, const cmData_t* key );
  264. // Dynamically allocate a pair node
  265. cmData_t* cmDataAllocPair( cmData_t* parent, const cmData_t* key, const cmData_t* value );
  266. cmData_t* cmDataAllocPairId( cmData_t* parent, unsigned keyId, cmData_t* value );
  267. cmData_t* cmDataAllocPairLabel( cmData_t* parent, const cmChar_t label, cmData_t* value );
  268. //----------------------------------------------------------------------------
  269. // List related functions
  270. //
  271. // Return the count of ele's in the list.
  272. cmData_t* cmDataListCount( const cmData_t* p );
  273. // Return the ith element in the list.
  274. cmData_t* cmDataListEle( const cmData_t* p, unsigned index );
  275. cmData_t* cmDataListMake( cmData_t* parent, cmData_t* p );
  276. cmData_t* cmDataListAlloc( cmData_t* parent);
  277. // Var-args fmt:
  278. // <typeId> <value> {<cnt>}
  279. // scalar types: <value> is literal,<cnt> is not included
  280. // ptr types: <value> is pointer,<cnt> is element count
  281. // struct types: <value> is cmData_t, <cnt> is not included
  282. cmData_t* cmDataListAllocV(cmData_t* parent, va_list vl );
  283. cmData_t* cmDataListAllocA(cmData_t* parent, ... );
  284. cmData_t* cmDataListAppendEle( cmData_t* p, cmData_t* ele );
  285. cmData_t* cmDataListAppendEleN(cmData_t* p, cmData_t* ele[], unsigned n );
  286. cmDtRC_t cmDataListAppendV( cmData_t* p, va_list vl );
  287. cmDtRC_t cmDataListAppend( cmData_t* p, ... );
  288. cmData_t* cmDataListInsertEle( cmData_t* p, unsigned index, cmData_t* ele );
  289. cmData_t* cmDataListInsertEleN(cmData_t* p, cmData_t* ele[], unsigned n );
  290. cmDtRC_t cmDataListInsertV( cmData_t* p, va_list vl );
  291. cmDtRC_t cmDataListInsert( cmData_t* p, unsigned index, ... );
  292. cmData_t* cmDataListUnlink( cmData_t* p, unsigned index );
  293. cmData_t* cmDataListFree( cmData_t* p, unsigned index );
  294. //----------------------------------------------------------------------------
  295. // Record related functions
  296. //
  297. // Return count of pairs.
  298. cmData_t* cmDataRecdCount( const cmData_t* p );
  299. // Return the ith pair.
  300. cmData_t* cmDataRecdEle( const cmData_t* p, unsigned index );
  301. // Return the ith value.
  302. cmData_t* cmDataRecdValue( const cmData_t* p, unsigned index );
  303. // Return the ith key
  304. cmData_t* cmDataRecdKey( const cmData_t* p, unsigned index );
  305. unsigned cmDataRecdKeyId( const cmData_t* p, unsigned index );
  306. const cmChar_t* cmDataRecdKeyLabel( const cmData_t* p, unsigned index );
  307. cmData_t* cmRecdMake( cmData_t* p );
  308. cmData_t* cmRecdAlloc();
  309. void cmDataFree( cmData_t* p );
  310. unsigned cmDataSerializeByteCount( const cmData_t* p );
  311. cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt );
  312. cmDtRC_t cmDataDeserialize( const void* buf, unsigned bufByteCnt, cmData_t** pp );
  313. void cmDataPrint( const cmData_t* p, cmRpt_t* rpt );
  314. void cmDataTest( cmCtx_t* ctx );
  315. #ifdef __cplusplus
  316. }
  317. #endif
  318. #endif