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 60KB

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