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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188
  1. #include "cmGlobal.h"
  2. #include "cmRpt.h"
  3. #include "cmErr.h"
  4. #include "cmCtx.h"
  5. #include "cmMem.h"
  6. #include "cmMallocDebug.h"
  7. #include "cmData.h"
  8. cmDtRC_t _cmDataErrNo = kOkDtRC;
  9. cmData_t cmDataNull = { kInvalidDtId,0,NULL,NULL,0 };
  10. typedef struct
  11. {
  12. cmDataFmtId_t tid;
  13. unsigned cnt;
  14. } cmDataSerialHdr_t;
  15. cmDtRC_t _cmDataSetError( unsigned err )
  16. {
  17. _cmDataErrNo = err;
  18. return err;
  19. }
  20. void _cmDataFreeArray( cmData_t* p )
  21. {
  22. if(cmIsFlag(p->flags,kDynPtrDtFl))
  23. {
  24. cmMemFree(p->u.vp);
  25. p->u.vp = NULL;
  26. p->flags = cmClrFlag(p->flags,kDynPtrDtFl);
  27. }
  28. p->tid = kInvalidDtId;
  29. p->cnt = 0;
  30. }
  31. void _cmDataFree( cmData_t* p )
  32. {
  33. if( cmDataIsStruct(p) )
  34. {
  35. cmData_t* cp = p->u.child;
  36. for(; cp!=NULL; cp=cp->sibling)
  37. _cmDataFree(cp);
  38. }
  39. _cmDataFreeArray(p);
  40. if( cmIsFlag(p->flags,kDynObjDtFl) )
  41. cmMemFree(p);
  42. }
  43. cmData_t* _cmDataAllocNode( cmData_t* parent, cmDataFmtId_t tid )
  44. {
  45. cmData_t* p = cmMemAllocZ(cmData_t,1);
  46. p->tid = tid;
  47. p->flags = kDynObjDtFl;
  48. p->parent = parent;
  49. if( parent != NULL )
  50. return cmDataAppendChild(parent,p);
  51. return p;
  52. }
  53. unsigned _cmDataByteCount( const cmData_t* p )
  54. {
  55. unsigned n = sizeof(cmDataSerialHdr_t);
  56. switch( p->tid )
  57. {
  58. case kInvalidDtId: return 0;
  59. case kNullDtId: return n;
  60. case kUCharDtId: return n + sizeof(unsigned char);
  61. case kCharDtId: return n + sizeof(char);
  62. case kUShortDtId: return n + sizeof(unsigned short);
  63. case kShortDtId: return n + sizeof(short);
  64. case kUIntDtId: return n + sizeof(unsigned int);
  65. case kIntDtId: return n + sizeof(int);
  66. case kULongDtId: return n + sizeof(unsigned long);
  67. case kLongDtId: return n + sizeof(long);
  68. case kFloatDtId: return n + sizeof(float);
  69. case kDoubleDtId: return n + sizeof(double);
  70. case kStrDtId: return n + (p->u.z ==NULL ? 0 : strlen(p->u.z) + 1);
  71. case kConstStrDtId: return n + (p->u.cz==NULL ? 0 : strlen(p->u.cz) + 1);
  72. case kUCharPtrDtId: return n + p->cnt * sizeof(unsigned char);
  73. case kCharPtrDtId: return n + p->cnt * sizeof(char);
  74. case kUShortPtrDtId: return n + p->cnt * sizeof(unsigned short);
  75. case kShortPtrDtId: return n + p->cnt * sizeof(short);
  76. case kUIntPtrDtId: return n + p->cnt * sizeof(unsigned int);
  77. case kIntPtrDtId: return n + p->cnt * sizeof(int);
  78. case kULongPtrDtId: return n + p->cnt * sizeof(unsigned long);
  79. case kLongPtrDtId: return n + p->cnt * sizeof(long);
  80. case kFloatPtrDtId: return n + p->cnt * sizeof(float);
  81. case kDoublePtrDtId: return n + p->cnt * sizeof(double);
  82. case kVoidPtrDtId: return n + p->cnt * sizeof(char);
  83. default:
  84. return n;
  85. }
  86. assert(0);
  87. return 0;
  88. }
  89. bool cmDataIsValue( const cmData_t* p )
  90. { return kMinValDtId <= p->tid && p->tid <= kMaxValDtId; }
  91. bool cmDataIsPtr( const cmData_t* p )
  92. { return kMinPtrDtId <= p->tid && p->tid <= kMaxPtrDtId; }
  93. bool cmDataIsStruct( const cmData_t* p )
  94. { return kMinStructDtId <= p->tid && p->tid <= kMaxStructDtId; }
  95. char cmDataChar( const cmData_t* p ) { assert(p->tid==kCharDtId); return p->u.c; }
  96. unsigned char cmDataUChar( const cmData_t* p ) { assert(p->tid==kUCharDtId); return p->u.uc; }
  97. short cmDataShort( const cmData_t* p ) { assert(p->tid==kShortDtId); return p->u.s; }
  98. unsigned short cmDataUShort( const cmData_t* p ) { assert(p->tid==kUShortDtId); return p->u.us; }
  99. int cmDataInt( const cmData_t* p ) { assert(p->tid==kIntDtId); return p->u.i; }
  100. unsigned int cmDataUInt( const cmData_t* p ) { assert(p->tid==kUIntDtId); return p->u.ui; }
  101. long cmDataLong( const cmData_t* p ) { assert(p->tid==kLongDtId); return p->u.l; }
  102. unsigned long cmDataULong( const cmData_t* p ) { assert(p->tid==kULongDtId); return p->u.ul; }
  103. float cmDataFloat( const cmData_t* p ) { assert(p->tid==kFloatDtId); return p->u.f; }
  104. double cmDataDouble( const cmData_t* p ) { assert(p->tid==kDoubleDtId); return p->u.d; }
  105. cmChar_t* cmDataStr( const cmData_t* p ) { assert(p->tid==kStrDtId); return p->u.z; }
  106. const cmChar_t* cmDataConstStr( const cmData_t* p ) { assert(p->tid==kConstStrDtId); return p->u.cz; }
  107. void* cmDataVoidPtr( const cmData_t* p ) { assert(p->tid==kVoidPtrDtId); return p->u.vp; }
  108. char* cmDataCharPtr( const cmData_t* p ) { assert(p->tid==kCharPtrDtId); return p->u.cp; }
  109. unsigned char* cmDataUCharPtr( const cmData_t* p ) { assert(p->tid==kUCharPtrDtId); return p->u.ucp; }
  110. short* cmDataShortPtr( const cmData_t* p ) { assert(p->tid==kShortPtrDtId); return p->u.sp; }
  111. unsigned short* cmDataUShortPtr( const cmData_t* p ) { assert(p->tid==kUShortPtrDtId); return p->u.usp; }
  112. int* cmDataIntPtr( const cmData_t* p ) { assert(p->tid==kIntPtrDtId); return p->u.ip; }
  113. unsigned int* cmDataUIntPtr( const cmData_t* p ) { assert(p->tid==kUIntPtrDtId); return p->u.uip; }
  114. long* cmDataLongPtr( const cmData_t* p ) { assert(p->tid==kLongPtrDtId); return p->u.lp; }
  115. unsigned long* cmDataULongPtr( const cmData_t* p ) { assert(p->tid==kULongPtrDtId); return p->u.ulp; }
  116. float* cmDataFloatPtr( const cmData_t* p ) { assert(p->tid==kFloatPtrDtId); return p->u.fp; }
  117. double* cmDataDoublePtr( const cmData_t* p ) { assert(p->tid==kDoublePtrDtId); return p->u.dp; }
  118. cmDtRC_t cmDataGetUChar( const cmData_t* p, unsigned char* vp )
  119. {
  120. switch( p->tid )
  121. {
  122. case kUCharDtId: *vp = p->u.uc; break;
  123. case kCharDtId: *vp = (unsigned char)p->u.c; break;
  124. case kUShortDtId: *vp = (unsigned char)p->u.us; break;
  125. case kShortDtId: *vp = (unsigned char)p->u.s; break;
  126. case kUIntDtId: *vp = (unsigned char)p->u.ui; break;
  127. case kIntDtId: *vp = (unsigned char)p->u.i; break;
  128. case kULongDtId: *vp = (unsigned char)p->u.ul; break;
  129. case kLongDtId: *vp = (unsigned char)p->u.l; break;
  130. case kFloatDtId: *vp = (unsigned char)p->u.f; break;
  131. case kDoubleDtId: *vp = (unsigned char)p->u.d; break;
  132. default:
  133. return _cmDataSetError(kCvtErrDtRC);
  134. }
  135. return kOkDtRC;
  136. }
  137. cmDtRC_t cmDataGetChar( const cmData_t* p, char* vp )
  138. {
  139. switch( p->tid )
  140. {
  141. case kUCharDtId: *vp = (char)p->u.uc; break;
  142. case kCharDtId: *vp = p->u.c; break;
  143. case kUShortDtId: *vp = (char)p->u.us; break;
  144. case kShortDtId: *vp = (char)p->u.s; break;
  145. case kUIntDtId: *vp = (char)p->u.ui; break;
  146. case kIntDtId: *vp = (char)p->u.i; break;
  147. case kULongDtId: *vp = (char)p->u.ul; break;
  148. case kLongDtId: *vp = (char)p->u.l; break;
  149. case kFloatDtId: *vp = (char)p->u.f; break;
  150. case kDoubleDtId: *vp = (char)p->u.d; break;
  151. default:
  152. return _cmDataSetError(kCvtErrDtRC);
  153. }
  154. return kOkDtRC;
  155. }
  156. cmDtRC_t cmDataGetShort( const cmData_t* p, short* vp )
  157. {
  158. switch( p->tid )
  159. {
  160. case kUCharDtId: *vp = (short)p->u.uc; break;
  161. case kCharDtId: *vp = (short)p->u.c; break;
  162. case kUShortDtId: *vp = (short)p->u.us; break;
  163. case kShortDtId: *vp = p->u.s; break;
  164. case kUIntDtId: *vp = (short)p->u.ui; break;
  165. case kIntDtId: *vp = (short)p->u.i; break;
  166. case kULongDtId: *vp = (short)p->u.ul; break;
  167. case kLongDtId: *vp = (short)p->u.l; break;
  168. case kFloatDtId: *vp = (short)p->u.f; break;
  169. case kDoubleDtId: *vp = (short)p->u.d; break;
  170. default:
  171. return _cmDataSetError(kCvtErrDtRC);
  172. }
  173. return kOkDtRC;
  174. }
  175. cmDtRC_t cmDataGetUShort( const cmData_t* p, unsigned short* vp )
  176. {
  177. switch( p->tid )
  178. {
  179. case kUCharDtId: *vp = (unsigned short)p->u.uc; break;
  180. case kCharDtId: *vp = (unsigned short)p->u.c; break;
  181. case kUShortDtId: *vp = p->u.us; break;
  182. case kShortDtId: *vp = (unsigned short)p->u.s; break;
  183. case kUIntDtId: *vp = (unsigned short)p->u.ui; break;
  184. case kIntDtId: *vp = (unsigned short)p->u.i; break;
  185. case kULongDtId: *vp = (unsigned short)p->u.ul; break;
  186. case kLongDtId: *vp = (unsigned short)p->u.l; break;
  187. case kFloatDtId: *vp = (unsigned short)p->u.f; break;
  188. case kDoubleDtId: *vp = (unsigned short)p->u.d; break;
  189. default:
  190. return _cmDataSetError(kCvtErrDtRC);
  191. }
  192. return kOkDtRC;
  193. }
  194. cmDtRC_t cmDataGetInt( const cmData_t* p, int* vp )
  195. {
  196. switch( p->tid )
  197. {
  198. case kUCharDtId: *vp = (int)p->u.uc; break;
  199. case kCharDtId: *vp = (int)p->u.c; break;
  200. case kUShortDtId: *vp = (int)p->u.us; break;
  201. case kShortDtId: *vp = (int)p->u.s; break;
  202. case kUIntDtId: *vp = (int)p->u.ui; break;
  203. case kIntDtId: *vp = p->u.i; break;
  204. case kULongDtId: *vp = (int)p->u.ul; break;
  205. case kLongDtId: *vp = (int)p->u.l; break;
  206. case kFloatDtId: *vp = (int)p->u.f; break;
  207. case kDoubleDtId: *vp = (int)p->u.d; break;
  208. default:
  209. return _cmDataSetError(kCvtErrDtRC);
  210. }
  211. return kOkDtRC;
  212. }
  213. cmDtRC_t cmDataGetUInt( const cmData_t* p, unsigned int* vp )
  214. {
  215. switch( p->tid )
  216. {
  217. case kUCharDtId: *vp = (unsigned int)p->u.uc; break;
  218. case kCharDtId: *vp = (unsigned int)p->u.c; break;
  219. case kUShortDtId: *vp = (unsigned int)p->u.us; break;
  220. case kShortDtId: *vp = (unsigned int)p->u.s; break;
  221. case kUIntDtId: *vp = p->u.ui; break;
  222. case kIntDtId: *vp = (unsigned int)p->u.i; break;
  223. case kULongDtId: *vp = (unsigned int)p->u.ul; break;
  224. case kLongDtId: *vp = (unsigned int)p->u.l; break;
  225. case kFloatDtId: *vp = (unsigned int)p->u.f; break;
  226. case kDoubleDtId: *vp = (unsigned int)p->u.d; break;
  227. default:
  228. return _cmDataSetError(kCvtErrDtRC);
  229. }
  230. return kOkDtRC;
  231. }
  232. cmDtRC_t cmDataGetLong( const cmData_t* p, long* vp )
  233. {
  234. switch( p->tid )
  235. {
  236. case kUCharDtId: *vp = (long)p->u.uc; break;
  237. case kCharDtId: *vp = (long)p->u.c; break;
  238. case kUShortDtId: *vp = (long)p->u.us; break;
  239. case kShortDtId: *vp = (long)p->u.s; break;
  240. case kUIntDtId: *vp = (long)p->u.ui; break;
  241. case kIntDtId: *vp = (long)p->u.i; break;
  242. case kULongDtId: *vp = (long)p->u.ul; break;
  243. case kLongDtId: *vp = p->u.l; break;
  244. case kFloatDtId: *vp = (long)p->u.f; break;
  245. case kDoubleDtId: *vp = (long)p->u.d; break;
  246. default:
  247. return _cmDataSetError(kCvtErrDtRC);
  248. }
  249. return kOkDtRC;
  250. }
  251. cmDtRC_t cmDataGetULong( const cmData_t* p, unsigned long* vp )
  252. {
  253. switch( p->tid )
  254. {
  255. case kUCharDtId: *vp = (unsigned long)p->u.uc; break;
  256. case kCharDtId: *vp = (unsigned long)p->u.c; break;
  257. case kUShortDtId: *vp = (unsigned long)p->u.us; break;
  258. case kShortDtId: *vp = (unsigned long)p->u.s; break;
  259. case kUIntDtId: *vp = (unsigned long)p->u.ui; break;
  260. case kIntDtId: *vp = (unsigned long)p->u.i; break;
  261. case kULongDtId: *vp = p->u.ul; break;
  262. case kLongDtId: *vp = (unsigned long)p->u.l; break;
  263. case kFloatDtId: *vp = (unsigned long)p->u.f; break;
  264. case kDoubleDtId: *vp = (unsigned long)p->u.d; break;
  265. default:
  266. return _cmDataSetError(kCvtErrDtRC);
  267. }
  268. return kOkDtRC;
  269. }
  270. cmDtRC_t cmDataGetFloat( const cmData_t* p, float* vp )
  271. {
  272. switch( p->tid )
  273. {
  274. case kUCharDtId: *vp = (float)p->u.uc; break;
  275. case kCharDtId: *vp = (float)p->u.c; break;
  276. case kUShortDtId: *vp = (float)p->u.us; break;
  277. case kShortDtId: *vp = (float)p->u.s; break;
  278. case kUIntDtId: *vp = (float)p->u.ui; break;
  279. case kIntDtId: *vp = (float)p->u.i; break;
  280. case kULongDtId: *vp = (float)p->u.ul; break;
  281. case kLongDtId: *vp = (float)p->u.l; break;
  282. case kFloatDtId: *vp = p->u.f; break;
  283. case kDoubleDtId: *vp = (float)p->u.d; break;
  284. default:
  285. return _cmDataSetError(kCvtErrDtRC);
  286. }
  287. return kOkDtRC;
  288. }
  289. cmDtRC_t cmDataGetDouble( const cmData_t* p, double* vp )
  290. {
  291. switch( p->tid )
  292. {
  293. case kUCharDtId: *vp = (double)p->u.uc; break;
  294. case kCharDtId: *vp = (double)p->u.c; break;
  295. case kUShortDtId: *vp = (double)p->u.us; break;
  296. case kShortDtId: *vp = (double)p->u.s; break;
  297. case kUIntDtId: *vp = (double)p->u.ui; break;
  298. case kIntDtId: *vp = (double)p->u.i; break;
  299. case kULongDtId: *vp = (double)p->u.ul; break;
  300. case kLongDtId: *vp = (double)p->u.l; break;
  301. case kFloatDtId: *vp = (double)p->u.f; break;
  302. case kDoubleDtId: *vp = p->u.d; break;
  303. default:
  304. return _cmDataSetError(kCvtErrDtRC);
  305. }
  306. return kOkDtRC;
  307. }
  308. cmDtRC_t cmDataGetStr( const cmData_t* p, cmChar_t** vp )
  309. {
  310. if( p->tid == kStrDtId || p->tid == kConstStrDtId)
  311. {
  312. *vp = (p->tid == kStrDtId || p->tid == kConstStrDtId) ? p->u.z : NULL;
  313. return kOkDtRC;
  314. }
  315. return _cmDataSetError(kCvtErrDtRC);
  316. }
  317. cmDtRC_t cmDataGetConstStr( const cmData_t* p, const cmChar_t** vp )
  318. {
  319. if( p->tid == kStrDtId || p->tid == kConstStrDtId)
  320. {
  321. *vp = (p->tid == kStrDtId || p->tid == kConstStrDtId) ? p->u.cz : NULL;
  322. return kOkDtRC;
  323. }
  324. return _cmDataSetError(kCvtErrDtRC);
  325. }
  326. cmDtRC_t cmDataGetVoidPtr( const cmData_t* p, void** vp )
  327. {
  328. if( kMinPtrDtId <= p->tid && p->tid <= kMaxPtrDtId )
  329. {
  330. *vp = ( kMinPtrDtId <= p->tid && p->tid <= kMaxPtrDtId ) ? p->u.vp : NULL;
  331. return kOkDtRC;
  332. }
  333. return _cmDataSetError(kCvtErrDtRC);
  334. }
  335. cmDtRC_t cmDataGetCharPtr( const cmData_t* p, char** vp )
  336. {
  337. if( p->tid == kCharPtrDtId || p->tid == kUCharPtrDtId )
  338. {
  339. *vp = (p->tid == kCharPtrDtId || p->tid == kUCharPtrDtId) ? p->u.cp : NULL;
  340. return kOkDtRC;
  341. }
  342. return _cmDataSetError(kCvtErrDtRC);
  343. }
  344. cmDtRC_t cmDataGetUCharPtr( const cmData_t* p, unsigned char** vp )
  345. {
  346. if( p->tid == kCharPtrDtId || p->tid == kUCharPtrDtId )
  347. {
  348. *vp = (p->tid == kCharPtrDtId || p->tid == kUCharPtrDtId) ? p->u.ucp : NULL;
  349. return kOkDtRC;
  350. }
  351. return _cmDataSetError(kCvtErrDtRC);
  352. }
  353. cmDtRC_t cmDataGetShortPtr( const cmData_t* p, short** vp )
  354. {
  355. if( p->tid == kShortPtrDtId || p->tid == kUShortPtrDtId )
  356. {
  357. *vp = (p->tid == kShortPtrDtId || p->tid == kUShortPtrDtId ) ? p->u.sp : NULL;
  358. return kOkDtRC;
  359. }
  360. return _cmDataSetError(kCvtErrDtRC);
  361. }
  362. cmDtRC_t cmDataGetUShortPtr( const cmData_t* p, unsigned short** vp )
  363. {
  364. if( p->tid == kShortPtrDtId || p->tid == kUShortPtrDtId )
  365. {
  366. *vp = (p->tid == kShortPtrDtId || p->tid == kUShortPtrDtId ) ? p->u.usp : NULL;
  367. return kOkDtRC;
  368. }
  369. return _cmDataSetError(kCvtErrDtRC);
  370. }
  371. cmDtRC_t cmDataGetIntPtr( const cmData_t* p, int** vp )
  372. {
  373. if( p->tid == kIntPtrDtId || p->tid == kUIntPtrDtId )
  374. {
  375. *vp = (p->tid == kIntPtrDtId || p->tid == kUIntPtrDtId ) ? p->u.ip : NULL;
  376. return kOkDtRC;
  377. }
  378. return _cmDataSetError(kCvtErrDtRC);
  379. }
  380. cmDtRC_t cmDataGetUIntPtr( const cmData_t* p, unsigned int** vp )
  381. {
  382. if( p->tid == kIntPtrDtId || p->tid == kUIntPtrDtId )
  383. {
  384. *vp = (p->tid == kIntPtrDtId || p->tid == kUIntPtrDtId ) ? p->u.uip : NULL;
  385. return kOkDtRC;
  386. }
  387. return _cmDataSetError(kCvtErrDtRC);
  388. }
  389. cmDtRC_t cmDataGetLongPtr( const cmData_t* p, long** vp )
  390. {
  391. if( p->tid == kLongPtrDtId || p->tid == kULongPtrDtId )
  392. {
  393. *vp = (p->tid == kLongPtrDtId || p->tid == kULongPtrDtId ) ? p->u.lp : NULL;
  394. return kOkDtRC;
  395. }
  396. return _cmDataSetError(kCvtErrDtRC);
  397. }
  398. cmDtRC_t cmDataGetULongPtr( const cmData_t* p, unsigned long** vp )
  399. {
  400. if( p->tid == kLongPtrDtId || p->tid == kULongPtrDtId )
  401. {
  402. *vp = (p->tid == kLongPtrDtId || p->tid == kULongPtrDtId ) ? p->u.ulp : NULL;
  403. return kOkDtRC;
  404. }
  405. return _cmDataSetError(kCvtErrDtRC);
  406. }
  407. cmDtRC_t cmDataGetFloatPtr( const cmData_t* p, float** vp )
  408. {
  409. if( p->tid == kFloatPtrDtId )
  410. {
  411. *vp = p->u.fp;
  412. return kOkDtRC;
  413. }
  414. return _cmDataSetError(kCvtErrDtRC);
  415. }
  416. cmDtRC_t cmDataGetDoublePtr( const cmData_t* p, double** vp )
  417. {
  418. if( p->tid == kDoublePtrDtId )
  419. {
  420. *vp = p->u.dp;
  421. return kOkDtRC;
  422. }
  423. return _cmDataSetError(kCvtErrDtRC);
  424. }
  425. // Set the value of an existing data object.
  426. cmData_t* cmDataSetNull( cmData_t* p )
  427. {
  428. _cmDataFreeArray(p);
  429. p->tid = kNullDtId;
  430. return p;
  431. }
  432. cmData_t* cmDataSetChar( cmData_t* p, char v )
  433. {
  434. _cmDataFreeArray(p);
  435. p->tid = kCharDtId;
  436. p->u.c = v;
  437. return p;
  438. }
  439. cmData_t* cmDataSetUChar( cmData_t* p, unsigned char v )
  440. {
  441. _cmDataFreeArray(p);
  442. p->tid = kUCharDtId;
  443. p->u.uc = v;
  444. return p;
  445. }
  446. cmData_t* cmDataSetShort( cmData_t* p, short v )
  447. {
  448. _cmDataFreeArray(p);
  449. p->tid = kShortDtId;
  450. p->u.s = v;
  451. return p;
  452. }
  453. cmData_t* cmDataSetUShort( cmData_t* p, unsigned short v )
  454. {
  455. _cmDataFreeArray(p);
  456. p->tid = kUShortDtId;
  457. p->u.us = v;
  458. return p;
  459. }
  460. cmData_t* cmDataSetInt( cmData_t* p, int v )
  461. {
  462. _cmDataFreeArray(p);
  463. p->tid = kCharDtId;
  464. p->u.c = v;
  465. return p;
  466. }
  467. cmData_t* cmDataSetUInt( cmData_t* p, unsigned int v )
  468. {
  469. _cmDataFreeArray(p);
  470. p->tid = kUIntDtId;
  471. p->u.ui = v;
  472. return p;
  473. }
  474. cmData_t* cmDataSetLong( cmData_t* p, long v )
  475. {
  476. _cmDataFreeArray(p);
  477. p->tid = kLongDtId;
  478. p->u.l = v;
  479. return p;
  480. }
  481. cmData_t* cmDataSetULong( cmData_t* p, unsigned long v )
  482. {
  483. _cmDataFreeArray(p);
  484. p->tid = kULongDtId;
  485. p->u.ul = v;
  486. return p;
  487. }
  488. cmData_t* cmDataSetFloat( cmData_t* p, float v )
  489. {
  490. _cmDataFreeArray(p);
  491. p->tid = kFloatDtId;
  492. p->u.f = v;
  493. return p;
  494. }
  495. cmData_t* cmDataSetDouble( cmData_t* p, double v )
  496. {
  497. _cmDataFreeArray(p);
  498. p->tid = kDoubleDtId;
  499. p->u.d = v;
  500. return p;
  501. }
  502. cmData_t* cmDataSetStr( cmData_t* p, cmChar_t* s )
  503. {
  504. _cmDataFreeArray(p);
  505. p->tid = kStrDtId;
  506. p->u.z = s;
  507. return p;
  508. }
  509. cmData_t* cmDataSetConstStr( cmData_t* p, const cmChar_t* s )
  510. {
  511. _cmDataFreeArray(p);
  512. p->tid = kConstStrDtId;
  513. p->u.cz = s;
  514. return p;
  515. }
  516. // Set the value of an existing data object to an external array.
  517. // The array is not copied.
  518. cmData_t* cmDataSetVoidPtr( cmData_t* p, void* vp, unsigned cnt )
  519. {
  520. cmDataSetCharPtr(p,(char*)vp,cnt);
  521. p->tid = kVoidPtrDtId;
  522. return p;
  523. }
  524. cmData_t* cmDataSetCharPtr( cmData_t* p, char* vp, unsigned cnt )
  525. {
  526. _cmDataFreeArray(p);
  527. p->tid = kCharPtrDtId;
  528. p->u.cp = vp;
  529. p->cnt = cnt;
  530. return p;
  531. }
  532. cmData_t* cmDataSetUCharPtr( cmData_t* p, unsigned char* vp, unsigned cnt )
  533. {
  534. _cmDataFreeArray(p);
  535. p->tid = kUCharPtrDtId;
  536. p->u.ucp = vp;
  537. p->cnt = cnt;
  538. return p;
  539. }
  540. cmData_t* cmDataSetShortPtr( cmData_t* p, short* vp, unsigned cnt )
  541. {
  542. _cmDataFreeArray(p);
  543. p->tid = kShortPtrDtId;
  544. p->u.sp = vp;
  545. p->cnt = cnt;
  546. return p;
  547. }
  548. cmData_t* cmDataSetUShortPtr( cmData_t* p, unsigned short* vp, unsigned cnt )
  549. {
  550. _cmDataFreeArray(p);
  551. p->tid = kUShortPtrDtId;
  552. p->u.usp = vp;
  553. p->cnt = cnt;
  554. return p;
  555. }
  556. cmData_t* cmDataSetIntPtr( cmData_t* p, int* vp, unsigned cnt )
  557. {
  558. _cmDataFreeArray(p);
  559. p->tid = kCharPtrDtId;
  560. p->u.ip = vp;
  561. p->cnt = cnt;
  562. return p;
  563. }
  564. cmData_t* cmDataSetUIntPtr( cmData_t* p, unsigned int* vp, unsigned cnt )
  565. {
  566. _cmDataFreeArray(p);
  567. p->tid = kUIntPtrDtId;
  568. p->u.uip = vp;
  569. p->cnt = cnt;
  570. return p;
  571. }
  572. cmData_t* cmDataSetLongPtr( cmData_t* p, long* vp, unsigned cnt )
  573. {
  574. _cmDataFreeArray(p);
  575. p->tid = kLongPtrDtId;
  576. p->u.lp = vp;
  577. p->cnt = cnt;
  578. return p;
  579. }
  580. cmData_t* cmDataSetULongPtr( cmData_t* p, unsigned long* vp, unsigned cnt )
  581. {
  582. _cmDataFreeArray(p);
  583. p->tid = kULongPtrDtId;
  584. p->u.ulp = vp;
  585. p->cnt = cnt;
  586. return p;
  587. }
  588. cmData_t* cmDataSetFloatPtr( cmData_t* p, float* vp, unsigned cnt )
  589. {
  590. _cmDataFreeArray(p);
  591. p->tid = kFloatPtrDtId;
  592. p->u.fp = vp;
  593. p->cnt = cnt;
  594. return p;
  595. }
  596. cmData_t* cmDataSetDoublePtr( cmData_t* p, double* vp, unsigned cnt )
  597. {
  598. _cmDataFreeArray(p);
  599. p->tid = kDoublePtrDtId;
  600. p->u.dp = vp;
  601. p->cnt = cnt;
  602. return p;
  603. }
  604. // Set the value of an existing array based data object.
  605. // Allocate the internal array and copy the array into it.
  606. cmData_t* cmDataSetStrAlloc( cmData_t* p, const cmChar_t* s )
  607. {
  608. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  609. cmMemResizeStr(p->u.z,s);
  610. else
  611. {
  612. _cmDataFreeArray(p);
  613. p->u.z = cmMemAllocStr(s);
  614. }
  615. p->tid = kStrDtId;
  616. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  617. return p;
  618. }
  619. cmData_t* cmDataSetConstStrAlloc( cmData_t* p, const cmChar_t* s )
  620. { return cmDataSetStrAlloc(p,s); }
  621. cmData_t* cmDataSetVoidAllocPtr( cmData_t* p, const void* vp, unsigned cnt )
  622. { return cmDataSetCharAllocPtr(p,(char*)vp,cnt); }
  623. cmData_t* cmDataSetCharAllocPtr( cmData_t* p, const char* vp, unsigned cnt )
  624. {
  625. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  626. p->u.cp = cmMemResize(char, p->u.cp, cnt );
  627. else
  628. {
  629. _cmDataFreeArray(p);
  630. p->u.cp = cmMemAlloc(char, cnt );
  631. }
  632. memcpy(p->u.cp,vp,sizeof(char)*cnt);
  633. p->tid = kCharPtrDtId;
  634. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  635. p->cnt = cnt;
  636. return p;
  637. }
  638. cmData_t* cmDataSetUCharAllocPtr( cmData_t* p, const unsigned char* vp, unsigned cnt )
  639. {
  640. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  641. p->u.ucp = cmMemResize(unsigned char, p->u.ucp, cnt );
  642. else
  643. {
  644. _cmDataFreeArray(p);
  645. p->u.ucp = cmMemAlloc(unsigned char, cnt );
  646. }
  647. memcpy(p->u.ucp,vp,sizeof(unsigned char)*cnt);
  648. p->tid = kUCharPtrDtId;
  649. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  650. p->cnt = cnt;
  651. return p;
  652. }
  653. cmData_t* cmDataSetShortAllocPtr( cmData_t* p, const short* vp, unsigned cnt )
  654. {
  655. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  656. p->u.sp = cmMemResize(short, p->u.sp, cnt );
  657. else
  658. {
  659. _cmDataFreeArray(p);
  660. p->u.sp = cmMemAlloc(short, cnt );
  661. }
  662. memcpy(p->u.sp,vp,sizeof(short)*cnt);
  663. p->tid = kShortPtrDtId;
  664. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  665. p->cnt = cnt;
  666. return p;
  667. }
  668. cmData_t* cmDataSetUShortAllocPtr( cmData_t* p, const unsigned short* vp, unsigned cnt )
  669. {
  670. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  671. p->u.usp = cmMemResize(unsigned short, p->u.usp, cnt );
  672. else
  673. {
  674. _cmDataFreeArray(p);
  675. p->u.usp = cmMemAlloc(unsigned short, cnt );
  676. }
  677. memcpy(p->u.usp,vp,sizeof(unsigned short)*cnt);
  678. p->tid = kUShortPtrDtId;
  679. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  680. p->cnt = cnt;
  681. return p;
  682. }
  683. cmData_t* cmDataSetIntAllocPtr( cmData_t* p, const int* vp, unsigned cnt )
  684. {
  685. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  686. p->u.ip = cmMemResize(int, p->u.ip, cnt );
  687. else
  688. {
  689. _cmDataFreeArray(p);
  690. p->u.ip = cmMemAlloc(int, cnt );
  691. }
  692. memcpy(p->u.ip,vp,sizeof(int)*cnt);
  693. p->tid = kIntPtrDtId;
  694. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  695. p->cnt = cnt;
  696. return p;
  697. }
  698. cmData_t* cmDataSetUIntAllocPtr( cmData_t* p, const unsigned int* vp, unsigned cnt )
  699. {
  700. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  701. p->u.uip = cmMemResize(unsigned int, p->u.uip, cnt );
  702. else
  703. {
  704. _cmDataFreeArray(p);
  705. p->u.uip = cmMemAlloc(unsigned int, cnt );
  706. }
  707. memcpy(p->u.uip,vp,sizeof(unsigned int)*cnt);
  708. p->tid = kUIntPtrDtId;
  709. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  710. p->cnt = cnt;
  711. return p;
  712. }
  713. cmData_t* cmDataSetLongAllocPtr( cmData_t* p, const long* vp, unsigned cnt )
  714. {
  715. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  716. p->u.lp = cmMemResize(long, p->u.lp, cnt );
  717. else
  718. {
  719. _cmDataFreeArray(p);
  720. p->u.lp = cmMemAlloc(long, cnt );
  721. }
  722. memcpy(p->u.lp,vp,sizeof(long)*cnt);
  723. p->tid = kLongPtrDtId;
  724. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  725. p->cnt = cnt;
  726. return p;
  727. }
  728. cmData_t* cmDataSetULongAllocPtr( cmData_t* p, const unsigned long* vp, unsigned cnt )
  729. {
  730. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  731. p->u.ulp = cmMemResize(unsigned long, p->u.ulp, cnt );
  732. else
  733. {
  734. _cmDataFreeArray(p);
  735. p->u.ulp = cmMemAlloc(unsigned long, cnt );
  736. }
  737. memcpy(p->u.ulp,vp,sizeof(unsigned long)*cnt);
  738. p->tid = kULongPtrDtId;
  739. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  740. p->cnt = cnt;
  741. return p;
  742. }
  743. cmData_t* cmDataSetFloatAllocPtr( cmData_t* p, const float* vp, unsigned cnt )
  744. {
  745. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  746. p->u.fp = cmMemResize(float, p->u.fp, cnt );
  747. else
  748. {
  749. _cmDataFreeArray(p);
  750. p->u.fp = cmMemAlloc(float, cnt );
  751. }
  752. memcpy(p->u.fp,vp,sizeof(float)*cnt);
  753. p->tid = kFloatPtrDtId;
  754. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  755. p->cnt = cnt;
  756. return p;
  757. }
  758. cmData_t* cmDataSetDoubleAllocPtr( cmData_t* p, const double* vp, unsigned cnt )
  759. {
  760. if( cmIsFlag(p->flags,kDynPtrDtFl) )
  761. p->u.dp = cmMemResize(double, p->u.dp, cnt );
  762. else
  763. {
  764. _cmDataFreeArray(p);
  765. p->u.dp = cmMemAlloc(double, cnt );
  766. }
  767. memcpy(p->u.dp,vp,sizeof(double)*cnt);
  768. p->tid = kDoublePtrDtId;
  769. p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
  770. p->cnt = cnt;
  771. return p;
  772. }
  773. // Dynamically allocate a data object and set it's value.
  774. cmData_t* cmDataAllocNull( cmData_t* parent )
  775. { return _cmDataAllocNode(parent,kNullDtId); }
  776. cmData_t* cmDataAllocChar( cmData_t* parent, char v )
  777. {
  778. cmData_t* p = _cmDataAllocNode(parent,kCharDtId);
  779. cmDataSetChar(p,v);
  780. return p;
  781. }
  782. cmData_t* cmDataAllocUChar( cmData_t* parent, unsigned char v )
  783. {
  784. cmData_t* p = _cmDataAllocNode(parent,kUCharDtId);
  785. cmDataSetUChar(p,v);
  786. return p;
  787. }
  788. cmData_t* cmDataAllocShort( cmData_t* parent, short v )
  789. {
  790. cmData_t* p = _cmDataAllocNode(parent,kShortDtId);
  791. cmDataSetShort(p,v);
  792. return p;
  793. }
  794. cmData_t* cmDataAllocUShort( cmData_t* parent, unsigned short v )
  795. {
  796. cmData_t* p = _cmDataAllocNode(parent,kUShortDtId);
  797. cmDataSetUShort(p,v);
  798. return p;
  799. }
  800. cmData_t* cmDataAllocInt( cmData_t* parent, int v )
  801. {
  802. cmData_t* p = _cmDataAllocNode(parent,kIntDtId);
  803. cmDataSetInt(p,v);
  804. return p;
  805. }
  806. cmData_t* cmDataAllocUInt( cmData_t* parent, unsigned int v )
  807. {
  808. cmData_t* p = _cmDataAllocNode(parent,kUIntDtId);
  809. cmDataSetUInt(p,v);
  810. return p;
  811. }
  812. cmData_t* cmDataAllocLong( cmData_t* parent, long v )
  813. {
  814. cmData_t* p = _cmDataAllocNode(parent,kLongDtId);
  815. cmDataSetLong(p,v);
  816. return p;
  817. }
  818. cmData_t* cmDataAllocULong( cmData_t* parent, unsigned long v )
  819. {
  820. cmData_t* p = _cmDataAllocNode(parent,kULongDtId);
  821. cmDataSetULong(p,v);
  822. return p;
  823. }
  824. cmData_t* cmDataAllocFloat( cmData_t* parent, float v )
  825. {
  826. cmData_t* p = _cmDataAllocNode(parent,kFloatDtId);
  827. cmDataSetFloat(p,v);
  828. return p;
  829. }
  830. cmData_t* cmDataAllocDouble( cmData_t* parent, double v )
  831. {
  832. cmData_t* p = _cmDataAllocNode(parent,kDoubleDtId);
  833. cmDataSetDouble(p,v);
  834. return p;
  835. }
  836. // Dynamically allocate a data object and set its array value to an external
  837. // array. The data is not copied.
  838. cmData_t* cmDataAllocStr( cmData_t* parent, cmChar_t* str )
  839. {
  840. cmData_t* p = _cmDataAllocNode(parent,kStrDtId);
  841. cmDataSetStr(p,str);
  842. return p;
  843. }
  844. cmData_t* cmDataAllocConstStr( cmData_t* parent, const cmChar_t* str )
  845. {
  846. cmData_t* p = _cmDataAllocNode(parent,kConstStrDtId);
  847. cmDataSetConstStr(p,str);
  848. return p;
  849. }
  850. cmData_t* cmDataAllocCharPtr( cmData_t* parent, char* v, unsigned cnt )
  851. {
  852. cmData_t* p = _cmDataAllocNode(parent,kCharPtrDtId);
  853. cmDataSetCharPtr(p,(char*)v,cnt);
  854. return p;
  855. }
  856. cmData_t* cmDataAllocUCharPtr( cmData_t* parent, unsigned char* v, unsigned cnt )
  857. {
  858. cmData_t* p = _cmDataAllocNode(parent,kUCharPtrDtId);
  859. cmDataSetUCharPtr(p,(unsigned char*)v,cnt);
  860. return p;
  861. }
  862. cmData_t* cmDataAllocShortPtr( cmData_t* parent, short* v, unsigned cnt )
  863. {
  864. cmData_t* p = _cmDataAllocNode(parent,kShortPtrDtId);
  865. cmDataSetShortPtr(p,(short*)v,cnt);
  866. return p;
  867. }
  868. cmData_t* cmDataAllocUShortPtr( cmData_t* parent, unsigned short* v, unsigned cnt )
  869. {
  870. cmData_t* p = _cmDataAllocNode(parent,kUShortPtrDtId);
  871. cmDataSetUShortPtr(p,(unsigned short*)v,cnt);
  872. return p;
  873. }
  874. cmData_t* cmDataAllocIntPtr( cmData_t* parent, int* v, unsigned cnt )
  875. {
  876. cmData_t* p = _cmDataAllocNode(parent,kIntPtrDtId);
  877. cmDataSetIntPtr(p,(int*)v,cnt);
  878. return p;
  879. }
  880. cmData_t* cmDataAllocUIntPtr( cmData_t* parent, unsigned int* v, unsigned cnt )
  881. {
  882. cmData_t* p = _cmDataAllocNode(parent,kUIntPtrDtId);
  883. cmDataSetUIntPtr(p,(unsigned int*)v,cnt);
  884. return p;
  885. }
  886. cmData_t* cmDataAllocLongPtr( cmData_t* parent, long* v, unsigned cnt )
  887. {
  888. cmData_t* p = _cmDataAllocNode(parent,kLongPtrDtId);
  889. cmDataSetLongPtr(p,(long*)v,cnt);
  890. return p;
  891. }
  892. cmData_t* cmDataAllocULongPtr( cmData_t* parent, unsigned long* v, unsigned cnt )
  893. {
  894. cmData_t* p = _cmDataAllocNode(parent,kULongPtrDtId);
  895. cmDataSetULongPtr(p,(unsigned long*)v,cnt);
  896. return p;
  897. }
  898. cmData_t* cmDataAllocFloatPtr( cmData_t* parent, float* v, unsigned cnt )
  899. {
  900. cmData_t* p = _cmDataAllocNode(parent,kFloatPtrDtId);
  901. cmDataSetFloatPtr(p,(float*)v,cnt);
  902. return p;
  903. }
  904. cmData_t* cmDataAllocDoublePtr( cmData_t* parent, double* v, unsigned cnt )
  905. {
  906. cmData_t* p = _cmDataAllocNode(parent,kDoublePtrDtId);
  907. cmDataSetDoublePtr(p,(double*)v,cnt);
  908. return p;
  909. }
  910. cmData_t* cmDataAllocVoidPtr( cmData_t* parent, void* v, unsigned cnt )
  911. {
  912. cmData_t* p = _cmDataAllocNode(parent,kVoidPtrDtId);
  913. cmDataSetCharPtr(p,(char*)v,cnt);
  914. p->tid = kVoidPtrDtId;
  915. return p;
  916. }
  917. // Dynamically allocate a data object and its array value.
  918. // v[cnt] is copied into the allocated array.
  919. cmData_t* cmDataStrAlloc( cmData_t* parent, cmChar_t* str )
  920. {
  921. cmData_t* p = _cmDataAllocNode(parent,kStrDtId);
  922. cmDataSetStrAlloc(p,str);
  923. return p;
  924. }
  925. cmData_t* cmDataConstStrAlloc( cmData_t* parent, const cmChar_t* str )
  926. {
  927. cmData_t* p = _cmDataAllocNode(parent,kConstStrDtId);
  928. cmDataSetConstStrAlloc(p,str);
  929. return p;
  930. }
  931. cmData_t* cmDataCharAllocPtr( cmData_t* parent, const char* v, unsigned cnt )
  932. {
  933. cmData_t* p = _cmDataAllocNode(parent,kCharPtrDtId);
  934. cmDataSetCharAllocPtr(p, v, cnt );
  935. return p;
  936. }
  937. cmData_t* cmDataUCharAllocPtr( cmData_t* parent, const unsigned char* v, unsigned cnt )
  938. {
  939. cmData_t* p = _cmDataAllocNode(parent,kUCharPtrDtId);
  940. cmDataSetUCharAllocPtr(p, v, cnt );
  941. return p;
  942. }
  943. cmData_t* cmDataShortAllocPtr( cmData_t* parent, const short* v, unsigned cnt )
  944. {
  945. cmData_t* p = _cmDataAllocNode(parent,kShortPtrDtId);
  946. cmDataSetShortAllocPtr(p, v, cnt );
  947. return p;
  948. }
  949. cmData_t* cmDataUShortAllocPtr( cmData_t* parent, const unsigned short* v, unsigned cnt )
  950. {
  951. cmData_t* p = _cmDataAllocNode(parent,kUShortPtrDtId);
  952. cmDataSetUShortAllocPtr(p, v, cnt );
  953. return p;
  954. }
  955. cmData_t* cmDataIntAllocPtr( cmData_t* parent, const int* v, unsigned cnt )
  956. {
  957. cmData_t* p = _cmDataAllocNode(parent,kIntPtrDtId);
  958. cmDataSetIntAllocPtr(p, v, cnt );
  959. return p;
  960. }
  961. cmData_t* cmDataUIntAllocPtr( cmData_t* parent, const unsigned int* v, unsigned cnt )
  962. {
  963. cmData_t* p = _cmDataAllocNode(parent,kUIntPtrDtId);
  964. cmDataSetUIntAllocPtr(p, v, cnt );
  965. return p;
  966. }
  967. cmData_t* cmDataLongAllocPtr( cmData_t* parent, const long* v, unsigned cnt )
  968. {
  969. cmData_t* p = _cmDataAllocNode(parent,kLongPtrDtId);
  970. cmDataSetLongAllocPtr(p, v, cnt );
  971. return p;
  972. }
  973. cmData_t* cmDataULongAllocPtr( cmData_t* parent, const unsigned long* v, unsigned cnt )
  974. {
  975. cmData_t* p = _cmDataAllocNode(parent,kULongPtrDtId);
  976. cmDataSetULongAllocPtr(p, v, cnt );
  977. return p;
  978. }
  979. cmData_t* cmDataFloatAllocPtr( cmData_t* parent, const float* v, unsigned cnt )
  980. {
  981. cmData_t* p = _cmDataAllocNode(parent,kFloatPtrDtId);
  982. cmDataSetFloatAllocPtr(p, v, cnt );
  983. return p;
  984. }
  985. cmData_t* cmDataDoubleAllocPtr( cmData_t* parent, const double* v, unsigned cnt )
  986. {
  987. cmData_t* p = _cmDataAllocNode(parent,kDoublePtrDtId);
  988. cmDataSetDoubleAllocPtr(p, v, cnt );
  989. return p;
  990. }
  991. cmData_t* cmDataVoidAllocPtr( cmData_t* parent, const void* v, unsigned cnt )
  992. {
  993. cmData_t* p = _cmDataAllocNode(parent,kVoidPtrDtId);
  994. cmDataSetCharAllocPtr(p, (const char*)v, cnt );
  995. p->tid = kVoidPtrDtId;
  996. return p;
  997. }
  998. void cmDataFree( cmData_t* p )
  999. {
  1000. _cmDataFree(p);
  1001. }
  1002. cmData_t* cmDataUnlink( cmData_t* p )
  1003. {
  1004. if( p->parent == NULL )
  1005. return p;
  1006. assert( cmDataIsStruct(p->parent) );
  1007. cmData_t* cp = p->u.child;
  1008. cmData_t* pp = NULL;
  1009. for(; cp!=NULL; cp=cp->sibling)
  1010. if( cp == p )
  1011. {
  1012. if( pp == NULL )
  1013. p->parent->u.child = p->sibling;
  1014. else
  1015. pp->sibling = cp->sibling;
  1016. }
  1017. return p;
  1018. }
  1019. void cmDataUnlinkAndFree( cmData_t* p )
  1020. {
  1021. cmDataUnlink(p);
  1022. cmDataFree(p);
  1023. }
  1024. cmData_t* _cmDataDupl( const cmData_t* p, cmData_t* parent )
  1025. {
  1026. cmData_t* rp = NULL;
  1027. switch( p->tid )
  1028. {
  1029. case kNullDtId: rp = cmDataAllocNull(parent); break;
  1030. case kUCharDtId: rp = cmDataAllocUChar(parent,p->u.uc); break;
  1031. case kCharDtId: rp = cmDataAllocChar(parent,p->u.c); break;
  1032. case kUShortDtId: rp = cmDataAllocShort(parent,p->u.us); break;
  1033. case kShortDtId: rp = cmDataAllocUShort(parent,p->u.s); break;
  1034. case kUIntDtId: rp = cmDataAllocUInt(parent,p->u.i); break;
  1035. case kIntDtId: rp = cmDataAllocInt(parent,p->u.ui); break;
  1036. case kULongDtId: rp = cmDataAllocULong(parent,p->u.ul); break;
  1037. case kLongDtId: rp = cmDataAllocLong(parent,p->u.l); break;
  1038. case kFloatDtId: rp = cmDataAllocFloat(parent,p->u.f); break;
  1039. case kDoubleDtId: rp = cmDataAllocDouble(parent,p->u.d); break;
  1040. case kStrDtId: rp = cmDataStrAlloc(parent,p->u.z); break;
  1041. case kConstStrDtId: rp = cmDataConstStrAlloc(parent,p->u.cz); break;
  1042. case kUCharPtrDtId: rp = cmDataUCharAllocPtr(parent,p->u.ucp,p->cnt); break;
  1043. case kCharPtrDtId: rp = cmDataCharAllocPtr(parent,p->u.cp,p->cnt); break;
  1044. case kUShortPtrDtId: rp = cmDataUShortAllocPtr(parent,p->u.usp,p->cnt); break;
  1045. case kShortPtrDtId: rp = cmDataShortAllocPtr(parent,p->u.sp,p->cnt); break;
  1046. case kUIntPtrDtId: rp = cmDataUIntAllocPtr(parent,p->u.uip,p->cnt); break;
  1047. case kIntPtrDtId: rp = cmDataIntAllocPtr(parent,p->u.ip,p->cnt); break;
  1048. case kULongPtrDtId: rp = cmDataULongAllocPtr(parent,p->u.ulp,p->cnt); break;
  1049. case kLongPtrDtId: rp = cmDataLongAllocPtr(parent,p->u.lp,p->cnt); break;
  1050. case kFloatPtrDtId: rp = cmDataFloatAllocPtr(parent,p->u.fp,p->cnt); break;
  1051. case kDoublePtrDtId: rp = cmDataDoubleAllocPtr(parent,p->u.dp,p->cnt); break;
  1052. case kVoidPtrDtId: rp = cmDataVoidAllocPtr(parent,p->u.vp,p->cnt); break;
  1053. case kListDtId:
  1054. case kPairDtId:
  1055. case kRecordDtId:
  1056. {
  1057. rp = _cmDataAllocNode(parent,p->tid);
  1058. cmData_t* cp = p->u.child;
  1059. for(; cp!=NULL; cp=cp->sibling)
  1060. cmDataAppendChild(rp,_cmDataDupl(cp,rp));
  1061. }
  1062. break;
  1063. default:
  1064. assert(0);
  1065. }
  1066. return rp;
  1067. }
  1068. cmData_t* cmDataDupl( const cmData_t* p )
  1069. { return _cmDataDupl(p,NULL); }
  1070. cmData_t* cmDataReplace( cmData_t* dst, cmData_t* src )
  1071. {
  1072. if( dst->parent == NULL )
  1073. {
  1074. cmDataUnlinkAndFree(dst);
  1075. src->parent = NULL;
  1076. return src;
  1077. }
  1078. cmData_t* parent = dst->parent;
  1079. cmData_t* cp = parent->u.child;
  1080. cmData_t* pp = NULL;
  1081. unsigned i = 0;
  1082. unsigned n = cmDataChildCount(parent);
  1083. // locate dst's right sibling
  1084. for(i=0; i<n; ++i,cp=cp->sibling)
  1085. {
  1086. if( cp == dst )
  1087. {
  1088. // link in 'src' in place of 'dst'
  1089. src->sibling = dst->sibling;
  1090. // free dst
  1091. cmDataUnlinkAndFree(dst);
  1092. // update the sibling link to
  1093. if( pp == NULL )
  1094. parent->u.child = src;
  1095. else
  1096. pp->sibling = src;
  1097. src->parent = parent;
  1098. break;
  1099. }
  1100. pp = cp;
  1101. }
  1102. return src;
  1103. }
  1104. unsigned cmDataChildCount( const cmData_t* p )
  1105. {
  1106. if( !cmDataIsStruct(p) )
  1107. return 0;
  1108. unsigned n = 0;
  1109. const cmData_t* cp = p->u.child;
  1110. for(; cp!=NULL; cp=cp->sibling)
  1111. ++n;
  1112. return n;
  1113. }
  1114. cmData_t* cmDataChild( cmData_t* p, unsigned index )
  1115. {
  1116. if( !cmDataIsStruct(p) )
  1117. return NULL;
  1118. unsigned n = 0;
  1119. cmData_t* cp = p->u.child;
  1120. for(; cp!=NULL; cp=cp->sibling)
  1121. {
  1122. if( n == index )
  1123. break;
  1124. ++n;
  1125. }
  1126. return cp;
  1127. }
  1128. cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p )
  1129. {
  1130. assert( cmDataIsStruct(p) );
  1131. cmDataUnlink(p);
  1132. p->u.child = parent->u.child;
  1133. parent->u.child = p;
  1134. p->parent = parent;
  1135. return p;
  1136. }
  1137. cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p )
  1138. {
  1139. assert( cmDataIsStruct(parent) );
  1140. assert( parent->tid != kRecordDtId || (parent->tid == kRecordDtId && p->tid==kPairDtId));
  1141. cmDataUnlink(p);
  1142. cmData_t* cp = parent->u.child;
  1143. if( cp == NULL )
  1144. parent->u.child = p;
  1145. else
  1146. {
  1147. for(; cp!=NULL; cp=cp->sibling)
  1148. if( cp->sibling == NULL )
  1149. {
  1150. cp->sibling = p;
  1151. break;
  1152. }
  1153. }
  1154. p->parent = parent;
  1155. p->sibling = NULL;
  1156. return p;
  1157. }
  1158. cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p )
  1159. {
  1160. if( !cmDataIsStruct(parent) )
  1161. return NULL;
  1162. cmDataUnlink(p);
  1163. unsigned n = 0;
  1164. cmData_t* cp = parent->u.child;
  1165. cmData_t* pp = NULL;
  1166. for(; cp!=NULL; cp=cp->sibling)
  1167. {
  1168. if( n == index )
  1169. {
  1170. if( pp == NULL )
  1171. {
  1172. parent->u.child = p;
  1173. p->sibling = NULL;
  1174. }
  1175. else
  1176. {
  1177. p->sibling = pp->sibling;
  1178. pp->sibling = p;
  1179. }
  1180. break;
  1181. }
  1182. ++n;
  1183. }
  1184. p->parent = parent;
  1185. return p;
  1186. }
  1187. //----------------------------------------------------------------------------
  1188. bool _cmDataPairIsValid( const cmData_t* p )
  1189. {
  1190. assert( p->tid == kPairDtId );
  1191. const cmData_t* cp = p->u.child;
  1192. bool fl = cp->u.child == NULL || cp->u.child->sibling == NULL || cp->u.child->sibling->sibling!=NULL;
  1193. return !fl;
  1194. }
  1195. // Get the key/value of a pair
  1196. cmData_t* cmDataPairKey( cmData_t* p )
  1197. {
  1198. assert( _cmDataPairIsValid(p) );
  1199. return p->u.child;
  1200. }
  1201. unsigned cmDataPairKeyId( cmData_t* p )
  1202. {
  1203. assert( _cmDataPairIsValid(p) );
  1204. unsigned id = cmInvalidId;
  1205. cmDataGetUInt(p->u.child,&id);
  1206. return id;
  1207. }
  1208. const cmChar_t* cmDataPairKeyLabel( cmData_t* p )
  1209. {
  1210. assert( _cmDataPairIsValid(p) );
  1211. const cmChar_t* label = NULL;
  1212. cmDataGetConstStr(p->u.child,&label);
  1213. return label;
  1214. }
  1215. cmData_t* cmDataPairValue( cmData_t* p )
  1216. {
  1217. assert( _cmDataPairIsValid(p) );
  1218. return p->u.child->sibling;
  1219. }
  1220. // Set the key or value of an existing pair node.
  1221. cmData_t* cmDataPairSetValue( cmData_t* p, cmData_t* value )
  1222. {
  1223. assert( _cmDataPairIsValid(p) );
  1224. cmDataReplace( cmDataPairValue(p), value );
  1225. return p;
  1226. }
  1227. cmData_t* cmDataPairSetKey( cmData_t* p, cmData_t* key )
  1228. {
  1229. assert( _cmDataPairIsValid(p) );
  1230. cmDataReplace( cmDataPairValue(p), key );
  1231. return p;
  1232. }
  1233. cmData_t* cmDataPairSetKeyId( cmData_t* p, unsigned id )
  1234. {
  1235. assert( _cmDataPairIsValid(p) );
  1236. cmDataSetUInt(p->u.child,id);
  1237. return p;
  1238. }
  1239. cmData_t* cmDataPairSetKeyLabel( cmData_t* p, const cmChar_t* label )
  1240. {
  1241. assert( _cmDataPairIsValid(p) );
  1242. cmDataSetConstStrAlloc(p->u.child,label);
  1243. return p;
  1244. }
  1245. cmData_t* cmDataMakePair( cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t* value )
  1246. {
  1247. _cmDataFree(p);
  1248. p->tid = kPairDtId;
  1249. p->parent = parent;
  1250. p->flags = 0;
  1251. p->u.child = NULL;
  1252. cmDataAppendChild(p,key);
  1253. cmDataAppendChild(p,value);
  1254. return p;
  1255. }
  1256. // Dynamically allocate a pair node
  1257. cmData_t* cmDataAllocPair( cmData_t* parent, const cmData_t* key, const cmData_t* value )
  1258. {
  1259. cmData_t* p = _cmDataAllocNode(parent,kPairDtId);
  1260. cmData_t* kp = cmDataDupl(key);
  1261. cmData_t* vp = cmDataDupl(value);
  1262. cmDataPrependChild(p,vp);
  1263. cmDataPrependChild(p,kp);
  1264. return p;
  1265. }
  1266. cmData_t* cmDataAllocPairId(cmData_t* parent, unsigned keyId, cmData_t* value )
  1267. {
  1268. cmData_t* p = _cmDataAllocNode(parent,kPairDtId);
  1269. cmDataAllocUInt(p,keyId);
  1270. cmDataAppendChild(p,value);
  1271. return p;
  1272. }
  1273. cmData_t* cmDataAllocPairLabel( cmData_t* parent, const cmChar_t *label, cmData_t* value )
  1274. {
  1275. cmData_t* p = _cmDataAllocNode(parent,kPairDtId);
  1276. cmDataConstStrAlloc(p,label);
  1277. cmDataAppendChild(p,value);
  1278. return p;
  1279. }
  1280. //----------------------------------------------------------------------------
  1281. unsigned cmDataListCount(const cmData_t* p )
  1282. { return cmDataChildCount(p); }
  1283. cmData_t* cmDataListEle( cmData_t* p, unsigned index )
  1284. { return cmDataChild(p,index); }
  1285. cmData_t* cmDataListMake( cmData_t* parent, cmData_t* p )
  1286. {
  1287. _cmDataFree(p);
  1288. p->parent = parent;
  1289. p->tid = kListDtId;
  1290. p->flags = 0;
  1291. p->u.child = NULL;
  1292. return p;
  1293. }
  1294. cmData_t* cmDataListAlloc( cmData_t* parent)
  1295. { return _cmDataAllocNode(parent,kListDtId); }
  1296. cmDtRC_t _cmDataParseArgV( cmData_t* parent, va_list vl, cmData_t** vpp )
  1297. {
  1298. cmDtRC_t rc = kOkDtRC;
  1299. cmData_t* vp = NULL;
  1300. unsigned tid = va_arg(vl,unsigned);
  1301. switch(tid)
  1302. {
  1303. case kInvalidDtId: rc = kEolDtRC; break;
  1304. case kNullDtId: vp = cmDataAllocNull(parent); break;
  1305. case kUCharDtId: vp = cmDataAllocUChar( parent,va_arg(vl,int)); break;
  1306. case kCharDtId: vp = cmDataAllocChar( parent,va_arg(vl,int)); break;
  1307. case kUShortDtId: vp = cmDataAllocUShort( parent,va_arg(vl,int)); break;
  1308. case kShortDtId: vp = cmDataAllocShort( parent,va_arg(vl,int)); break;
  1309. case kUIntDtId: vp = cmDataAllocUInt( parent,va_arg(vl,unsigned int)); break;
  1310. case kIntDtId: vp = cmDataAllocInt( parent,va_arg(vl,int)); break;
  1311. case kULongDtId: vp = cmDataAllocULong( parent,va_arg(vl,unsigned long)); break;
  1312. case kLongDtId: vp = cmDataAllocLong( parent,va_arg(vl,long)); break;
  1313. case kFloatDtId: vp = cmDataAllocFloat( parent,va_arg(vl,double)); break;
  1314. case kDoubleDtId: vp = cmDataAllocDouble( parent,va_arg(vl,double)); break;
  1315. case kStrDtId: vp = cmDataStrAlloc( parent,va_arg(vl,cmChar_t*)); break;
  1316. case kConstStrDtId: vp = cmDataConstStrAlloc( parent,va_arg(vl,const cmChar_t*)); break;
  1317. case kUCharPtrDtId:
  1318. {
  1319. unsigned char* p = va_arg(vl,unsigned char*);
  1320. vp = cmDataUCharAllocPtr(parent, p, va_arg(vl,unsigned));
  1321. }
  1322. break;
  1323. case kCharPtrDtId:
  1324. {
  1325. char* p = va_arg(vl,char*);
  1326. vp = cmDataCharAllocPtr(parent, p, va_arg(vl,unsigned));
  1327. }
  1328. break;
  1329. case kUShortPtrDtId:
  1330. {
  1331. unsigned short* p = va_arg(vl,unsigned short*);
  1332. vp = cmDataUShortAllocPtr(parent, p, va_arg(vl,unsigned));
  1333. }
  1334. break;
  1335. case kShortPtrDtId:
  1336. {
  1337. short* p = va_arg(vl,short*);
  1338. vp = cmDataShortAllocPtr(parent, p, va_arg(vl,unsigned));
  1339. }
  1340. break;
  1341. case kUIntPtrDtId:
  1342. {
  1343. unsigned int* p = va_arg(vl,unsigned int*);
  1344. vp = cmDataUIntAllocPtr(parent, p, va_arg(vl,unsigned));
  1345. }
  1346. break;
  1347. case kIntPtrDtId:
  1348. {
  1349. int * p = va_arg(vl,int*);
  1350. vp = cmDataIntAllocPtr(parent, p, va_arg(vl,unsigned));
  1351. }
  1352. break;
  1353. case kULongPtrDtId:
  1354. {
  1355. unsigned long* p = va_arg(vl,unsigned long*);
  1356. vp = cmDataULongAllocPtr(parent, p, va_arg(vl,unsigned));
  1357. }
  1358. break;
  1359. case kLongPtrDtId:
  1360. {
  1361. long* p = va_arg(vl,long*);
  1362. vp = cmDataLongAllocPtr(parent, p, va_arg(vl,unsigned));
  1363. }
  1364. break;
  1365. case kFloatPtrDtId:
  1366. {
  1367. float* p = va_arg(vl,float*);
  1368. vp = cmDataFloatAllocPtr(parent, p, va_arg(vl,unsigned));
  1369. }
  1370. break;
  1371. case kDoublePtrDtId:
  1372. {
  1373. double* p = va_arg(vl,double*);
  1374. vp = cmDataDoubleAllocPtr(parent,p, va_arg(vl,unsigned));
  1375. }
  1376. break;
  1377. case kVoidPtrDtId:
  1378. {
  1379. void* p = va_arg(vl,void*);
  1380. vp = cmDataVoidAllocPtr(parent, p, va_arg(vl,unsigned));
  1381. }
  1382. break;
  1383. case kListDtId:
  1384. case kPairDtId:
  1385. case kRecordDtId:
  1386. vp = _cmDataAllocNode(parent,tid);
  1387. break;
  1388. default:
  1389. _cmDataSetError(kVarArgErrDtRC);
  1390. break;
  1391. }
  1392. *vpp = vp;
  1393. return rc;
  1394. }
  1395. cmData_t* _cmDataListParseV(cmData_t* parent, va_list vl )
  1396. {
  1397. cmData_t* p = NULL;
  1398. bool contFl = true;
  1399. while( contFl )
  1400. {
  1401. cmData_t* vp;
  1402. cmDtRC_t rc = _cmDataParseArgV(parent, vl, &vp);
  1403. if(rc != kOkDtRC || cmDataAppendChild(parent,vp)==NULL )
  1404. contFl = false;
  1405. }
  1406. return p;
  1407. }
  1408. cmData_t* cmDataListAllocV(cmData_t* parent, va_list vl )
  1409. {
  1410. cmData_t* p = cmDataListAlloc(parent);
  1411. _cmDataListParseV(p, vl );
  1412. return p;
  1413. }
  1414. cmData_t* cmDataListAllocA(cmData_t* parent, ... )
  1415. {
  1416. va_list vl;
  1417. va_start(vl,parent);
  1418. cmData_t* p = cmDataListAllocV(parent,vl);
  1419. va_end(vl);
  1420. return p;
  1421. }
  1422. cmData_t* cmDataListAppendEle( cmData_t* p, cmData_t* ele )
  1423. {
  1424. assert(p->tid == kListDtId);
  1425. return cmDataAppendChild(p,ele);
  1426. }
  1427. cmData_t* cmDataListAppendEleN(cmData_t* p, cmData_t* ele[], unsigned n )
  1428. {
  1429. assert(p->tid == kListDtId);
  1430. cmData_t* rp = NULL;
  1431. unsigned i;
  1432. for(i=0; i<n; ++i)
  1433. {
  1434. cmData_t* ep = cmDataAppendChild(p,ele[i]);
  1435. if( rp == NULL )
  1436. rp = ep;
  1437. }
  1438. return rp;
  1439. }
  1440. cmDtRC_t cmDataListAppendV( cmData_t* p, va_list vl )
  1441. {
  1442. if( _cmDataListParseV(p, vl ) == NULL )
  1443. return _cmDataErrNo;
  1444. return kOkDtRC;
  1445. }
  1446. cmDtRC_t cmDataListAppend( cmData_t* p, ... )
  1447. {
  1448. va_list vl;
  1449. va_start(vl,p);
  1450. cmDtRC_t rc = cmDataListAppendV(p,vl);
  1451. va_end(vl);
  1452. return rc;
  1453. }
  1454. cmData_t* cmDataListInsertEle( cmData_t* p, unsigned index, cmData_t* ele )
  1455. { return cmDataInsertChild(p,index,ele); }
  1456. cmData_t* cmDataListInsertEleN(cmData_t* p, unsigned index, cmData_t* ele[], unsigned n )
  1457. {
  1458. unsigned i;
  1459. for(i=0; i<n; ++i)
  1460. cmDataListInsertEle(p,index+i,ele[i]);
  1461. return p;
  1462. }
  1463. //----------------------------------------------------------------------------
  1464. unsigned cmDataRecdCount( const cmData_t* p )
  1465. {
  1466. assert( p->tid == kRecordDtId );
  1467. return cmDataChildCount(p);
  1468. }
  1469. cmData_t* cmDataRecdEle( cmData_t* p, unsigned index )
  1470. {
  1471. assert( p->tid == kRecordDtId );
  1472. cmData_t* cp = cmDataChild(p,index);
  1473. assert( p->tid == kPairDtId );
  1474. return cp;
  1475. }
  1476. cmData_t* cmDataRecdValueFromIndex( cmData_t* p, unsigned index )
  1477. {
  1478. assert( p->tid == kRecordDtId );
  1479. cmData_t* cp = cmDataChild(p,index);
  1480. assert( p->tid == kPairDtId );
  1481. return cmDataPairValue(cp);
  1482. }
  1483. cmData_t* cmDataRecdValueFromId( cmData_t* p, unsigned id )
  1484. {
  1485. assert( p->tid == kRecordDtId );
  1486. cmData_t* cp = p->u.child;
  1487. for(; cp!=NULL; cp=cp->sibling)
  1488. if( cmDataPairKeyId(cp) == id )
  1489. break;
  1490. assert( cp!=NULL && cp->tid==kPairDtId );
  1491. return cmDataPairValue(cp);
  1492. }
  1493. cmData_t* cmDataRecdValueFromLabel( cmData_t* p, const cmChar_t* label )
  1494. {
  1495. assert( p->tid == kRecordDtId );
  1496. cmData_t* cp = p->u.child;
  1497. for(; cp!=NULL; cp=cp->sibling)
  1498. {
  1499. const cmChar_t* lp = cmDataPairKeyLabel(cp);
  1500. if( lp!=NULL && strcmp(lp,label)==0 )
  1501. break;
  1502. }
  1503. assert( cp!=NULL && cp->tid==kPairDtId );
  1504. return cmDataPairValue(cp);
  1505. }
  1506. cmData_t* cmDataRecdKey( cmData_t* p, unsigned index )
  1507. {
  1508. assert( p->tid == kRecordDtId );
  1509. cmData_t* cp = cmDataChild(p,index);
  1510. assert( p->tid == kPairDtId );
  1511. return cmDataPairKey(cp);
  1512. }
  1513. unsigned cmDataRecdKeyId( cmData_t* p, unsigned index )
  1514. {
  1515. cmData_t* kp = cmDataRecdKey(p,index);
  1516. unsigned id = cmInvalidId;
  1517. cmDataGetUInt(kp,&id);
  1518. return id;
  1519. }
  1520. const cmChar_t* cmDataRecdKeyLabel( cmData_t* p, unsigned index )
  1521. {
  1522. cmData_t* kp = cmDataRecdKey(p,index);
  1523. const cmChar_t* label = NULL;
  1524. cmDataGetConstStr(kp,&label);
  1525. return label;
  1526. }
  1527. cmData_t* cmRecdMake( cmData_t* parent, cmData_t* p )
  1528. {
  1529. _cmDataFree(p);
  1530. p->parent = parent;
  1531. p->tid = kRecordDtId;
  1532. p->flags = 0;
  1533. p->u.child = NULL;
  1534. return p;
  1535. }
  1536. cmData_t* cmRecdAlloc(cmData_t* parent)
  1537. { return _cmDataAllocNode(parent,kRecordDtId); }
  1538. cmData_t* cmRecdAppendPair( cmData_t* p, cmData_t* pair )
  1539. {
  1540. assert( p!=NULL && p->tid==kRecordDtId);
  1541. cmDataAppendChild(p,pair);
  1542. return p;
  1543. }
  1544. cmDtRC_t _cmDataRecdParseInputV(cmData_t* parent, unsigned idFl, va_list vl )
  1545. {
  1546. assert( parent != NULL && parent->tid == kRecordDtId );
  1547. bool contFl = true;
  1548. cmDtRC_t rc = kOkDtRC;
  1549. // for each record field
  1550. while( contFl )
  1551. {
  1552. cmData_t* vp = NULL;
  1553. unsigned id = cmInvalidId;
  1554. const cmChar_t* label = NULL;
  1555. // parse the field idenfier
  1556. if( idFl )
  1557. id = va_arg(vl,unsigned); // numeric field identifier
  1558. else
  1559. label = va_arg(vl,const char*); // text field label identifier
  1560. // validate the field identifier
  1561. if( (idFl && id==kInvalidDtId) || (!idFl && label==NULL) )
  1562. break;
  1563. // parse the field data
  1564. if((rc =_cmDataParseArgV( NULL, vl, &vp )) != kOkDtRC )
  1565. {
  1566. contFl = false;
  1567. }
  1568. else
  1569. {
  1570. // create the field pair
  1571. if( idFl )
  1572. cmDataAllocPairId(parent,id,vp);
  1573. else
  1574. cmDataAllocPairLabel(parent,label,vp);
  1575. }
  1576. }
  1577. return rc;
  1578. }
  1579. cmData_t* cmDataRecdAllocLabelV( cmData_t* parent, va_list vl )
  1580. {
  1581. cmData_t* p = cmRecdAlloc(parent);
  1582. cmDtRC_t rc = _cmDataRecdParseInputV(p, false, vl );
  1583. if( rc != kOkDtRC )
  1584. {
  1585. cmDataFree(p);
  1586. p = NULL;
  1587. }
  1588. return p;
  1589. }
  1590. cmData_t* cmDataRecdAllocLabelA( cmData_t* parent, ... )
  1591. {
  1592. va_list vl;
  1593. va_start(vl,parent);
  1594. cmData_t* p = cmDataRecdAllocLabelV(parent,vl);
  1595. va_end(vl);
  1596. return p;
  1597. }
  1598. cmData_t* cmDataRecdAllocIdV( cmData_t* parent, va_list vl )
  1599. {
  1600. cmData_t* p = cmRecdAlloc(parent);
  1601. cmDtRC_t rc = _cmDataRecdParseInputV(p, true, vl );
  1602. if( rc != kOkDtRC )
  1603. {
  1604. cmDataFree(p);
  1605. p = NULL;
  1606. }
  1607. return p;
  1608. }
  1609. cmData_t* cmDataRecdAllocIdA( cmData_t* parent, ... )
  1610. {
  1611. va_list vl;
  1612. va_start(vl,parent);
  1613. cmData_t* p = cmDataRecdAllocIdV(parent,vl);
  1614. va_end(vl);
  1615. return p;
  1616. }
  1617. cmDtRC_t _cmDataRecdParseV(cmData_t* p, bool idFl, cmErr_t* err, va_list vl )
  1618. {
  1619. bool contFl = true;
  1620. cmDtRC_t rc = kOkDtRC;
  1621. while( contFl )
  1622. {
  1623. unsigned id;
  1624. const char* label;
  1625. // parse the field idenfier
  1626. if( idFl )
  1627. id = va_arg(vl,unsigned); // numeric field identifier
  1628. else
  1629. label = va_arg(vl,const char*); // text field label identifier
  1630. // validate the field identifier
  1631. if( (idFl && id==kInvalidDtId) || (!idFl && label==NULL) )
  1632. break;
  1633. cmDataFmtId_t typeId = va_arg(vl,unsigned);
  1634. void* v = va_arg(vl,void*);
  1635. cmData_t* np = NULL;
  1636. if( idFl )
  1637. np = cmDataRecdValueFromLabel( p, label );
  1638. else
  1639. np = cmDataRecdValueFromId( p, id );
  1640. switch(typeId)
  1641. {
  1642. case kNullDtId:
  1643. break;
  1644. case kUCharDtId:
  1645. rc = cmDataGetUChar(np,(unsigned char*)v);
  1646. break;
  1647. case kCharDtId:
  1648. rc = cmDataGetChar(np,(char*)v);
  1649. break;
  1650. case kUShortDtId:
  1651. rc = cmDataGetUShort(np,(unsigned short*)v);
  1652. break;
  1653. case kShortDtId:
  1654. rc = cmDataGetShort(np,(short*)v);
  1655. break;
  1656. case kUIntDtId:
  1657. rc = cmDataGetUInt(np,(unsigned int*)v);
  1658. break;
  1659. case kIntDtId:
  1660. rc = cmDataGetInt(np,(int*)v);
  1661. break;
  1662. case kULongDtId:
  1663. rc = cmDataGetULong(np,(unsigned long*)v);
  1664. break;
  1665. case kLongDtId:
  1666. rc = cmDataGetLong(np,(long*)v);
  1667. break;
  1668. case kFloatDtId:
  1669. rc = cmDataGetFloat(np,(float*)v);
  1670. break;
  1671. case kDoubleDtId:
  1672. rc = cmDataGetDouble(np,(double*)v);
  1673. break;
  1674. case kStrDtId:
  1675. rc = cmDataGetStr(np,(char**)v);
  1676. break;
  1677. case kConstStrDtId:
  1678. rc = cmDataGetConstStr(np,(const char**)v);
  1679. break;
  1680. case kUCharPtrDtId:
  1681. rc = cmDataGetUCharPtr(np,(unsigned char**)v);
  1682. break;
  1683. case kCharPtrDtId:
  1684. rc = cmDataGetCharPtr(np,(char**)v);
  1685. break;
  1686. case kUShortPtrDtId:
  1687. rc = cmDataGetUShortPtr(np,(unsigned short**)v);
  1688. break;
  1689. case kShortPtrDtId:
  1690. rc = cmDataGetShortPtr(np,(short**)v);
  1691. break;
  1692. case kUIntPtrDtId:
  1693. rc = cmDataGetUIntPtr(np,(unsigned int**)v);
  1694. break;
  1695. case kIntPtrDtId:
  1696. rc = cmDataGetIntPtr(np,(int**)v);
  1697. break;
  1698. case kULongPtrDtId:
  1699. rc = cmDataGetULongPtr(np,(unsigned long**)v);
  1700. break;
  1701. case kLongPtrDtId:
  1702. rc = cmDataGetLongPtr(np,(long**)v);
  1703. break;
  1704. case kFloatPtrDtId:
  1705. rc = cmDataGetFloatPtr(np,(float**)v);
  1706. break;
  1707. case kDoublePtrDtId:
  1708. rc = cmDataGetDoublePtr(np,(double**)v);
  1709. break;
  1710. case kVoidPtrDtId:
  1711. rc = cmDataGetVoidPtr(np,(void**)v);
  1712. break;
  1713. case kListDtId:
  1714. case kPairDtId:
  1715. case kRecordDtId:
  1716. if( np->tid != typeId )
  1717. _cmDataSetError(kCvtErrDtRC);
  1718. else
  1719. *(cmData_t**)v = np;
  1720. break;
  1721. default:
  1722. _cmDataSetError(kVarArgErrDtRC);
  1723. assert(0);
  1724. }
  1725. }
  1726. return rc;
  1727. }
  1728. cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, va_list vl )
  1729. { return _cmDataRecdParseV(p,false,err,vl); }
  1730. cmDtRC_t cmDataRecdParseLabel(cmData_t* p, cmErr_t* err, ... )
  1731. {
  1732. va_list vl;
  1733. va_start(vl,err);
  1734. cmDtRC_t rc = cmDataRecdParseLabelV(p,err,vl);
  1735. va_end(vl);
  1736. return rc;
  1737. }
  1738. cmDtRC_t cmDataRecdParseIdV(cmData_t* p, cmErr_t* err, va_list vl )
  1739. { return _cmDataRecdParseV(p,true,err,vl); }
  1740. cmDtRC_t cmDataRecdParseId(cmData_t* p, cmErr_t* err, ... )
  1741. {
  1742. va_list vl;
  1743. va_start(vl,err);
  1744. cmDtRC_t rc = cmDataRecdParseIdV(p,err,vl);
  1745. va_end(vl);
  1746. return rc;
  1747. }
  1748. //----------------------------------------------------------------------------
  1749. unsigned cmDataSerializeByteCount( const cmData_t* p )
  1750. {
  1751. unsigned bn = 0;
  1752. // if this data type has a child then calculate it's size
  1753. if( kMinStructDtId <= p->tid && p->tid <= kMaxStructDtId && p->u.child != NULL )
  1754. bn = cmDataSerializeByteCount(p->u.child);
  1755. // if this data type has siblings get their type
  1756. cmData_t* dp = p->u.child;
  1757. for(; dp != NULL; dp=dp->sibling )
  1758. bn += cmDataSerializeByteCount(dp->sibling);
  1759. //
  1760. return _cmDataByteCount(p) + bn;
  1761. }
  1762. cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt )
  1763. {
  1764. return kOkDtRC;
  1765. }
  1766. cmDtRC_t cmDataDeserialize( const void* buf, unsigned bufByteCnt, cmData_t** pp )
  1767. {
  1768. return kOkDtRC;
  1769. }
  1770. #define parr(rpt,fmt,arr,n) do{int i=0; cmRptPrintf(rpt,"[ "); for(;i<n;++i) cmRptPrintf(rpt,fmt,arr[i]); cmRptPrintf(rpt," ]"); }while(0)
  1771. void _cmDataPrintIndent( cmRpt_t* rpt, unsigned indent )
  1772. {
  1773. unsigned j=0;
  1774. for(; j<indent; ++j)
  1775. cmRptPrintf(rpt," ");
  1776. }
  1777. void _cmDataPrint( const cmData_t* p, cmRpt_t* rpt, unsigned indent )
  1778. {
  1779. cmData_t* cp;
  1780. //_cmDataPrintIndent(rpt,indent);
  1781. switch(p->tid)
  1782. {
  1783. case kNullDtId: cmRptPrintf(rpt,"<null>"); break;
  1784. case kUCharDtId: cmRptPrintf(rpt,"%c ",cmDataUChar(p)); break;
  1785. case kCharDtId: cmRptPrintf(rpt,"%c ",cmDataChar(p)); break;
  1786. case kUShortDtId: cmRptPrintf(rpt,"%i ",cmDataUShort(p)); break;
  1787. case kShortDtId: cmRptPrintf(rpt,"%i ",cmDataShort(p)); break;
  1788. case kUIntDtId: cmRptPrintf(rpt,"%i ",cmDataUInt(p)); break;
  1789. case kIntDtId: cmRptPrintf(rpt,"%i ",cmDataInt(p)); break;
  1790. case kULongDtId: cmRptPrintf(rpt,"%i ",cmDataULong(p)); break;
  1791. case kLongDtId: cmRptPrintf(rpt,"%i ",cmDataLong(p)); break;
  1792. case kFloatDtId: cmRptPrintf(rpt,"%f ",cmDataFloat(p)); break;
  1793. case kDoubleDtId: cmRptPrintf(rpt,"%f ",cmDataDouble(p)); break;
  1794. case kStrDtId: cmRptPrintf(rpt,"%s ",cmDataStr(p)); break;
  1795. case kConstStrDtId: cmRptPrintf(rpt,"%s ",cmDataConstStr(p)); break;
  1796. case kUCharPtrDtId: parr(rpt,"%c ",cmDataUCharPtr(p), p->cnt); break;
  1797. case kCharPtrDtId: parr(rpt,"%c ",cmDataCharPtr(p), p->cnt); break;
  1798. case kUShortPtrDtId: parr(rpt,"%i ",cmDataUShortPtr(p),p->cnt); break;
  1799. case kShortPtrDtId: parr(rpt,"%i ",cmDataShortPtr(p), p->cnt); break;
  1800. case kUIntPtrDtId: parr(rpt,"%i ",cmDataUIntPtr(p), p->cnt); break;
  1801. case kIntPtrDtId: parr(rpt,"%i ",cmDataIntPtr(p), p->cnt); break;
  1802. case kULongPtrDtId: parr(rpt,"%i ",cmDataULongPtr(p), p->cnt); break;
  1803. case kLongPtrDtId: parr(rpt,"%i ",cmDataLongPtr(p), p->cnt); break;
  1804. case kFloatPtrDtId: parr(rpt,"%f ",cmDataFloatPtr(p), p->cnt); break;
  1805. case kDoublePtrDtId: parr(rpt,"%f ",cmDataDoublePtr(p),p->cnt); break;
  1806. case kVoidPtrDtId: cmRptPrintf(rpt,"<void:%i>",p->cnt); break;
  1807. case kPairDtId:
  1808. _cmDataPrint(p->u.child,rpt,indent);
  1809. cmRptPrintf(rpt," : ");
  1810. _cmDataPrint(p->u.child->sibling,rpt,indent);
  1811. cmRptPrintf(rpt,"\n");
  1812. break;
  1813. case kListDtId:
  1814. cmRptPrintf(rpt,"(\n");
  1815. indent += 2;
  1816. cp = p->u.child;
  1817. for(; cp!=NULL; cp=cp->sibling)
  1818. {
  1819. _cmDataPrintIndent(rpt,indent);
  1820. _cmDataPrint(cp,rpt,indent);
  1821. cmRptPrintf(rpt,"\n");
  1822. }
  1823. indent -= 2;
  1824. _cmDataPrintIndent(rpt,indent);
  1825. cmRptPrintf(rpt,")\n");
  1826. break;
  1827. case kRecordDtId:
  1828. cmRptPrintf(rpt,"{\n");
  1829. indent += 2;
  1830. cp = p->u.child;
  1831. for(; cp!=NULL; cp=cp->sibling)
  1832. {
  1833. _cmDataPrintIndent(rpt,indent);
  1834. _cmDataPrint(cp,rpt, indent);
  1835. }
  1836. indent -= 2;
  1837. _cmDataPrintIndent(rpt,indent);
  1838. cmRptPrintf(rpt,"}\n");
  1839. break;
  1840. default:
  1841. break;
  1842. }
  1843. }
  1844. void cmDataPrint( const cmData_t* p, cmRpt_t* rpt )
  1845. { _cmDataPrint(p,rpt,0); }
  1846. void cmDataTest( cmCtx_t* ctx )
  1847. {
  1848. float farr[] = { 1.23, 45.6, 7.89 };
  1849. cmData_t* d0 = cmDataRecdAllocLabelA(NULL,
  1850. "name",kConstStrDtId,"This is a string.",
  1851. "id", kUIntDtId, 21,
  1852. "real",kFloatDtId, 1.23,
  1853. "arr", kFloatPtrDtId, farr, 3,
  1854. NULL);
  1855. cmDataPrint(d0,&ctx->rpt);
  1856. cmDataFree(d0);
  1857. cmData_t* d1 = cmDataListAllocA(NULL,
  1858. kUIntDtId, 53,
  1859. kStrDtId, "Blah blah",
  1860. kFloatPtrDtId, farr, 3,
  1861. kInvalidDtId );
  1862. cmDataPrint(d1,&ctx->rpt);
  1863. cmDataFree(d1);
  1864. cmRptPrintf(&ctx->rpt,"Done!.\n");
  1865. }