libcm is a C development framework with an emphasis on audio signal processing applications.
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

cmData.h 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  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. kNullDtId,
  26. kUCharDtId,
  27. kCharDtId,
  28. kUShortDtId,
  29. kShortDtId,
  30. kUIntDtId,
  31. kIntDtId,
  32. kULongDtId,
  33. kLongDtId,
  34. kFloatDtId,
  35. kDoubleDtId,
  36. kStrDtId,
  37. kConstStrDtId,
  38. kMinPtrDtId,
  39. kUCharPtrDtId = kMinPtrDtId, // cnt=array element count
  40. kCharPtrDtId,
  41. kUShortPtrDtId,
  42. kShortPtrDtId,
  43. kUIntPtrDtId,
  44. kIntPtrDtId,
  45. kULongPtrDtId,
  46. kLongPtrDtId,
  47. kFloatPtrDtId,
  48. kDoublePtrDtId,
  49. kVoidPtrDtId,
  50. kMaxPtrDtId = kVoidPtrDtId,
  51. kMinStructDtId,
  52. kListDtId = kMinStructDtId, // children nodes are array elements, cnt=child count
  53. kPairDtId, // key/value pairs, cnt=2, first child is key, second is value
  54. kRecordDtId, // children nodes are pairs, cnt=pair count
  55. kMaxStructDtId
  56. } cmDataFmtId_t;
  57. enum
  58. {
  59. kDynObjDtFl = 0x01, // object was dynamically allocated
  60. kDynPtrDtFl = 0x02 // ptr array was dynamically allocated
  61. };
  62. typedef struct cmData_str
  63. {
  64. cmDataFmtId_t tid; // data format id
  65. unsigned flags; //
  66. struct cmData_str* parent; // this childs parent
  67. struct cmData_str* sibling; // this childs sibling
  68. unsigned allocCnt; // allocated count
  69. unsigned cnt; // actual count
  70. union
  71. {
  72. char c;
  73. unsigned char uc;
  74. short s;
  75. unsigned short us;
  76. int i;
  77. unsigned int ui;
  78. long l;
  79. unsigned long ul;
  80. float f;
  81. double d;
  82. cmChar_t* z;
  83. const cmChar_t* cz;
  84. void* vp;
  85. char* cp;
  86. unsigned char* ucp;
  87. short* sp;
  88. unsigned short* usp;
  89. int* ip;
  90. unsigned int* uip;
  91. long* lp;
  92. unsigned long* ulp;
  93. float* fp;
  94. double* dp;
  95. struct cmData_str* child; // first child (array,record,pair)
  96. } u;
  97. } cmData_t;
  98. typedef unsigned cmDtRC_t;
  99. // Get the value of an object without conversion.
  100. // The data type id must match the return type or the
  101. // conversion must be an automatic C conversion.
  102. char cmDataChar( const cmData_t* p );
  103. unsigned char cmDataUChar( const cmData_t* p );
  104. short cmDataShort( const cmData_t* p );
  105. unsigned short cmDataUShort( const cmData_t* p );
  106. int cmDataInt( const cmData_t* p );
  107. unsigned int cmDataUInt( const cmData_t* p );
  108. long cmDataLong( const cmData_t* p );
  109. unsigned long cmDataULong( const cmData_t* p );
  110. float cmDataFloat( const cmData_t* p );
  111. double cmDataDouble( const cmData_t* p );
  112. cmChar_t* cmDataStr( const cmData_t* p );
  113. const cmChar_t* cmDataConstStr( const cmData_t* p );
  114. void* cmDataVoidPtr( const cmData_t* p );
  115. char* cmDataCharPtr( const cmData_t* p );
  116. unsigned char* cmDataUCharPtr( const cmData_t* p );
  117. short* cmDataShortPtr( const cmData_t* p );
  118. unsigned short* cmDataUShortPtr( const cmData_t* p );
  119. int* cmDataIntPtr( const cmData_t* p );
  120. unsigned int* cmDataUIntPtr( const cmData_t* p );
  121. long* cmDataLongPtr( const cmData_t* p );
  122. unsigned long* cmDataULongPtr( const cmData_t* p );
  123. float* cmDataFloatPtr( const cmData_t* p );
  124. double* cmDataDoublePtr( const cmData_t* p );
  125. // Get the value of an object with conversion.
  126. char cmDataGetChar( const cmData_t* p );
  127. unsigned char cmDataGetUChar( const cmData_t* p );
  128. short cmDataGetShort( const cmData_t* p );
  129. unsigned short cmDataGetUShort( const cmData_t* p );
  130. int cmDataGetInt( const cmData_t* p );
  131. unsigned int cmDataGetUInt( const cmData_t* p );
  132. long cmDataGetLong( const cmData_t* p );
  133. unsigned long cmDataGetULong( const cmData_t* p );
  134. float cmDataGetFloat( const cmData_t* p );
  135. double cmDataGetDouble( const cmData_t* p );
  136. cmChar_t* cmDataGetStr( const cmData_t* p );
  137. const cmChar_t* cmDataGetConstStr( const cmData_t* p );
  138. void* cmDataGetVoidPtr( const cmData_t* p );
  139. char* cmDataGetCharPtr( const cmData_t* p );
  140. unsigned char* cmDataGetUCharPtr( const cmData_t* p );
  141. short* cmDataGetShortPtr( const cmData_t* p );
  142. unsigned short* cmDataGetUShortPtr( const cmData_t* p );
  143. int* cmDataGetIntPtr( const cmData_t* p );
  144. unsigned int* cmDataGetUIntPtr( const cmData_t* p );
  145. long* cmDataGetLongPtr( const cmData_t* p );
  146. unsigned long* cmDataGetULongPtr( const cmData_t* p );
  147. float* cmDataGetFloatPtr( const cmData_t* p );
  148. double* cmDataGetDoublePtr( const cmData_t* p );
  149. // Set the value of an existing data object.
  150. void cmDataSetChar( cmData_t* p, char v );
  151. void cmDataSetUChar( cmData_t* p, unsigned char v );
  152. void cmDataSetShort( cmData_t* p, short v );
  153. void cmDataSetUShort( cmData_t* p, unsigned short v );
  154. void cmDataSetInt( cmData_t* p, int v );
  155. void cmDataSetUInt( cmData_t* p, unsigned int v );
  156. void cmDataSetLong( cmData_t* p, long v );
  157. void cmDataSetULong( cmData_t* p, unsigned long v );
  158. void cmDataSetFloat( cmData_t* p, float v );
  159. void cmDataSetDouble( cmData_t* p, double v );
  160. void cmDataSetStr( cmData_t* p, cmChar_t* s );
  161. void cmDataSetConstStr( cmData_t* p, const cmChar_t* s );
  162. // Set the value of an existing data object to an external array.
  163. // The array is not copied.
  164. void cmDataSetVoidPtr( cmData_t* p, void* vp, unsigned cnt );
  165. void cmDataSetCharPtr( cmData_t* p, char* vp, unsigned cnt );
  166. void cmDataSetUCharPtr( cmData_t* p, unsigned char* vp, unsigned cnt );
  167. void cmDataSetShortPtr( cmData_t* p, short* vp, unsigned cnt );
  168. void cmDataSetUShortPtr( cmData_t* p, unsigned short* vp, unsigned cnt );
  169. void cmDataSetIntPtr( cmData_t* p, int* vp, unsigned cnt );
  170. void cmDataSetUIntPtr( cmData_t* p, unsigned int* vp, unsigned cnt );
  171. void cmDataSetLongPtr( cmData_t* p, long* vp, unsigned cnt );
  172. void cmDataSetULongPtr( cmData_t* p, unsigned long* vp, unsigned cnt );
  173. void cmDataSetFloatPtr( cmData_t* p, float* vp, unsigned cnt );
  174. void cmDataSetDoublePtr( cmData_t* p, double* vp, unsigned cnt );
  175. // Set the value of an existing array based data object.
  176. // Allocate the internal array and copy the array into it.
  177. void cmDataSetStrAlloc( cmData_t* p, const cmChar_t* s );
  178. void cmDataSetConstStrAlloc( cmData_t* p, const cmChar_t* s );
  179. void cmDataSetVoidAllocPtr( cmData_t* p, const void* vp, unsigned cnt );
  180. void cmDataSetCharAllocPtr( cmData_t* p, const char* vp, unsigned cnt );
  181. void cmDataSetUCharAllocPtr( cmData_t* p, const unsigned char* vp, unsigned cnt );
  182. void cmDataSetShortAllocPtr( cmData_t* p, const short* vp, unsigned cnt );
  183. void cmDataSetUShortAllocPtr( cmData_t* p, const unsigned short* vp, unsigned cnt );
  184. void cmDataSetIntAllocPtr( cmData_t* p, const int* vp, unsigned cnt );
  185. void cmDataSetUIntAllocPtr( cmData_t* p, const unsigned int* vp, unsigned cnt );
  186. void cmDataSetLongAllocPtr( cmData_t* p, const long* vp, unsigned cnt );
  187. void cmDataSetULongAllocPtr( cmData_t* p, const unsigned long* vp, unsigned cnt );
  188. void cmDataSetFloatAllocPtr( cmData_t* p, const float* vp, unsigned cnt );
  189. void cmDataSetDoubleAllocPtr( cmData_t* p, const double* vp, unsigned cnt );
  190. // Dynamically allocate a data object and set it's value.
  191. cmData_t* cmDataAllocChar( char v );
  192. cmData_t* cmDataAllocUChar( unsigned char v );
  193. cmData_t* cmDataAllocShort( short v );
  194. cmData_t* cmDataAllocUShort( unsigned short v );
  195. cmData_t* cmDataAllocInt( int v );
  196. cmData_t* cmDataAllocUInt( unsigned int v );
  197. cmData_t* cmDataAllocLong( long v );
  198. cmData_t* cmDataAllocULong( unsigned long v );
  199. cmData_t* cmDataAllocFloat( float v );
  200. cmData_t* cmDataAllocDouble( double v );
  201. cmData_t* cmDataAllocStr( cmChar_t* str );
  202. cmData_t* cmDataAllocConstStr( const cmChar_t* str );
  203. // Dynamically allocate a data object and set its array value to an external
  204. // array. The data is not copied.
  205. cmData_t* cmDataAllocVoidPtr( const void* v, unsigned cnt );
  206. cmData_t* cmDataAllocCharPtr( const char* v, unsigned cnt );
  207. cmData_t* cmDataAllocUCharPtr( const unsigned char* v, unsigned cnt );
  208. cmData_t* cmDataAllocShortPtr( const short* v, unsigned cnt );
  209. cmData_t* cmDataAllocUShortPtr( const unsigned short* v, unsigned cnt );
  210. cmData_t* cmDataAllocIntPtr( const int* v, unsigned cnt );
  211. cmData_t* cmDataAllocUIntPtr( const unsigned int* v, unsigned cnt );
  212. cmData_t* cmDataAllocLongPtr( const long* v, unsigned cnt );
  213. cmData_t* cmDataAllocULongPtr( const unsigned long* v, unsigned cnt );
  214. cmData_t* cmDataAllocFloatPtr( const float* v, unsigned cnt );
  215. cmData_t* cmDataAllocDoublePtr( const double* v, unsigned cnt );
  216. // Dynamically allocate a data object and its array value.
  217. // v[cnt] is copied into the allocated array.
  218. cmData_t* cmDataVoidAllocPtr( const void* v, unsigned cnt );
  219. cmData_t* cmDataCharAllocPtr( const char* v, unsigned cnt );
  220. cmData_t* cmDataUCharAllocPtr( const unsigned char* v, unsigned cnt );
  221. cmData_t* cmDataShortAllocPtr( const short* v, unsigned cnt );
  222. cmData_t* cmDataUShortAllocPtr( const unsigned short* v, unsigned cnt );
  223. cmData_t* cmDataIntAllocPtr( const int* v, unsigned cnt );
  224. cmData_t* cmDataUIntAllocPtr( const unsigned int* v, unsigned cnt );
  225. cmData_t* cmDataLongAllocPtr( const long* v, unsigned cnt );
  226. cmData_t* cmDataULongAllocPtr( const unsigned long* v, unsigned cnt );
  227. cmData_t* cmDataFloatAllocPtr( const float* v, unsigned cnt );
  228. cmData_t* cmDataDoubleAllocPtr( const double* v, unsigned cnt );
  229. void cmDataFree( cmData_t* p );
  230. unsigned cmDataSerializeByteCount( const cmData_t* p );
  231. cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt );
  232. cmDtRC_t cmDataDeserialize( const void* buf, unsigned bufByteCnt, cmData_t** pp );
  233. void cmDataPrint( const cmData_t* p, cmRpt_t* rpt );
  234. void cmDataTest( cmCtx_t* ctx );
  235. #ifdef __cplusplus
  236. }
  237. #endif
  238. #endif