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.c 27KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006
  1. #include "cmData.h"
  2. cmDtRC_t _cmDataErrNo = kOkDtRC;
  3. void _cmDataFreeArray( cmData_t* p )
  4. {
  5. if(cmIsFlag(p->flags,kDynPtrDtFl))
  6. {
  7. cmMemFree(p->vp);
  8. p->vp = NULL;
  9. p->flags = cmClrFlag(p->flags,kDynPtrFl);
  10. }
  11. p->tid = cmInvalidDtId;
  12. p->cnt = 0;
  13. }
  14. void _cmDataFree( cmData_t* p )
  15. {
  16. _cmDataFreeArray(p);
  17. if( cmIsFlag(p->flags,kDynObjDtFl) )
  18. cmMemFree(p);
  19. }
  20. unsigned _cmDataByteCount( cmData_t* p )
  21. {
  22. unsigned n = sizeof(cmDataSerialHdr_t)
  23. switch( p->tid )
  24. {
  25. case kInvalidDtId: return 0;
  26. case kNullDtId: return n;
  27. case kUCharDtId: return n + sizeof(unsigned char);
  28. case kCharDtId: return n + sizeof(char);
  29. case kUShortDtId: return n + sizeof(unsigned short);
  30. case kShortDtId: return n + sizeof(short);
  31. case kUIntDtId: return n + sizeof(unsigned int);
  32. case kIntDtId: return n + sizeof(int);
  33. case kULongDtId: return n + sizeof(unsigned long);
  34. case kLongDtId: return n + sizeof(long);
  35. case kFloatDtId: return n + sizeof(float);
  36. case kDoubleDtId: return n + sizeof(double);
  37. case kStrDtId: return n + (p->u.z ==NULL ? 0 : strlen(p->u.z) + 1);
  38. case kConstStrDtId: return n + (p->u.cz==NULL ? 0 : strlen(p->u.cz) + 1);
  39. case kUCharPtrDtId: return n + p->cnt * sizeof(unsigned char);
  40. case kCharPtrDtId: return n + p->cnt * sizeof(char);
  41. case kUShortPtrDtId: return n + p->cnt * sizeof(unsigned short);
  42. case kShortPtrDtId: return n + p->cnt * sizeof(short);
  43. case kUIntPtrDtId: return n + p->cnt * sizeof(unsigned int);
  44. case kIntPtrDtId: return n + p->cnt * sizeof(int);
  45. case kULongPtrDtId: return n + p->cnt * sizeof(unsigned long);
  46. case kLongPtrDtId: return n + p->cnt * sizeof(long);
  47. case kFloatPtrDtId: return n + p->cnt * sizeof(float);
  48. case kDoublePtrDtId: return n + p->cnt * sizeof(double);
  49. case kVoidPtrDtId: return n + p->cnt * sizeof(char);
  50. }
  51. assert(0);
  52. return 0;
  53. }
  54. char cmDataChar( const cmData_t* p ) { assert(p->tid==kCharDtId); p->u.c; }
  55. unsigned char cmDataUChar( const cmData_t* p ) { assert(p->tid==kUCharDtId); p->u.uc; }
  56. short cmDataShort( const cmData_t* p ) { assert(p->tid==kShortDtId); p->u.s; }
  57. unsigned short cmDataUShort( const cmData_t* p ) { assert(p->tid==kUShortDtId); p->u.us; }
  58. int cmDataInt( const cmData_t* p ) { assert(p->tid==kIntDtId); p->u.i; }
  59. unsigned int cmDataUInt( const cmData_t* p ) { assert(p->tid==kUIntDtId); p->u.ui; }
  60. long cmDataLong( const cmData_t* p ) { assert(p->tid==kLongDtId); p->u.l; }
  61. unsigned long cmDataULong( const cmData_t* p ) { assert(p->tid==kULongDtId); p->u.ul; }
  62. float cmDataFloat( const cmData_t* p ) { assert(p->tid==kFloatDtId); p->u.f; }
  63. double cmDataDouble( const cmData_t* p ) { assert(p->tid==kDoubleDtId); p->u.d; }
  64. cmChar_t* cmDataStr( const cmData_t* p ) { assert(p->tid==kStrDtId); p->u.z; }
  65. const cmChar_t* cmDataConstStr( const cmData_t* p ) { assert(p->tid==kConstStrDtId); p->u.cz; }
  66. void* cmDataVoidPtr( const cmData_t* p ) { assert(p->tid==kVoidDtId); p->u.vp; }
  67. char* cmDataCharPtr( const cmData_t* p ) { assert(p->tid==kCharPtrDtId); p->u.cp; }
  68. unsigned char* cmDataUCharPtr( const cmData_t* p ) { assert(p->tid==kUCharPtrDtId); p->u.ucp; }
  69. short* cmDataShortPtr( const cmData_t* p ) { assert(p->tid==kShortPtrDtId); p->u.sp; }
  70. unsigned short* cmDataUShortPtr( const cmData_t* p ) { assert(p->tid==kUShortPtrDtId); p->u.usp; }
  71. int* cmDataIntPtr( const cmData_t* p ) { assert(p->tid==kIntPtrDtId); p->u.ip; }
  72. unsigned int* cmDataUIntPtr( const cmData_t* p ) { assert(p->tid==kUIntPtrDtId); p->u.uip; }
  73. long* cmDataLongPtr( const cmData_t* p ) { assert(p->tid==kLongPtrDtId); p->u.lp; }
  74. unsigned long* cmDataULongPtr( const cmData_t* p ) { assert(p->tid==kULongPtrDtId); p->u.ulp; }
  75. float* cmDataFloatPtr( const cmData_t* p ) { assert(p->tid==kFloatPtrDtId); p->u.fp; }
  76. double* cmDataDoublePtr( const cmData_t* p ) { assert(p->tid==kDoublePtrDtId); p->u.dp; }
  77. unsigned char cmDataGetUChar( const cmData_t* p )
  78. {
  79. unsigned char v = kInvalidUChar;
  80. switch( p->tid )
  81. {
  82. case kUCharDtId: v = p->u.uc; break;
  83. case kCharDtId: v = (unsigned char)p->u.c; break;
  84. case kUShortDtId: v = (unsigned char)p->u.us; break;
  85. case kShortDtId: v = (unsigned char)p->u.s; break;
  86. case kUIntDtId: v = (unsigned char)p->u.ui; break;
  87. case kIntDtId: v = (unsigned char)p->u.i; break;
  88. case kULongDtId: v = (unsigned char)p->u.ul; break;
  89. case kLongDtId: v = (unsigned char)p->u.l; break;
  90. case kFloatDtId: v = (unsigned char)p->u.f; break;
  91. case kDoubleDtId: v = (unsigned char)p->u.d; break;
  92. default:
  93. _cmDataErrNo = kCvtErrDtRC;
  94. }
  95. return v;
  96. }
  97. char cmDataGetChar( const cmData_t* p )
  98. {
  99. char v = kInvalidChar;
  100. switch( p->tid )
  101. {
  102. case kUCharDtId: v = (char)p->u.uc; break;
  103. case kCharDtId: v = p->u.c; break;
  104. case kUShortDtId: v = (char)p->u.us; break;
  105. case kShortDtId: v = (char)p->u.s; break;
  106. case kUIntDtId: v = (char)p->u.ui; break;
  107. case kIntDtId: v = (char)p->u.i; break;
  108. case kULongDtId: v = (char)p->u.ul; break;
  109. case kLongDtId: v = (char)p->u.l; break;
  110. case kFloatDtId: v = (char)p->u.f; break;
  111. case kDoubleDtId: v = (char)p->u.d; break;
  112. default:
  113. _cmDataErrNo = kCvtErrDtRC;
  114. }
  115. return v;
  116. }
  117. short cmDataGetShort( const cmData_t* p )
  118. {
  119. short v = kInvalidShort;
  120. switch( p->tid )
  121. {
  122. case kUCharDtId: v = (short)p->u.uc; break;
  123. case kCharDtId: v = (short)p->u.c; break;
  124. case kUShortDtId: v = (short)p->u.us; break;
  125. case kShortDtId: v = p->u.s; break;
  126. case kUIntDtId: v = (short)p->u.ui; break;
  127. case kIntDtId: v = (short)p->u.i; break;
  128. case kULongDtId: v = (short)p->u.ul; break;
  129. case kLongDtId: v = (short)p->u.l; break;
  130. case kFloatDtId: v = (short)p->u.f; break;
  131. case kDoubleDtId: v = (short)p->u.d; break;
  132. default:
  133. _cmDataErrNo = kCvtErrDtRC;
  134. }
  135. return v;
  136. }
  137. unsigned short cmDataGetUShort( const cmData_t* p )
  138. {
  139. unsigned short v = kInvalidUShort;
  140. switch( p->tid )
  141. {
  142. case kUCharDtId: v = (unsigned short)p->u.uc; break;
  143. case kCharDtId: v = (unsigned short)p->u.c; break;
  144. case kUShortDtId: v = p->u.us; break;
  145. case kShortDtId: v = (unsigned short)p->u.s; break;
  146. case kUIntDtId: v = (unsigned short)p->u.ui; break;
  147. case kIntDtId: v = (unsigned short)p->u.i; break;
  148. case kULongDtId: v = (unsigned short)p->u.ul; break;
  149. case kLongDtId: v = (unsigned short)p->u.l; break;
  150. case kFloatDtId: v = (unsigned short)p->u.f; break;
  151. case kDoubleDtId: v = (unsigned short)p->u.d; break;
  152. default:
  153. _cmDataErrNo = kCvtErrDtRC;
  154. }
  155. return v;
  156. }
  157. int cmDataGetInt( const cmData_t* p )
  158. {
  159. int v = kInvalidInt;
  160. switch( p->tid )
  161. {
  162. case kUCharDtId: v = (int)p->u.uc; break;
  163. case kCharDtId: v = (int)p->u.c; break;
  164. case kUShortDtId: v = (int)p->u.us; break;
  165. case kShortDtId: v = (int)p->u.s; break;
  166. case kUIntDtId: v = (int)p->u.ui; break;
  167. case kIntDtId: v = p->u.i; break;
  168. case kULongDtId: v = (int)p->u.ul; break;
  169. case kLongDtId: v = (int)p->u.l; break;
  170. case kFloatDtId: v = (int)p->u.f; break;
  171. case kDoubleDtId: v = (int)p->u.d; break;
  172. default:
  173. _cmDataErrNo = kCvtErrDtRC;
  174. }
  175. return v;
  176. }
  177. unsigned int cmDataGetUInt( const cmData_t* p )
  178. {
  179. unsigned int v = kInvalidUInt;
  180. switch( p->tid )
  181. {
  182. case kUCharDtId: v = (unsigned int)p->u.uc; break;
  183. case kCharDtId: v = (unsigned int)p->u.c; break;
  184. case kUShortDtId: v = (unsigned int)p->u.us; break;
  185. case kShortDtId: v = (unsigned int)p->u.s; break;
  186. case kUIntDtId: v = p->u.ui; break;
  187. case kIntDtId: v = (unsigned int)p->u.i; break;
  188. case kULongDtId: v = (unsigned int)p->u.ul; break;
  189. case kLongDtId: v = (unsigned int)p->u.l; break;
  190. case kFloatDtId: v = (unsigned int)p->u.f; break;
  191. case kDoubleDtId: v = (unsigned int)p->u.d; break;
  192. default:
  193. _cmDataErrNo = kCvtErrDtRC;
  194. }
  195. return v;
  196. }
  197. long cmDataGetLong( const cmData_t* p )
  198. {
  199. long v = kInvalidLong;
  200. switch( p->tid )
  201. {
  202. case kUCharDtId: v = (long)p->u.uc; break;
  203. case kCharDtId: v = (long)p->u.c; break;
  204. case kUShortDtId: v = (long)p->u.us; break;
  205. case kShortDtId: v = (long)p->u.s; break;
  206. case kUIntDtId: v = (long)p->u.ui; break;
  207. case kIntDtId: v = (long)p->u.i; break;
  208. case kULongDtId: v = (long)p->u.ul; break;
  209. case kLongDtId: v = p->u.l; break;
  210. case kFloatDtId: v = (long)p->u.f; break;
  211. case kDoubleDtId: v = (long)p->u.d; break;
  212. default:
  213. _cmDataErrNo = kCvtErrDtRC;
  214. }
  215. return v;
  216. }
  217. unsigned long cmDataGetULong( const cmData_t* p )
  218. {
  219. unsigned long v = kInvalidULong;
  220. switch( p->tid )
  221. {
  222. case kUCharDtId: v = (unsigned long)p->u.uc; break;
  223. case kCharDtId: v = (unsigned long)p->u.c; break;
  224. case kUShortDtId: v = (unsigned long)p->u.us; break;
  225. case kShortDtId: v = (unsigned long)p->u.s; break;
  226. case kUIntDtId: v = (unsigned long)p->u.ui; break;
  227. case kIntDtId: v = (unsigned long)p->u.i; break;
  228. case kULongDtId: v = p->u.ul; break;
  229. case kLongDtId: v = (unsigned long)p->u.l; break;
  230. case kFloatDtId: v = (unsigned long)p->u.f; break;
  231. case kDoubleDtId: v = (unsigned long)p->u.d; break;
  232. default:
  233. _cmDataErrNo = kCvtErrDtRC;
  234. }
  235. return v;
  236. }
  237. float cmDataGetFloat( const cmData_t* p )
  238. {
  239. float v = kInvalidChar;
  240. switch( p->tid )
  241. {
  242. case kUCharDtId: v = (float)p->u.uc; break;
  243. case kCharDtId: v = (float)p->u.c; break;
  244. case kUShortDtId: v = (float)p->u.us; break;
  245. case kShortDtId: v = (float)p->u.s; break;
  246. case kUIntDtId: v = (float)p->u.ui; break;
  247. case kIntDtId: v = (float)p->u.i; break;
  248. case kULongDtId: v = (float)p->u.ul; break;
  249. case kLongDtId: v = (float)p->u.l; break;
  250. case kFloatDtId: v = p->u.f; break;
  251. case kDoubleDtId: v = (float)p->u.d; break;
  252. default:
  253. _cmDataErrNo = kCvtErrDtRC;
  254. }
  255. return v;
  256. }
  257. double cmDataGetDouble( const cmData_t* p )
  258. {
  259. double v = kInvalidChar;
  260. switch( p->tid )
  261. {
  262. case kUCharDtId: v = (double)p->u.uc; break;
  263. case kCharDtId: v = (double)p->u.c; break;
  264. case kUShortDtId: v = (double)p->u.us; break;
  265. case kShortDtId: v = (double)p->u.s; break;
  266. case kUIntDtId: v = (double)p->u.ui; break;
  267. case kIntDtId: v = (double)p->u.i; break;
  268. case kULongDtId: v = (double)p->u.ul; break;
  269. case kLongDtId: v = (double)p->u.l; break;
  270. case kFloatDtId: v = (double)p->u.f; break;
  271. case kDoubleDtId: v = p->u.d; break;
  272. default:
  273. _cmDataErrNo = kCvtErrDtRC;
  274. }
  275. return v;
  276. }
  277. cmChar_t* cmDataGetStr( const cmData_t* p )
  278. {
  279. assert( p->tid == kStrDtId || p->tid == kConstStrDtId);
  280. return (p->tid == kStrDtId || p->tid == kConstStrDtId) ? p->u.z : NULL;
  281. }
  282. const cmChar_t* cmDataGetConstStr( const cmData_t* p )
  283. {
  284. assert( p->tid == kStrDtId || p->tid == kConstStrDtId);
  285. return (p->tid == kStrDtId || p->tid == kConstStrDtId) ? p->u.cz : NULL;
  286. }
  287. void* cmDataGetVoidPtr( const cmData_t* p )
  288. { return cmDataVoidPtr(p); }
  289. void* cmDataGetVoidPtr( const cmData_t* p )
  290. {
  291. assert( kMinPtrDtId <= p->tid && p->tid <= kMaxPtrDtId );
  292. return ( kMinPtrDtId <= p->tid && p->tid <= kMaxPtrDtId ) ? p->u.vp : NULL;
  293. }
  294. char* cmDataGetCharPtr( const cmData_t* p )
  295. {
  296. assert( p->tid == kCharPtrDtId || p->tid == kUCharPtrDtId );
  297. return (p->tid == kCharPtrDtId || p->tid == kUCharPtrDtId) ? p->u.cp : NULL;
  298. }
  299. unsigned char* cmDataGetUCharPtr( const cmData_t* p )
  300. {
  301. assert( p->tid == kCharPtrDtId || p->tid == kUCharPtrDtId );
  302. return (p->tid == kCharPtrDtId || p->tid == kUCharPtrDtId) ? p->u.ucp : NULL;
  303. }
  304. short* cmDataGetShortPtr( const cmData_t* p )
  305. {
  306. assert( p->tid == kShortPtrDtId || p->tid == kUShortPtrDtId );
  307. return (p->tid == kShortPtrDtId || p->tid == kUShortPtrDtId ) ? p->u.sp : NULL;
  308. }
  309. unsigned short* cmDataGetUShortPtr( const cmData_t* p )
  310. {
  311. assert( p->tid == kShortPtrDtId || p->tid == kUShortPtrDtId );
  312. return (p->tid == kShortPtrDtId || p->tid == kUShortPtrDtId ) ? p->u.usp : NULL;
  313. }
  314. int* cmDataGetIntPtr( const cmData_t* p )
  315. {
  316. assert( p->tid == kIntPtrDtId || p->tid == kUIntPtrDtId );
  317. return (p->tid == kIntPtrDtId || p->tid == kUIntPtrDtId ) ? p->u.ip : NULL;
  318. }
  319. unsigned int* cmDataGetUIntPtr( const cmData_t* p )
  320. {
  321. assert( p->tid == kIntPtrDtId || p->tid == kUIntPtrDtId );
  322. return (p->tid == kIntPtrDtId || p->tid == kUIntPtrDtId ) ? p->u.uip : NULL;
  323. }
  324. long* cmDataGetLongPtr( const cmData_t* p )
  325. {
  326. assert( p->tid == kLongPtrDtId || p->tid == kULongPtrDtId );
  327. return (p->tid == kLongPtrDtId || p->tid == kULongPtrDtId ) ? p->u.lp : NULL;
  328. }
  329. unsigned long* cmDataGetULongPtr( const cmData_t* p )
  330. {
  331. assert( p->tid == kLongPtrDtId || p->tid == kULongPtrDtId );
  332. return (p->tid == kLongPtrDtId || p->tid == kULongPtrDtId ) ? p->u.ulp : NULL;
  333. }
  334. float* cmDataGetFloatPtr( const cmData_t* p )
  335. { return p->tid == kFloatPtrDtId ? p->u.fp : NULL; }
  336. double* cmDataGetDoublePtr( const cmData_t* p )
  337. { return p->tid == kDoublePtrDtId ? p->u.dp : NULL; }
  338. // Set the value of an existing data object.
  339. void cmDataSetChar( cmData_t* p, char v )
  340. {
  341. _cmDataFreeArray(p);
  342. p->tid = kCharDtId;
  343. p->u.c = v;
  344. }
  345. void cmDataSetUChar( cmData_t* p, unsigned char v )
  346. {
  347. _cmDataFreeArray(p);
  348. p->tid = kUCharDtId;
  349. p->u.uc = v;
  350. }
  351. void cmDataSetShort( cmData_t* p, short v )
  352. {
  353. _cmDataFreeArray(p);
  354. p->tid = kShortDtId;
  355. p->u.s = v;
  356. }
  357. void cmDataSetUShort( cmData_t* p, unsigned short v )
  358. {
  359. _cmDataFreeArray(p);
  360. p->tid = kUShortDtId;
  361. p->u.us = v;
  362. }
  363. void cmDataSetInt( cmData_t* p, int v )
  364. {
  365. _cmDataFreeArray(p);
  366. p->tid = kCharDtId;
  367. p->u.c = v;
  368. }
  369. void cmDataSetUInt( cmData_t* p, unsigned int v )
  370. {
  371. _cmDataFreeArray(p);
  372. p->tid = kUIntDtId;
  373. p->u.ui = v;
  374. }
  375. void cmDataSetLong( cmData_t* p, long v )
  376. {
  377. _cmDataFreeArray(p);
  378. p->tid = kLongDtId;
  379. p->u.l = v;
  380. }
  381. void cmDataSetULong( cmData_t* p, unsigned long v )
  382. {
  383. _cmDataFreeArray(p);
  384. p->tid = kULongDtId;
  385. p->u.ul = v;
  386. }
  387. void cmDataSetFloat( cmData_t* p, float v )
  388. {
  389. _cmDataFreeArray(p);
  390. p->tid = kFloatDtId;
  391. p->u.f = v;
  392. }
  393. void cmDataSetDouble( cmData_t* p, double v )
  394. {
  395. _cmDataFreeArray(p);
  396. p->tid = kDoubleDtId;
  397. p->u.d = v;
  398. }
  399. void cmDataSetStr( cmData_t* p, cmChar_t* s )
  400. {
  401. _cmDataFreeArray(p);
  402. p->tid = kStrDtId;
  403. p->u.z = s;
  404. }
  405. void cmDataSetConstStr( cmData_t* p, const cmChar_t* s )
  406. {
  407. _cmDataFreeArray(p);
  408. p->tid = kConstStrDtId;
  409. p->u.cz = s;
  410. }
  411. // Set the value of an existing data object to an external array.
  412. // The array is not copied.
  413. void cmDataSetVoidPtr( cmData_t* p, void* vp, unsigned cnt )
  414. {
  415. cmDataSetCharPtr(p,(char*),cnt);
  416. }
  417. void cmDataSetCharPtr( cmData_t* p, char* vp, unsigned cnt )
  418. {
  419. _cmDataFreeArray(p);
  420. p->tid = kCharPtrDtId;
  421. p->u.cp = vp;
  422. p->cnt = cnt;
  423. }
  424. void cmDataSetUCharPtr( cmData_t* p, unsigned char* vp, unsigned cnt )
  425. {
  426. _cmDataFreeArray(p);
  427. p->tid = kUCharPtrDtId;
  428. p->u.ucp = vp;
  429. p->cnt = cnt;
  430. }
  431. void cmDataSetShortPtr( cmData_t* p, short* vp, unsigned cnt )
  432. {
  433. _cmDataFreeArray(p);
  434. p->tid = kShortPtrDtId;
  435. p->u.sp = vp;
  436. p->cnt = cnt;
  437. }
  438. void cmDataSetUShortPtr( cmData_t* p, unsigned short* vp, unsigned cnt )
  439. {
  440. _cmDataFreeArray(p);
  441. p->tid = kUShortPtrDtId;
  442. p->u.usp = vp;
  443. p->cnt = cnt;
  444. }
  445. void cmDataSetIntPtr( cmData_t* p, int* vp, unsigned cnt )
  446. {
  447. _cmDataFreeArray(p);
  448. p->tid = kCharPtrDtId;
  449. p->u.cp = vp;
  450. p->cnt = cnt;
  451. }
  452. void cmDataSetUIntPtr( cmData_t* p, unsigned int* vp, unsigned cnt )
  453. {
  454. _cmDataFreeArray(p);
  455. p->tid = kUIntPtrDtId;
  456. p->u.uip = vp;
  457. p->cnt = cnt;
  458. }
  459. void cmDataSetLongPtr( cmData_t* p, long* vp, unsigned cnt )
  460. {
  461. _cmDataFreeArray(p);
  462. p->tid = kLongPtrDtId;
  463. p->u.lp = vp;
  464. p->cnt = cnt;
  465. }
  466. void cmDataSetULongPtr( cmData_t* p, unsigned long* vp, unsigned cnt )
  467. {
  468. _cmDataFreeArray(p);
  469. p->tid = kULongPtrDtId;
  470. p->u.ulp = vp;
  471. p->cnt = cnt;
  472. }
  473. void cmDataSetFloatPtr( cmData_t* p, float* vp, unsigned cnt )
  474. {
  475. _cmDataFreeArray(p);
  476. p->tid = kFloatPtrDtId;
  477. p->u.fp = vp;
  478. p->cnt = cnt;
  479. }
  480. void cmDataSetDoublePtr( cmData_t* p, double* vp, unsigned cnt )
  481. {
  482. _cmDataFreeArray(p);
  483. p->tid = kDoublePtrDtId;
  484. p->u.dp = vp;
  485. p->cnt = cnt;
  486. }
  487. // Set the value of an existing array based data object.
  488. // Allocate the internal array and copy the array into it.
  489. void cmDataSetStrAlloc( cmData_t* p, const cmChar_t* s )
  490. {
  491. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  492. cmMemResizeStr(p->u.z,s);
  493. else
  494. {
  495. _cmDataFreeArray(p);
  496. cmMemAllocStr(p->u.z,s);
  497. }
  498. p->tid = kStrDtId;
  499. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  500. }
  501. void cmDataSetConstStrAlloc( cmData_t* p, const cmChar_t* s )
  502. { cmDataSetStrAlloc(p,s); }
  503. void cmDataSetVoidAllocPtr( cmData_t* p, const void* vp, unsigned cnt )
  504. { cmDataSetCharAllocPtr(p,(char*)vp,cnt); }
  505. void cmDataSetCharAllocPtr( cmData_t* p, const char* vp, unsigned cnt )
  506. {
  507. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  508. cmMemResize(char, p->u.ucp, cnt );
  509. else
  510. {
  511. _cmDataFreeArray(p);
  512. p->u.ucp = cmMemAlloc(char, cnt );
  513. }
  514. p->tid = kCharPtrDtId;
  515. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  516. }
  517. void cmDataSetUCharAllocPtr( cmData_t* p, const unsigned char* vp, unsigned cnt )
  518. {
  519. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  520. cmMemResize(unsigned char, p->u.ucp, cnt );
  521. else
  522. {
  523. _cmDataFreeArray(p);
  524. p->u.ucp = cmMemAlloc(unsigned char, cnt );
  525. }
  526. p->tid = kUCharPtrDtId;
  527. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  528. }
  529. void cmDataSetShortAllocPtr( cmData_t* p, const short* vp, unsigned cnt )
  530. {
  531. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  532. cmMemResize(short, p->u.ucp, cnt );
  533. else
  534. {
  535. _cmDataFreeArray(p);
  536. p->u.ucp = cmMemAlloc(short, cnt );
  537. }
  538. p->tid = kShortPtrDtId;
  539. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  540. }
  541. void cmDataSetUShortAllocPtr( cmData_t* p, const unsigned short* vp, unsigned cnt )
  542. {
  543. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  544. cmMemResize(unsigned short, p->u.ucp, cnt );
  545. else
  546. {
  547. _cmDataFreeArray(p);
  548. p->u.ucp = cmMemAlloc(unsigned short, cnt );
  549. }
  550. p->tid = kUShortPtrDtId;
  551. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  552. }
  553. void cmDataSetIntAllocPtr( cmData_t* p, const int* vp, unsigned cnt )
  554. {
  555. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  556. cmMemResize(int, p->u.ucp, cnt );
  557. else
  558. {
  559. _cmDataFreeArray(p);
  560. p->u.ucp = cmMemAlloc(int, cnt );
  561. }
  562. p->tid = kIntPtrDtId;
  563. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  564. }
  565. void cmDataSetUIntAllocPtr( cmData_t* p, const unsigned int* vp, unsigned cnt )
  566. {
  567. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  568. cmMemResize(unsigned int, p->u.ucp, cnt );
  569. else
  570. {
  571. _cmDataFreeArray(p);
  572. p->u.ucp = cmMemAlloc(unsigned int, cnt );
  573. }
  574. p->tid = kUIntPtrDtId;
  575. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  576. }
  577. void cmDataSetLongAllocPtr( cmData_t* p, const long* vp, unsigned cnt )
  578. {
  579. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  580. cmMemResize(long, p->u.ucp, cnt );
  581. else
  582. {
  583. _cmDataFreeArray(p);
  584. p->u.ucp = cmMemAlloc(long, cnt );
  585. }
  586. p->tid = kLongPtrDtId;
  587. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  588. }
  589. void cmDataSetULongAllocPtr( cmData_t* p, const unsigned long* vp, unsigned cnt )
  590. {
  591. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  592. cmMemResize(unsigned long, p->u.ucp, cnt );
  593. else
  594. {
  595. _cmDataFreeArray(p);
  596. p->u.ucp = cmMemAlloc(unsigned long, cnt );
  597. }
  598. p->tid = kULongPtrDtId;
  599. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  600. }
  601. void cmDataSetFloatAllocPtr( cmData_t* p, const float* vp, unsigned cnt )
  602. {
  603. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  604. cmMemResize(float, p->u.ucp, cnt );
  605. else
  606. {
  607. _cmDataFreeArray(p);
  608. p->u.ucp = cmMemAlloc(float, cnt );
  609. }
  610. p->tid = kFloatPtrDtId;
  611. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  612. }
  613. void cmDataSetDoubleAllocPtr( cmData_t* p, const double* vp, unsigned cnt )
  614. {
  615. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  616. cmMemResize(double, p->u.ucp, cnt );
  617. else
  618. {
  619. _cmDataFreeArray(p);
  620. p->u.ucp = cmMemAlloc(double, cnt );
  621. }
  622. p->tid = kDoublePtrDtId;
  623. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  624. }
  625. // Dynamically allocate a data object and set it's value.
  626. cmData_t* cmDataAllocChar( char v )
  627. {
  628. cmData_t* p = cmMemAllocZ(cmData_t,1);
  629. cmDataSetChar(p,v);
  630. return p;
  631. }
  632. cmData_t* cmDataAllocUChar( unsigned char v )
  633. {
  634. cmData_t* p = cmMemAllocZ(cmData_t,1);
  635. cmDataSetUChar(p,v);
  636. return p;
  637. }
  638. cmData_t* cmDataAllocShort( short v )
  639. {
  640. cmData_t* p = cmMemAllocZ(cmData_t,1);
  641. cmDataSetShort(p,v);
  642. return p;
  643. }
  644. cmData_t* cmDataAllocUShort( unsigned short v )
  645. {
  646. cmData_t* p = cmMemAllocZ(cmData_t,1);
  647. cmDataSetUShort(p,v);
  648. return p;
  649. }
  650. cmData_t* cmDataAllocInt( int v )
  651. {
  652. cmData_t* p = cmMemAllocZ(cmData_t,1);
  653. cmDataSetInt(p,v);
  654. return p;
  655. }
  656. cmData_t* cmDataAllocUInt( unsigned int v )
  657. {
  658. cmData_t* p = cmMemAllocZ(cmData_t,1);
  659. cmDataSetUInt(p,v);
  660. return p;
  661. }
  662. cmData_t* cmDataAllocLong( long v )
  663. {
  664. cmData_t* p = cmMemAllocZ(cmData_t,1);
  665. cmDataSetLong(p,v);
  666. return p;
  667. }
  668. cmData_t* cmDataAllocULong( unsigned long v )
  669. {
  670. cmData_t* p = cmMemAllocZ(cmData_t,1);
  671. cmDataSetULong(p,v);
  672. return p;
  673. }
  674. cmData_t* cmDataAllocFloat( float v )
  675. {
  676. cmData_t* p = cmMemAllocZ(cmData_t,1);
  677. cmDataSetFloat(p,v);
  678. return p;
  679. }
  680. cmData_t* cmDataAllocDouble( double v )
  681. {
  682. cmData_t* p = cmMemAllocZ(cmData_t,1);
  683. cmDataSetDouble(p,v);
  684. return p;
  685. }
  686. cmData_t* cmDataAllocStr( cmChar_t* str )
  687. {
  688. cmData_t* p = cmMemAllocZ(cmData_t,1);
  689. cmDataSetStr(p,v);
  690. return p;
  691. }
  692. cmData_t* cmDataAllocConstStr( const cmChar_t* str )
  693. {
  694. cmData_t* p = cmMemAllocZ(cmData_t,1);
  695. cmDataSetConstStr(p,v);
  696. return p;
  697. }
  698. // Dynamically allocate a data object and set its array value to an external
  699. // array. The data is not copied.
  700. cmData_t* cmDataAllocVoidPtr( const void* v, unsigned cnt );
  701. {
  702. cmData_t* p = cmMemAllocZ(cmData_t,1);
  703. cmDataSetCharPtr(p,(const char*)v,cnt);
  704. return p;
  705. }
  706. cmData_t* cmDataAllocCharPtr( const char* v, unsigned cnt )
  707. {
  708. cmData_t* p = cmMemAllocZ(cmData_t,1);
  709. cmDataSetCharPtr(p,v,cnt);
  710. return p;
  711. }
  712. cmData_t* cmDataAllocUCharPtr( const unsigned char* v, unsigned cnt )
  713. {
  714. cmData_t* p = cmMemAllocZ(cmData_t,1);
  715. cmDataSetUCharPtr(p,v,cnt);
  716. return p;
  717. }
  718. cmData_t* cmDataAllocShortPtr( const short* v, unsigned cnt )
  719. {
  720. cmData_t* p = cmMemAllocZ(cmData_t,1);
  721. cmDataSetShortPtr(p,v,cnt);
  722. return p;
  723. }
  724. cmData_t* cmDataAllocUShortPtr( const unsigned short* v, unsigned cnt )
  725. {
  726. cmData_t* p = cmMemAllocZ(cmData_t,1);
  727. cmDataSetUShortPtr(p,v,cnt);
  728. return p;
  729. }
  730. cmData_t* cmDataAllocIntPtr( const int* v, unsigned cnt )
  731. {
  732. cmData_t* p = cmMemAllocZ(cmData_t,1);
  733. cmDataSetIntPtr(p,v,cnt);
  734. return p;
  735. }
  736. cmData_t* cmDataAllocUIntPtr( const unsigned int* v, unsigned cnt )
  737. {
  738. cmData_t* p = cmMemAllocZ(cmData_t,1);
  739. cmDataSetUIntPtr(p,v,cnt);
  740. return p;
  741. }
  742. cmData_t* cmDataAllocLongPtr( const long* v, unsigned cnt )
  743. {
  744. cmData_t* p = cmMemAllocZ(cmData_t,1);
  745. cmDataSetLongPtr(p,v,cnt);
  746. return p;
  747. }
  748. cmData_t* cmDataAllocULongPtr( const unsigned long* v, unsigned cnt )
  749. {
  750. cmData_t* p = cmMemAllocZ(cmData_t,1);
  751. cmDataSetULongPtr(p,v,cnt);
  752. return p;
  753. }
  754. cmData_t* cmDataAllocFloatPtr( const float* v, unsigned cnt )
  755. {
  756. cmData_t* p = cmMemAllocZ(cmData_t,1);
  757. cmDataSetFloatPtr(p,v,cnt);
  758. return p;
  759. }
  760. cmData_t* cmDataAllocDoublePtr( const double* v, unsigned cnt )
  761. {
  762. cmData_t* p = cmMemAllocZ(cmData_t,1);
  763. cmDataSetDoublePtr(p,v,cnt);
  764. return p;
  765. }
  766. // Dynamically allocate a data object and its array value.
  767. // v[cnt] is copied into the allocated array.
  768. cmData_t* cmDataVoidAllocPtr( const void* v, unsigned cnt )
  769. {
  770. cmData_t* p = cmMemAllocZ(cmData_t,1);
  771. cmDataSetCharAllocPtr(p, (const char*)v, cnt );
  772. return p;
  773. }
  774. cmData_t* cmDataCharAllocPtr( const char* v, unsigned cnt )
  775. {
  776. cmData_t* p = cmMemAllocZ(cmData_t,1);
  777. cmDataSetCharAllocPtr(p, v, cnt );
  778. return p;
  779. }
  780. cmData_t* cmDataUCharAllocPtr( const unsigned char* v, unsigned cnt )
  781. {
  782. cmData_t* p = cmMemAllocZ(cmData_t,1);
  783. cmDataSetUCharAllocPtr(p, v, cnt );
  784. return p;
  785. }
  786. cmData_t* cmDataShortAllocPtr( const short* v, unsigned cnt )
  787. {
  788. cmData_t* p = cmMemAllocZ(cmData_t,1);
  789. cmDataSetShortAllocPtr(p, v, cnt );
  790. return p;
  791. }
  792. cmData_t* cmDataUShortAllocPtr( const unsigned short* v, unsigned cnt )
  793. {
  794. cmData_t* p = cmMemAllocZ(cmData_t,1);
  795. cmDataSetUShortAllocPtr(p, v, cnt );
  796. return p;
  797. }
  798. cmData_t* cmDataIntAllocPtr( const int* v, unsigned cnt )
  799. {
  800. cmData_t* p = cmMemAllocZ(cmData_t,1);
  801. cmDataSetIntAllocPtr(p, v, cnt );
  802. return p;
  803. }
  804. cmData_t* cmDataUIntAllocPtr( const unsigned int* v, unsigned cnt )
  805. {
  806. cmData_t* p = cmMemAllocZ(cmData_t,1);
  807. cmDataSetUIntAllocPtr(p, v, cnt );
  808. return p;
  809. }
  810. cmData_t* cmDataLongAllocPtr( const long* v, unsigned cnt )
  811. {
  812. cmData_t* p = cmMemAllocZ(cmData_t,1);
  813. cmDataSetLongAllocPtr(p, v, cnt );
  814. return p;
  815. }
  816. cmData_t* cmDataULongAllocPtr( const unsigned long* v, unsigned cnt )
  817. {
  818. cmData_t* p = cmMemAllocZ(cmData_t,1);
  819. cmDataSetULongAllocPtr(p, v, cnt );
  820. return p;
  821. }
  822. cmData_t* cmDataFloatAllocPtr( const float* v, unsigned cnt )
  823. {
  824. cmData_t* p = cmMemAllocZ(cmData_t,1);
  825. cmDataSetFloatAllocPtr(p, v, cnt );
  826. return p;
  827. }
  828. cmData_t* cmDataDoubleAllocPtr( const double* v, unsigned cnt )
  829. {
  830. cmData_t* p = cmMemAllocZ(cmData_t,1);
  831. cmDataSetDoubleAllocPtr(p, v, cnt );
  832. return p;
  833. }
  834. void cmDataFree( cmData_t* p )
  835. {
  836. _cmDataFree(p);
  837. }
  838. unsigned cmDataSerializeByteCount( const cmData_t* p )
  839. {
  840. unsigned bn = 0;
  841. // if this data type has a child then calculate it's size
  842. if( kMinStructDtId <= p->tid && p->tid <= kMaxStructDtId && p->u.child != NULL )
  843. bn = cmDataSerializeByteCount(p->child);
  844. // if this data type has siblings get their type
  845. cmData_t* dp = p->u.child;
  846. for(; dp != NULL; dp=dp->sibling )
  847. bn += cmDataSerializeByteCount(dp->sibling);
  848. //
  849. return _cmDataByteCount(p) + bn;
  850. }
  851. typedef struct
  852. {
  853. cmDataFmtId_t tid;
  854. unsigned cnt;
  855. } cmDataSerialHdr_t;
  856. cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt )
  857. {
  858. }
  859. cmDtRC_t cmDataDeserialize( const void* buf, unsigned bufByteCnt, cmData_t** pp )
  860. {
  861. }
  862. void cmDataPrint( const cmData_t* p, cmRpt_t* rpt )
  863. {
  864. }
  865. void cmDataTest( cmCtx_t* ctx )
  866. {
  867. }