libcm is a C development framework with an emphasis on audio signal processing applications.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cmData.c 77KB

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