libcm is a C development framework with an emphasis on audio signal processing applications.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

cmData.c 66KB

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