1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300 |
- #include "cmGlobal.h"
- #include "cmRpt.h"
- #include "cmErr.h"
- #include "cmCtx.h"
- #include "cmMem.h"
- #include "cmMallocDebug.h"
- #include "cmLinkedHeap.h"
- #include "cmData.h"
- #include "cmLex.h"
- #include "cmText.h"
- #include "cmStack.h"
-
- typedef struct
- {
- cmDataTypeId_t typeId;
- unsigned byteWidth;
- const cmChar_t* label;
- } cmDtTypeInfo_t;
-
- typedef struct
- {
- cmDataContainerId_t id;
- const cmChar_t* label;
- } cmDtCntInfo_t;
-
- cmDtTypeInfo_t _cmDtTypeInfoArray[] =
- {
- { kNullDtId, 0, "null" },
- { kUCharDtId, sizeof(unsigned char), "uchar" },
- { kCharDtId, sizeof(char), "char" },
- { kUShortDtId, sizeof(unsigned short), "ushort" },
- { kShortDtId, sizeof(short), "short" },
- { kUIntDtId, sizeof(unsigned int), "uint" },
- { kIntDtId, sizeof(int), "int" },
- { kULongDtId, sizeof(unsigned long), "ulong" },
- { kLongDtId, sizeof(long), "long" },
- { kFloatDtId, sizeof(float), "float" },
- { kDoubleDtId, sizeof(double), "double" },
- { kStrDtId, sizeof(char*), "string" },
- { kBlobDtId, sizeof(void*), "blob" },
- { kInvalidTypeDtId, 0, "<invalid-type>" },
- };
-
- cmDtCntInfo_t _cmDtCntInfoArray[] =
- {
- { kScalarDtId, "scalar" },
- { kArrayDtId, "array" },
- { kListDtId, "list" },
- { kPairDtId, "pair" },
- { kRecordDtId, "record"},
- { kInvalidCntDtId,"<invalid-container>"}
- };
-
- cmData_t cmDataNull = { kInvalidTypeDtId,kInvalidCntDtId,0,NULL,NULL,0 };
-
- cmDtRC_t _cmDtErrMsgV( const cmData_t* d, cmDtRC_t rc, const cmChar_t* fmt, va_list vl )
- {
- // REPLACE this with a global cmRpt call.
- vprintf(fmt,vl);
- return rc;
- }
-
- cmDtRC_t _cmDtErrMsg( const cmData_t* d, cmDtRC_t rc, const cmChar_t* fmt, ... )
- {
- va_list vl;
- va_start(vl,fmt);
- rc = _cmDtErrMsgV(d,rc,fmt,vl);
- va_end(vl);
- return rc;
- }
-
- const cmChar_t* cmDataTypeToLabel( cmDataTypeId_t tid )
- {
- unsigned i;
- for(i=0; _cmDtTypeInfoArray[i].typeId!=kInvalidTypeDtId; ++i)
- if( _cmDtTypeInfoArray[i].typeId == tid )
- return _cmDtTypeInfoArray[i].label;
- return NULL;
- }
-
- cmDataTypeId_t cmDataLabelToType( const cmChar_t* typeLabelStr )
- {
- unsigned i;
- for(i=0; _cmDtTypeInfoArray[i].typeId!=kInvalidTypeDtId; ++i)
- if( strcmp(_cmDtTypeInfoArray[i].label,typeLabelStr) == 0 )
- return _cmDtTypeInfoArray[i].typeId;
- return kInvalidTypeDtId;
- }
-
- unsigned cmDataByteWidth( cmDataTypeId_t tid )
- {
- unsigned i;
- for(i=0; _cmDtTypeInfoArray[i].typeId!=kInvalidTypeDtId; ++i)
- if( _cmDtTypeInfoArray[i].typeId == tid )
- return _cmDtTypeInfoArray[i].byteWidth;
- return cmInvalidCnt;
- }
-
- const cmChar_t* cmDataContainerIdToLabel( cmDataContainerId_t tid )
- {
- unsigned i;
- for(i=0; _cmDtCntInfoArray[i].id!=kInvalidCntDtId; ++i)
- if( _cmDtCntInfoArray[i].id == tid )
- return _cmDtCntInfoArray[i].label;
- return NULL;
- }
-
- cmDataContainerId_t cmDataLabelToContainerId( const cmChar_t* contLabelStr )
- {
- unsigned i;
- for(i=0; _cmDtCntInfoArray[i].id!=kInvalidCntDtId; ++i)
- if( strcmp(_cmDtCntInfoArray[i].label,contLabelStr) == 0 )
- return _cmDtCntInfoArray[i].id;
- return kInvalidCntDtId;
- }
-
- bool _cmDataIsDataOwner( const cmData_t* d )
- { return cmIsFlag(d->flags,kFreeValueDtFl) && (d->cid==kArrayDtId || d->tid==kStrDtId || d->tid==kBlobDtId); }
-
-
- cmDtRC_t _cmDataFreeData( cmData_t* d )
- {
- if( _cmDataIsDataOwner(d) )
- {
- // A object marked with kFreeValueDtFl should never also be 'const.
- // (??? is this true ???? )
- assert( cmIsNotFlag(d->flags,kConstValueDtFl) );
-
- cmMemPtrFree(&d->u.vp);
- }
-
- d->flags = cmClrFlag(d->flags,kFreeValueDtFl | kConstValueDtFl );
- d->tid = kNullDtId; // objects without data are always of type 'null'.
- d->cnt = 0;
- memset(&d->u,0,sizeof(d->u));
- return kOkDtRC;
- }
-
- void _cmDataFree( cmData_t* p )
- {
- if( p == NULL )
- return;
-
- if( cmDataIsStruct(p) )
- {
- cmData_t* cp = p->u.child;
- for(; cp!=NULL; cp=cp->sibling)
- _cmDataFree(cp);
- }
-
- _cmDataFreeData(p);
-
- if( cmIsFlag(p->flags,kFreeObjDtFl) )
- cmMemFree(p);
- }
-
- /*
- cmData_t* _cmDataAllocNode( cmData_t* parent, cmDataFmtId_t tid )
- {
- cmData_t* p = cmMemAllocZ(cmData_t,1);
- p->tid = tid;
- p->flags = kDynObjDtFl;
- p->parent = parent;
- if( parent != NULL )
- return cmDataAppendChild(parent,p);
- return p;
- }
- */
-
-
- // Dynamically allocate a 'null' data object.
- cmDtRC_t _cmDataNew(cmData_t* parent, cmData_t** ref)
- {
- cmData_t* d = cmMemAllocZ(cmData_t,1);
- d->tid = kNullDtId; // objects without data are of type 'null'.
- d->cid = kScalarDtId;
- d->flags = kFreeObjDtFl;
- d->parent = parent;
- d->cnt = 0;
-
- if( parent != NULL )
- cmDataAppendChild(parent,d);
-
- *ref = d;
- return kOkDtRC;
- }
-
-
- bool cmDataIsConstObj( const cmData_t* d )
- { return cmIsFlag(d->flags,kConstObjDtFl); }
-
- void cmDataEnableConstObj( cmData_t* d, bool enaFl )
- { d->flags = cmEnaFlag(d->flags,kConstObjDtFl,enaFl); }
-
- bool cmDataIsConstValue( const cmData_t* d )
- { return cmIsFlag(d->flags,kConstValueDtFl); }
-
- void cmDataEnableConstValue( cmData_t* d, bool enaFl )
- { d->flags = cmEnaFlag(d->flags,kConstValueDtFl,enaFl); }
-
- bool cmDataIsFreeValue( const cmData_t* d )
- { return cmIsFlag(d->flags,kFreeValueDtFl); }
-
- void cmDataEnableFreeValue( cmData_t* d, bool enaFl )
- { d->flags = cmEnaFlag(d->flags,kFreeValueDtFl,enaFl); }
-
- bool cmDataIsLeaf( const cmData_t* d)
- { return d->cid == kScalarDtId || d->cid == kArrayDtId; }
-
- bool cmDataIsStruct( const cmData_t* d )
- { return !cmDataIsLeaf(d); }
-
-
- cmDtRC_t cmDataNewScalar( cmData_t* parent, cmDataTypeId_t tid, unsigned flags, void* vp, unsigned byteCnt, cmData_t** ref )
- {
- cmData_t* d = NULL;
- cmDtRC_t rc;
-
- *ref = NULL;
-
- // create a scalar null object
- if((rc = _cmDataNew(parent,&d)) != kOkDtRC )
- return rc;
-
- if( tid!=kStrDtId && tid!=kBlobDtId )
- {
- // When used with scalars kFreeValueDtFl and kNoCopyDtFl only
- // has meaning for strings and blobs - so clear these flags for other types.
- flags = cmClrFlag(flags,kFreeValueDtFl | kNoCopyDtFl);
-
- // if this is not a blob or string then the byteCnt is reset
- byteCnt = cmDataByteWidth(tid);
- }
-
-
-
- // assign the value
- if((rc = cmDataSetScalarValue(d,tid,vp,byteCnt,flags)) != kOkDtRC )
- return rc;
-
- // set the const flags for the new object
- d->flags = cmSetFlag(d->flags, flags & (kConstValueDtFl | kConstObjDtFl));
-
- *ref = d;
-
- return rc;
- }
-
- cmDtRC_t cmDataNewNull( cmData_t* parent, unsigned flags, cmData_t** ref )
- { return _cmDataNew(parent, ref); }
- cmDtRC_t cmDataNewChar( cmData_t* parent, unsigned flags, char v, cmData_t** ref )
- { return cmDataNewScalar(parent,kCharDtId,flags,&v,0,ref); }
- cmDtRC_t cmDataNewUChar( cmData_t* parent, unsigned flags, unsigned char v, cmData_t** ref )
- { return cmDataNewScalar(parent,kUCharDtId,flags,&v,0,ref); }
- cmDtRC_t cmDataNewShort( cmData_t* parent, unsigned flags, short v, cmData_t** ref )
- { return cmDataNewScalar(parent,kShortDtId,flags,&v,0,ref); }
- cmDtRC_t cmDataNewUShort( cmData_t* parent, unsigned flags, unsigned short v, cmData_t** ref )
- { return cmDataNewScalar(parent,kUShortDtId,flags,&v,0,ref); }
- cmDtRC_t cmDataNewInt( cmData_t* parent, unsigned flags, int v, cmData_t** ref )
- { return cmDataNewScalar(parent,kIntDtId,flags,&v,0,ref); }
- cmDtRC_t cmDataNewUInt( cmData_t* parent, unsigned flags, unsigned int v, cmData_t** ref )
- { return cmDataNewScalar(parent,kUIntDtId,flags,&v,0,ref); }
- cmDtRC_t cmDataNewLong( cmData_t* parent, unsigned flags, long v, cmData_t** ref )
- { return cmDataNewScalar(parent,kLongDtId,flags,&v,0,ref); }
- cmDtRC_t cmDataNewULong( cmData_t* parent, unsigned flags, unsigned long v, cmData_t** ref )
- { return cmDataNewScalar(parent,kULongDtId,flags,&v,0,ref); }
- cmDtRC_t cmDataNewFloat( cmData_t* parent, unsigned flags, float v, cmData_t** ref )
- { return cmDataNewScalar(parent,kFloatDtId,flags,&v,0,ref); }
- cmDtRC_t cmDataNewDouble( cmData_t* parent, unsigned flags, double v, cmData_t** ref )
- { return cmDataNewScalar(parent,kDoubleDtId,flags,&v,0,ref); }
- cmDtRC_t cmDataNewStr( cmData_t* parent, unsigned flags, cmChar_t* v, cmData_t** ref )
- { return cmDataNewScalar(parent,kStrDtId,flags,v,strlen(v)+1,ref); }
- cmDtRC_t cmDataNewConstStr( cmData_t* parent, unsigned flags, const cmChar_t* v, cmData_t** ref )
- { return cmDataNewScalar(parent,kStrDtId,flags | kConstValueDtFl, (void*)v,strlen(v)+1,ref); }
- cmDtRC_t cmDataNewStrN( cmData_t* parent, unsigned flags, cmChar_t* v, unsigned charCnt, cmData_t** ref )
- { return cmDataNewScalar(parent,kStrDtId,flags,v,charCnt+1,ref); }
- cmDtRC_t cmDataNewConstStrN( cmData_t* parent, unsigned flags, const cmChar_t* v, unsigned charCnt, cmData_t** ref )
- { return cmDataNewScalar(parent,kStrDtId,flags | kConstValueDtFl, (void*)v,charCnt+1,ref); }
- cmDtRC_t cmDataNewBlob( cmData_t* parent, unsigned flags, void* v, unsigned byteCnt, cmData_t** ref )
- { return cmDataNewScalar(parent,kBlobDtId,flags,v,byteCnt,ref); }
- cmDtRC_t cmDataNewConstBlob( cmData_t* parent, unsigned flags, const void* v, unsigned byteCnt, cmData_t** ref )
- { return cmDataNewScalar(parent,kBlobDtId,flags | kConstValueDtFl, (void*)v,byteCnt,ref); }
-
-
- cmDtRC_t cmDataSetScalarValue( cmData_t* d, cmDataTypeId_t tid, void* vp, unsigned byteCnt, unsigned flags )
- {
- cmDtRC_t rc;
-
- // if the type of the object is changing
- if( d->tid != tid || d->cid != kScalarDtId )
- {
- // verify that it is legal to change the type of the object
- if( cmIsFlag(d->flags,kConstObjDtFl) )
- return _cmDtErrMsg(d,kConstErrDtRC,"Const object violation.");
-
- // convert this to a scalar null object.
- if((rc = _cmDataFreeData(d)) != kOkDtRC )
- return rc;
- }
-
- // verify that it is legal to change the value of this object
- if( cmIsFlag(d->flags,kConstValueDtFl) )
- return _cmDtErrMsg(d,kConstErrDtRC,"Const value violation.");
-
- switch( tid )
- {
- case kInvalidTypeDtId:
- return _cmDtErrMsg(d,kAssertErrDtRC,"Invalid data type.");
-
- case kNullDtId: // 'd' is already NULL.
- break;
-
- case kUCharDtId: d->u.uc = *(unsigned char*)vp; break;
- case kCharDtId: d->u.c = *(char*)vp; break;
- case kUShortDtId: d->u.us = *(unsigned short*)vp; break;
- case kShortDtId: d->u.s = *(short*)vp; break;
- case kUIntDtId: d->u.ui = *(unsigned int*)vp; break;
- case kIntDtId: d->u.i = *(int*)vp; break;
- case kULongDtId: d->u.ul = *(unsigned long*)vp; break;
- case kLongDtId: d->u.l = *(long*)vp; break;
- case kFloatDtId: d->u.f = *(float*)vp; break;
- case kDoubleDtId: d->u.d = *(double*)vp; break;
- case kStrDtId:
- case kBlobDtId:
- {
- cmChar_t* blankStr = "";
-
- // strings must have a byteCnt of at least one
- assert( tid==kBlobDtId || (tid==kStrDtId && byteCnt>0) );
-
- // if a NULL source string is encountered then make it a 0 length string
- if( d->tid==kStrDtId && vp==NULL )
- vp = blankStr;
-
- // if an empty blob was passed in then be sure it's src ptr is NULL and byteCnt==0
- if( d->tid==kBlobDtId && (vp==NULL || byteCnt==0) )
- {
- if((rc = _cmDataFreeData(d)) != kOkDtRC )
- return rc;
-
- byteCnt = 0;
- d->u.z = NULL;
- break;
- }
-
- // if the incoming string/blob should be internally duplicated
- if( cmIsNotFlag(flags,kNoCopyDtFl) )
- {
-
- // allocate internal space to store the incoming data
- if( (d->tid==kBlobDtId || d->tid == kStrDtId) && cmIsFlag(d->flags,kFreeValueDtFl) )
- d->u.z = cmMemResize(char,d->u.z,byteCnt);
- else
- d->u.z = cmMemAlloc(char,byteCnt);
-
- // store the source string/blob into the internal memory buffer
- memcpy(d->u.z,vp,byteCnt);
-
- // by default the system now takes responsibility for freeing this buffer
- d->flags |= kFreeValueDtFl;
- }
- else // the incoming string/blob pointer is simply being assigned w/o duplication
- {
- // free the objects previous value ...
- if((rc = _cmDataFreeData(d)) != kOkDtRC )
- return rc;
-
- // and assign the new value (without reallocating the string)
- d->u.z = vp;
-
- d->flags = cmEnaFlag(d->flags,kFreeValueDtFl,cmIsFlag(flags,kFreeValueDtFl));
- d->flags |= kNoCopyDtFl;
- }
- }
- break;
-
- default:
- break;
- }
-
- // we can't set this above because the string type relies
- // on knowing the previous type of the object
- d->cid = kScalarDtId;
- d->tid = tid;
- d->cnt = byteCnt;
- return rc;
- }
-
- cmDtRC_t cmDataSetNull( cmData_t* d )
- { return cmDataSetScalarValue(d, kNullDtId, NULL, 0, kNoFlagsDtFl ); }
- cmDtRC_t cmDataSetChar( cmData_t* d, char v )
- { return cmDataSetScalarValue(d, kCharDtId, &v, 0, kNoFlagsDtFl ); }
- cmDtRC_t cmDataSetUChar( cmData_t* d, unsigned char v )
- { return cmDataSetScalarValue(d, kUCharDtId, &v, 0, kNoFlagsDtFl ); }
- cmDtRC_t cmDataSetShort( cmData_t* d, short v )
- { return cmDataSetScalarValue(d, kShortDtId, &v, 0, kNoFlagsDtFl ); }
- cmDtRC_t cmDataSetUShort( cmData_t* d, unsigned short v )
- { return cmDataSetScalarValue(d, kUShortDtId, &v, 0, kNoFlagsDtFl ); }
- cmDtRC_t cmDataSetInt( cmData_t* d, int v )
- { return cmDataSetScalarValue(d, kIntDtId, &v, 0, kNoFlagsDtFl ); }
- cmDtRC_t cmDataSetUInt( cmData_t* d, unsigned int v )
- { return cmDataSetScalarValue(d, kUIntDtId, &v, 0, kNoFlagsDtFl ); }
- cmDtRC_t cmDataSetLong( cmData_t* d, long v )
- { return cmDataSetScalarValue(d, kLongDtId, &v, 0, kNoFlagsDtFl ); }
- cmDtRC_t cmDataSetULong( cmData_t* d, unsigned long v )
- { return cmDataSetScalarValue(d, kULongDtId, &v, 0, kNoFlagsDtFl ); }
- cmDtRC_t cmDataSetFloat( cmData_t* d, float v )
- { return cmDataSetScalarValue(d, kFloatDtId, &v, 0, kNoFlagsDtFl ); }
- cmDtRC_t cmDataSetDouble( cmData_t* d, double v )
- { return cmDataSetScalarValue(d, kDoubleDtId, &v, 0, kNoFlagsDtFl ); }
- cmDtRC_t cmDataSetStr( cmData_t* d, unsigned flags, cmChar_t* v )
- { return cmDataSetScalarValue(d, kStrDtId, v, v==NULL ? 1 : strlen(v)+1, flags ); }
- cmDtRC_t cmDataSetConstStr( cmData_t* d, unsigned flags, const cmChar_t* v )
- { return cmDataSetScalarValue(d, kStrDtId, (void*)v, v==NULL ? 1 : strlen(v)+1, flags |= kConstValueDtFl ); }
- cmDtRC_t cmDataSetStrN( cmData_t* d, unsigned flags, cmChar_t* v, unsigned charCnt )
- { return cmDataSetScalarValue(d, kStrDtId, (void*)v, v==NULL ? 1 : charCnt+1, flags); }
- cmDtRC_t cmDataSetConstStrN( cmData_t* d, unsigned flags, const cmChar_t* v, unsigned charCnt )
- { return cmDataSetScalarValue(d, kStrDtId, (void*)v, v==NULL ? 1 : charCnt+1, flags |= kConstValueDtFl); }
- cmDtRC_t cmDataSetBlob( cmData_t* d, unsigned flags, void* v, unsigned byteCnt )
- { return cmDataSetScalarValue(d, kBlobDtId, v, byteCnt, flags); }
- cmDtRC_t cmDataSetConstBlob( cmData_t* d, unsigned flags, const void* v, unsigned byteCnt )
- { return cmDataSetScalarValue(d, kBlobDtId, (void*)v, byteCnt, flags |= kConstValueDtFl); }
-
-
-
- cmDtRC_t cmDataChar( const cmData_t* d, char* v )
- {
- if( d->tid != kCharDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:char but encountered type:%s.",cmDataTypeToLabel(d->tid));
- *v = d->u.c;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataUChar( const cmData_t* d, unsigned char* v )
- {
- if( d->tid != kUCharDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:uchar but encountered type:%s.",cmDataTypeToLabel(d->tid));
- *v = d->u.uc;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataShort( const cmData_t* d, short* v )
- {
- if( d->tid != kShortDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:short but encountered type:%s.",cmDataTypeToLabel(d->tid));
- *v = d->u.s;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataUShort( const cmData_t* d, unsigned short* v )
- {
- if( d->tid != kUShortDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:ushort but encountered type:%s.",cmDataTypeToLabel(d->tid));
- *v = d->u.us;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataInt( const cmData_t* d, int* v )
- {
- if( d->tid != kIntDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:int but encountered type:%s.",cmDataTypeToLabel(d->tid));
- *v = d->u.i;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataUInt( const cmData_t* d, unsigned int* v )
- {
- if( d->tid != kUIntDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:uint but encountered type:%s.",cmDataTypeToLabel(d->tid));
- *v = d->u.ui;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataLong( const cmData_t* d, long* v )
- {
- if( d->tid != kLongDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:long but encountered type:%s.",cmDataTypeToLabel(d->tid));
- *v = d->u.l;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataULong( const cmData_t* d, unsigned long* v )
- {
- if( d->tid != kULongDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:ulong but encountered type:%s.",cmDataTypeToLabel(d->tid));
- *v = d->u.ul;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataFloat( const cmData_t* d, float* v )
- {
- if( d->tid != kFloatDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:float but encountered type:%s.",cmDataTypeToLabel(d->tid));
- *v = d->u.f;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataDouble( const cmData_t* d, double* v )
- {
- if( d->tid != kDoubleDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:double but encountered type:%s.",cmDataTypeToLabel(d->tid));
- *v = d->u.d;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataStr( const cmData_t* d, cmChar_t** v )
- {
- if( d->tid != kStrDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:string but encountered type:%s.",cmDataTypeToLabel(d->tid));
-
- if( cmIsFlag(d->flags,kConstValueDtFl) )
- return _cmDtErrMsg(d,kConstErrDtRC,"A const string cannot return as a non-const string.");
-
- *v = d->u.z;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataConstStr( const cmData_t* d, const cmChar_t** v )
- {
- if( d->tid != kStrDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:string but encountered type:%s.",cmDataTypeToLabel(d->tid));
-
- *v = d->u.z;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataBlob( const cmData_t* d, cmChar_t** v, unsigned* byteCntRef )
- {
- if( v != NULL )
- *v = NULL;
-
- if( byteCntRef != NULL )
- *byteCntRef = 0;
-
- if( d->tid != kBlobDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:string but encountered type:%s.",cmDataTypeToLabel(d->tid));
-
- if( v != NULL )
- *v = d->u.z;
-
- if( byteCntRef != NULL )
- *byteCntRef = d->cnt;
-
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataConstBlob( const cmData_t* d, const cmChar_t** v, unsigned* byteCntRef )
- {
- if( v != NULL )
- *v = NULL;
-
- if( byteCntRef != NULL )
- *byteCntRef = 0;
-
- if( d->tid != kBlobDtId )
- return _cmDtErrMsg(d,kInvalidTypeDtRC,"Expected type:string but encountered type:%s.",cmDataTypeToLabel(d->tid));
-
- if( v != NULL )
- *v = d->u.z;
-
- if( byteCntRef != NULL )
- *byteCntRef = d->cnt;
-
- return kOkDtRC;
- }
-
-
- cmDtRC_t cmDataGetUChar( const cmData_t* p, unsigned char* vp )
- {
- if( p->cid != kScalarDtId )
- return _cmDtErrMsg(p,kInvalidContDtRC,"Cannot convert a non-scalar value to a scalar value.");
-
- switch( p->tid )
- {
- case kUCharDtId: *vp = p->u.uc; break;
- case kCharDtId: *vp = (unsigned char)p->u.c; break;
- case kUShortDtId: *vp = (unsigned char)p->u.us; break;
- case kShortDtId: *vp = (unsigned char)p->u.s; break;
- case kUIntDtId: *vp = (unsigned char)p->u.ui; break;
- case kIntDtId: *vp = (unsigned char)p->u.i; break;
- case kULongDtId: *vp = (unsigned char)p->u.ul; break;
- case kLongDtId: *vp = (unsigned char)p->u.l; break;
- case kFloatDtId: *vp = (unsigned char)p->u.f; break;
- case kDoubleDtId: *vp = (unsigned char)p->u.d; break;
- default:
- return _cmDtErrMsg(p,kCvtErrDtRC,"Cannot convert '%s' to 'uchar'.",cmDataTypeToLabel(p->tid));
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetChar( const cmData_t* p, char* vp )
- {
- if( p->cid != kScalarDtId )
- return _cmDtErrMsg(p,kInvalidContDtRC,"Cannot convert a non-scalar value to a scalar value.");
-
- switch( p->tid )
- {
- case kUCharDtId: *vp = (char)p->u.uc; break;
- case kCharDtId: *vp = p->u.c; break;
- case kUShortDtId: *vp = (char)p->u.us; break;
- case kShortDtId: *vp = (char)p->u.s; break;
- case kUIntDtId: *vp = (char)p->u.ui; break;
- case kIntDtId: *vp = (char)p->u.i; break;
- case kULongDtId: *vp = (char)p->u.ul; break;
- case kLongDtId: *vp = (char)p->u.l; break;
- case kFloatDtId: *vp = (char)p->u.f; break;
- case kDoubleDtId: *vp = (char)p->u.d; break;
- default:
- return _cmDtErrMsg(p,kCvtErrDtRC,"Cannot convert '%s' to 'char'.",cmDataTypeToLabel(p->tid));
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetShort( const cmData_t* p, short* vp )
- {
- if( p->cid != kScalarDtId )
- return _cmDtErrMsg(p,kInvalidContDtRC,"Cannot convert a non-scalar value to a scalar value.");
-
- switch( p->tid )
- {
- case kUCharDtId: *vp = (short)p->u.uc; break;
- case kCharDtId: *vp = (short)p->u.c; break;
- case kUShortDtId: *vp = (short)p->u.us; break;
- case kShortDtId: *vp = p->u.s; break;
- case kUIntDtId: *vp = (short)p->u.ui; break;
- case kIntDtId: *vp = (short)p->u.i; break;
- case kULongDtId: *vp = (short)p->u.ul; break;
- case kLongDtId: *vp = (short)p->u.l; break;
- case kFloatDtId: *vp = (short)p->u.f; break;
- case kDoubleDtId: *vp = (short)p->u.d; break;
- default:
- return _cmDtErrMsg(p,kCvtErrDtRC,"Cannot convert '%s' to 'short'.",cmDataTypeToLabel(p->tid));
-
- }
- return kOkDtRC;
- }
-
-
- cmDtRC_t cmDataGetUShort( const cmData_t* p, unsigned short* vp )
- {
- if( p->cid != kScalarDtId )
- return _cmDtErrMsg(p,kInvalidContDtRC,"Cannot convert a non-scalar value to a scalar value.");
-
- switch( p->tid )
- {
- case kUCharDtId: *vp = (unsigned short)p->u.uc; break;
- case kCharDtId: *vp = (unsigned short)p->u.c; break;
- case kUShortDtId: *vp = p->u.us; break;
- case kShortDtId: *vp = (unsigned short)p->u.s; break;
- case kUIntDtId: *vp = (unsigned short)p->u.ui; break;
- case kIntDtId: *vp = (unsigned short)p->u.i; break;
- case kULongDtId: *vp = (unsigned short)p->u.ul; break;
- case kLongDtId: *vp = (unsigned short)p->u.l; break;
- case kFloatDtId: *vp = (unsigned short)p->u.f; break;
- case kDoubleDtId: *vp = (unsigned short)p->u.d; break;
- default:
- return _cmDtErrMsg(p,kCvtErrDtRC,"Cannot convert '%s' to 'ushort'.",cmDataTypeToLabel(p->tid));
-
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetInt( const cmData_t* p, int* vp )
- {
- if( p->cid != kScalarDtId )
- return _cmDtErrMsg(p,kInvalidContDtRC,"Cannot convert a non-scalar value to a scalar value.");
-
- switch( p->tid )
- {
- case kUCharDtId: *vp = (int)p->u.uc; break;
- case kCharDtId: *vp = (int)p->u.c; break;
- case kUShortDtId: *vp = (int)p->u.us; break;
- case kShortDtId: *vp = (int)p->u.s; break;
- case kUIntDtId: *vp = (int)p->u.ui; break;
- case kIntDtId: *vp = p->u.i; break;
- case kULongDtId: *vp = (int)p->u.ul; break;
- case kLongDtId: *vp = (int)p->u.l; break;
- case kFloatDtId: *vp = (int)p->u.f; break;
- case kDoubleDtId: *vp = (int)p->u.d; break;
- default:
- return _cmDtErrMsg(p,kCvtErrDtRC,"Cannot convert '%s' to 'int'.",cmDataTypeToLabel(p->tid));
-
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetUInt( const cmData_t* p, unsigned int* vp )
- {
- if( p->cid != kScalarDtId )
- return _cmDtErrMsg(p,kInvalidContDtRC,"Cannot convert a non-scalar value to a scalar value.");
-
- switch( p->tid )
- {
- case kUCharDtId: *vp = (unsigned int)p->u.uc; break;
- case kCharDtId: *vp = (unsigned int)p->u.c; break;
- case kUShortDtId: *vp = (unsigned int)p->u.us; break;
- case kShortDtId: *vp = (unsigned int)p->u.s; break;
- case kUIntDtId: *vp = p->u.ui; break;
- case kIntDtId: *vp = (unsigned int)p->u.i; break;
- case kULongDtId: *vp = (unsigned int)p->u.ul; break;
- case kLongDtId: *vp = (unsigned int)p->u.l; break;
- case kFloatDtId: *vp = (unsigned int)p->u.f; break;
- case kDoubleDtId: *vp = (unsigned int)p->u.d; break;
- default:
- return _cmDtErrMsg(p,kCvtErrDtRC,"Cannot convert '%s' to 'uint'.",cmDataTypeToLabel(p->tid));
-
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetLong( const cmData_t* p, long* vp )
- {
- if( p->cid != kScalarDtId )
- return _cmDtErrMsg(p,kInvalidContDtRC,"Cannot convert a non-scalar value to a scalar value.");
-
- switch( p->tid )
- {
- case kUCharDtId: *vp = (long)p->u.uc; break;
- case kCharDtId: *vp = (long)p->u.c; break;
- case kUShortDtId: *vp = (long)p->u.us; break;
- case kShortDtId: *vp = (long)p->u.s; break;
- case kUIntDtId: *vp = (long)p->u.ui; break;
- case kIntDtId: *vp = (long)p->u.i; break;
- case kULongDtId: *vp = (long)p->u.ul; break;
- case kLongDtId: *vp = p->u.l; break;
- case kFloatDtId: *vp = (long)p->u.f; break;
- case kDoubleDtId: *vp = (long)p->u.d; break;
- default:
- return _cmDtErrMsg(p,kCvtErrDtRC,"Cannot convert '%s' to 'long'.",cmDataTypeToLabel(p->tid));
-
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetULong( const cmData_t* p, unsigned long* vp )
- {
- if( p->cid != kScalarDtId )
- return _cmDtErrMsg(p,kInvalidContDtRC,"Cannot convert a non-scalar value to a scalar value.");
-
- switch( p->tid )
- {
- case kUCharDtId: *vp = (unsigned long)p->u.uc; break;
- case kCharDtId: *vp = (unsigned long)p->u.c; break;
- case kUShortDtId: *vp = (unsigned long)p->u.us; break;
- case kShortDtId: *vp = (unsigned long)p->u.s; break;
- case kUIntDtId: *vp = (unsigned long)p->u.ui; break;
- case kIntDtId: *vp = (unsigned long)p->u.i; break;
- case kULongDtId: *vp = p->u.ul; break;
- case kLongDtId: *vp = (unsigned long)p->u.l; break;
- case kFloatDtId: *vp = (unsigned long)p->u.f; break;
- case kDoubleDtId: *vp = (unsigned long)p->u.d; break;
- default:
- return _cmDtErrMsg(p,kCvtErrDtRC,"Cannot convert '%s' to 'ulong'.",cmDataTypeToLabel(p->tid));
-
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetFloat( const cmData_t* p, float* vp )
- {
- if( p->cid != kScalarDtId )
- return _cmDtErrMsg(p,kInvalidContDtRC,"Cannot convert a non-scalar value to a scalar value.");
-
- switch( p->tid )
- {
- case kUCharDtId: *vp = (float)p->u.uc; break;
- case kCharDtId: *vp = (float)p->u.c; break;
- case kUShortDtId: *vp = (float)p->u.us; break;
- case kShortDtId: *vp = (float)p->u.s; break;
- case kUIntDtId: *vp = (float)p->u.ui; break;
- case kIntDtId: *vp = (float)p->u.i; break;
- case kULongDtId: *vp = (float)p->u.ul; break;
- case kLongDtId: *vp = (float)p->u.l; break;
- case kFloatDtId: *vp = p->u.f; break;
- case kDoubleDtId: *vp = (float)p->u.d; break;
- default:
- return _cmDtErrMsg(p,kCvtErrDtRC,"Cannot convert '%s' to 'float'.",cmDataTypeToLabel(p->tid));
-
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetDouble( const cmData_t* p, double* vp )
- {
- if( p->cid != kScalarDtId )
- return _cmDtErrMsg(p,kInvalidContDtRC,"Cannot convert a non-scalar value to a scalar value.");
-
- switch( p->tid )
- {
- case kUCharDtId: *vp = (double)p->u.uc; break;
- case kCharDtId: *vp = (double)p->u.c; break;
- case kUShortDtId: *vp = (double)p->u.us; break;
- case kShortDtId: *vp = (double)p->u.s; break;
- case kUIntDtId: *vp = (double)p->u.ui; break;
- case kIntDtId: *vp = (double)p->u.i; break;
- case kULongDtId: *vp = (double)p->u.ul; break;
- case kLongDtId: *vp = (double)p->u.l; break;
- case kFloatDtId: *vp = (double)p->u.f; break;
- case kDoubleDtId: *vp = p->u.d; break;
- default:
- return _cmDtErrMsg(p,kCvtErrDtRC,"Cannot convert '%s' to 'double'.",cmDataTypeToLabel(p->tid));
-
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataNewArray( cmData_t* parent, cmDataTypeId_t tid, void* vp, unsigned eleCnt, unsigned flags, cmData_t** ref )
- {
- cmDtRC_t rc;
- cmData_t* d = NULL;
-
- *ref = NULL;
-
- // create a new 'null' object
- if((rc = _cmDataNew(parent, &d)) != kOkDtRC )
- return rc;
-
- // assign the value
- if((rc = cmDataSetArrayValue(d,tid,vp,eleCnt,flags)) != kOkDtRC )
- return rc;
-
- // set the flags for the new object
- d->flags = cmSetFlag(d->flags, flags & (kConstValueDtFl | kConstObjDtFl | kNoCopyDtFl));
-
- *ref = d;
-
- return rc;
-
- }
-
- cmDtRC_t cmDataNewCharArray( cmData_t* parent, char* v, unsigned eleCnt, unsigned flags, cmData_t** ref )
- { return cmDataNewArray(parent, kCharDtId, v, eleCnt, flags, ref ); }
- cmDtRC_t cmDataNewUCharArray( cmData_t* parent, unsigned char* v, unsigned eleCnt, unsigned flags, cmData_t** ref )
- { return cmDataNewArray(parent, kUCharDtId, v, eleCnt, flags, ref ); }
- cmDtRC_t cmDataNewShortArray( cmData_t* parent, short* v, unsigned eleCnt, unsigned flags, cmData_t** ref )
- { return cmDataNewArray(parent, kShortDtId, v, eleCnt, flags, ref ); }
- cmDtRC_t cmDataNewUShortArray( cmData_t* parent, unsigned short* v, unsigned eleCnt, unsigned flags, cmData_t** ref )
- { return cmDataNewArray(parent, kUShortDtId, v, eleCnt, flags, ref ); }
- cmDtRC_t cmDataNewIntArray( cmData_t* parent, int* v, unsigned eleCnt, unsigned flags, cmData_t** ref )
- { return cmDataNewArray(parent, kIntDtId, v, eleCnt, flags, ref ); }
- cmDtRC_t cmDataNewUIntArray( cmData_t* parent, unsigned int* v, unsigned eleCnt, unsigned flags, cmData_t** ref )
- { return cmDataNewArray(parent, kUIntDtId, v, eleCnt, flags, ref ); }
- cmDtRC_t cmDataNewLongArray( cmData_t* parent, long* v, unsigned eleCnt, unsigned flags, cmData_t** ref )
- { return cmDataNewArray(parent, kLongDtId, v, eleCnt, flags, ref ); }
- cmDtRC_t cmDataNewULongArray( cmData_t* parent, unsigned long* v, unsigned eleCnt, unsigned flags, cmData_t** ref )
- { return cmDataNewArray(parent, kULongDtId, v, eleCnt, flags, ref ); }
- cmDtRC_t cmDataNewFloatArray( cmData_t* parent, float* v, unsigned eleCnt, unsigned flags, cmData_t** ref )
- { return cmDataNewArray(parent, kFloatDtId, v, eleCnt, flags, ref ); }
- cmDtRC_t cmDataNewDoubleArray( cmData_t* parent, double* v, unsigned eleCnt, unsigned flags, cmData_t** ref )
- { return cmDataNewArray(parent, kDoubleDtId, v, eleCnt, flags, ref ); }
- cmDtRC_t cmDataNewStrArray( cmData_t* parent, cmChar_t** v, unsigned eleCnt, unsigned flags, cmData_t** ref )
- { return cmDataNewArray(parent, kStrDtId, v, eleCnt, flags, ref ); }
- cmDtRC_t cmDataNewConstStrArray( cmData_t* parent, const cmChar_t** v,unsigned eleCnt, unsigned flags, cmData_t** ref )
- { return cmDataNewArray(parent, kStrDtId, (cmChar_t**)v, eleCnt, flags, ref ); }
-
-
- cmDtRC_t cmDataSetArrayValue( cmData_t* d, cmDataTypeId_t tid, void* vp, unsigned eleCnt, unsigned flags )
- {
- cmDtRC_t rc = kOkDtRC;
-
- // if the type of the object is changing
- if( d->tid != tid || d->cid != kScalarDtId )
- {
- // verify that it is legal to change the type of the object
- if( cmIsFlag(d->flags,kConstObjDtFl) )
- return _cmDtErrMsg(d,kConstErrDtRC,"Const object violation.");
-
- // convert this to a scalar null object.
- if((rc = _cmDataFreeData(d)) != kOkDtRC )
- return rc;
- }
-
- // verify that it is legal to change the value of this object
- if( cmIsFlag(d->flags,kConstValueDtFl) )
- return _cmDtErrMsg(d,kConstErrDtRC,"Const value violation.");
-
-
- // if the array should be reallocated
- if( cmIsNotFlag(flags,kNoCopyDtFl) )
- {
- unsigned byteCnt = cmDataByteWidth(tid) * eleCnt;
-
- // reallocate a new string
- if( d->cid == kArrayDtId && cmIsFlag(d->flags,kFreeValueDtFl) )
- d->u.vp = cmMemResize(char,d->u.z,byteCnt);
- else
- d->u.vp = cmMemAlloc(char,byteCnt);
-
- memcpy(d->u.z,vp,byteCnt);
-
- d->flags |= kFreeValueDtFl;
- }
- else
- {
- // free the previous value ...
- if((rc = _cmDataFreeData(d)) != kOkDtRC )
- return rc;
-
- // and assign the new value (without reallocating the array)
- d->u.vp = vp;
-
- d->flags = cmEnaFlag(d->flags,kFreeValueDtFl,cmIsFlag(flags,kFreeValueDtFl));
-
- }
-
- // we can't set this above because the string type relies
- // on knowing the previous type of the object
- d->cid = kArrayDtId;
- d->tid = tid;
- d->cnt = eleCnt;
-
- return rc;
-
- }
-
- cmDtRC_t cmDataSetCharArray( cmData_t* d, char* v, unsigned eleCnt, unsigned flags )
- { return cmDataSetArrayValue(d, kCharDtId, v, eleCnt, flags ); }
- cmDtRC_t cmDataSetUCharArray( cmData_t* d, unsigned char* v, unsigned eleCnt, unsigned flags )
- { return cmDataSetArrayValue(d, kUCharDtId, v, eleCnt, flags ); }
- cmDtRC_t cmDataSetShortArray( cmData_t* d, short* v, unsigned eleCnt, unsigned flags )
- { return cmDataSetArrayValue(d, kShortDtId, v, eleCnt, flags ); }
- cmDtRC_t cmDataSetUShortArray( cmData_t* d, unsigned short* v, unsigned eleCnt, unsigned flags )
- { return cmDataSetArrayValue(d, kUShortDtId, v, eleCnt, flags ); }
- cmDtRC_t cmDataSetIntArray( cmData_t* d, int* v, unsigned eleCnt, unsigned flags )
- { return cmDataSetArrayValue(d, kIntDtId, v, eleCnt, flags ); }
- cmDtRC_t cmDataSetUIntArray( cmData_t* d, unsigned int* v, unsigned eleCnt, unsigned flags )
- { return cmDataSetArrayValue(d, kUIntDtId, v, eleCnt, flags ); }
- cmDtRC_t cmDataSetLongArray( cmData_t* d, long* v, unsigned eleCnt, unsigned flags )
- { return cmDataSetArrayValue(d, kLongDtId, v, eleCnt, flags ); }
- cmDtRC_t cmDataSetULongArray( cmData_t* d, unsigned long* v, unsigned eleCnt, unsigned flags )
- { return cmDataSetArrayValue(d, kULongDtId, v, eleCnt, flags ); }
- cmDtRC_t cmDataSetFloatArray( cmData_t* d, float* v, unsigned eleCnt, unsigned flags )
- { return cmDataSetArrayValue(d, kFloatDtId, v, eleCnt, flags ); }
- cmDtRC_t cmDataSetDoubleArray( cmData_t* d, double* v, unsigned eleCnt, unsigned flags )
- { return cmDataSetArrayValue(d, kDoubleDtId, v, eleCnt, flags ); }
- cmDtRC_t cmDataSetStrArray( cmData_t* d, cmChar_t** v, unsigned eleCnt, unsigned flags )
- { return cmDataSetArrayValue(d, kStrDtId, v, eleCnt, flags ); }
- cmDtRC_t cmDataSetConstStrArray(cmData_t* d,const cmChar_t** v,unsigned eleCnt, unsigned flags )
- { return cmDataSetArrayValue(d, kStrDtId, (cmChar_t**)v, eleCnt, flags ); }
-
-
- unsigned cmDataArrayEleCount( const cmData_t* d )
- { return d->cid==kArrayDtId ? d->cnt : 0; }
-
-
- cmDtRC_t cmDataCharArray( const cmData_t* d, char** v )
- {
- if( d->cid != kArrayDtId )
- return _cmDtErrMsg(d,kInvalidContDtRC,"Cannot return an array base for a %s container.",cmDataContainerIdToLabel(d->cid));
- *v = (char*)d->u.vp;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataUCharArray( const cmData_t* d, unsigned char** v )
- {
- if( d->cid != kArrayDtId )
- return _cmDtErrMsg(d,kInvalidContDtRC,"Cannot return an array base for a %s container.",cmDataContainerIdToLabel(d->cid));
- *v = (unsigned char*)d->u.vp;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataShortArray( const cmData_t* d, short** v )
- {
- if( d->cid != kArrayDtId )
- return _cmDtErrMsg(d,kInvalidContDtRC,"Cannot return an array base for a %s container.",cmDataContainerIdToLabel(d->cid));
- *v = (short*)d->u.vp;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataUShortArray( const cmData_t* d, unsigned short** v )
- {
- if( d->cid != kArrayDtId )
- return _cmDtErrMsg(d,kInvalidContDtRC,"Cannot return an array base for a %s container.",cmDataContainerIdToLabel(d->cid));
- *v = (unsigned short*)d->u.vp;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataIntArray( const cmData_t* d, int** v )
- {
- if( d->cid != kArrayDtId )
- return _cmDtErrMsg(d,kInvalidContDtRC,"Cannot return an array base for a %s container.",cmDataContainerIdToLabel(d->cid));
- *v = (int*)d->u.vp;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataUIntArray( const cmData_t* d, unsigned int** v )
- {
- if( d->cid != kArrayDtId )
- return _cmDtErrMsg(d,kInvalidContDtRC,"Cannot return an array base for a %s container.",cmDataContainerIdToLabel(d->cid));
- *v = (unsigned int*)d->u.vp;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataLongArray( const cmData_t* d, long** v )
- {
- if( d->cid != kArrayDtId )
- return _cmDtErrMsg(d,kInvalidContDtRC,"Cannot return an array base for a %s container.",cmDataContainerIdToLabel(d->cid));
- *v = (long*)d->u.vp;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataULongArray( const cmData_t* d, unsigned long** v )
- {
- if( d->cid != kArrayDtId )
- return _cmDtErrMsg(d,kInvalidContDtRC,"Cannot return an array base for a %s container.",cmDataContainerIdToLabel(d->cid));
- *v = (unsigned long*)d->u.vp;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataFloatArray( const cmData_t* d, float** v )
- {
- if( d->cid != kArrayDtId )
- return _cmDtErrMsg(d,kInvalidContDtRC,"Cannot return an array base for a %s container.",cmDataContainerIdToLabel(d->cid));
- *v = (float*)d->u.vp;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataDoubleArray( const cmData_t* d, double** v )
- {
- if( d->cid != kArrayDtId )
- return _cmDtErrMsg(d,kInvalidContDtRC,"Cannot return an array base for a %s container.",cmDataContainerIdToLabel(d->cid));
- *v = (double*)d->u.vp;
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataStrArray( const cmData_t* d, cmChar_t*** v )
- {
- }
-
- cmDtRC_t cmDataConstStrArray( const cmData_t* d, const cmChar_t*** v )
- {
- }
-
-
-
-
- //----------------------------------------------------------------------------
- // Structure related functions
- //
-
-
- void cmDataFree( cmData_t* p )
- {
- _cmDataFree(p);
- }
-
- cmData_t* cmDataUnlink( cmData_t* p )
- {
- if( p->parent == NULL )
- return p;
-
- assert( cmDataIsStruct(p->parent) );
-
- cmData_t* cp = p->u.child;
- cmData_t* pp = NULL;
- for(; cp!=NULL; cp=cp->sibling)
- if( cp == p )
- {
- if( pp == NULL )
- p->parent->u.child = p->sibling;
- else
- pp->sibling = cp->sibling;
- }
- return p;
- }
-
- void cmDataUnlinkAndFree( cmData_t* p )
- {
- cmDataUnlink(p);
- cmDataFree(p);
- }
-
- cmDtRC_t _cmDataDupl( const cmData_t* d, cmData_t* parent, cmData_t** ref )
- {
- cmData_t* rp = NULL;
-
- *ref = NULL;
-
- switch( d->cid )
- {
- case kScalarDtId:
- if( d->tid == kBlobDtId || d->tid == kStrDtId )
- rc = cmDataNewScalar(parent, d->tid, d->flags, d->u.vp, d->cnt, &rp );
- else
- rc = cmDataNewScalar(parent, d->tid, d->flags, d->u.vp, 0, &rp );
- break;
-
- case kArrayDtId:
- rc = cmDataNewArray(parent, d->tid, d->u.vp, d->cnt, d->flags, &rp );
- break;
-
- case kListDtId:
- case kPairDtId:
- case kRecordDtId:
- {
- rp = _cmDataAllocNode(parent,d->tid);
- cmData_t* cp = d->u.child;
- for(; cp!=NULL; cp=cd->sibling)
- cmDataAppendChild(rp,_cmDataDupl(cp,rp));
- }
- break;
-
- default:
- assert(0);
- break;
- }
-
- if( rp != NULL )
- *ref = rp;
-
- return rc;
-
- /*
- cmData_t* rp = NULL;
-
- switch( p->tid )
- {
- case kNullDtId: rp = cmDataAllocNull(parent); break;
- case kUCharDtId: rp = cmDataAllocUChar(parent,p->u.uc); break;
- case kCharDtId: rp = cmDataAllocChar(parent,p->u.c); break;
- case kUShortDtId: rp = cmDataAllocShort(parent,p->u.us); break;
- case kShortDtId: rp = cmDataAllocUShort(parent,p->u.s); break;
- case kUIntDtId: rp = cmDataAllocUInt(parent,p->u.i); break;
- case kIntDtId: rp = cmDataAllocInt(parent,p->u.ui); break;
- case kULongDtId: rp = cmDataAllocULong(parent,p->u.ul); break;
- case kLongDtId: rp = cmDataAllocLong(parent,p->u.l); break;
- case kFloatDtId: rp = cmDataAllocFloat(parent,p->u.f); break;
- case kDoubleDtId: rp = cmDataAllocDouble(parent,p->u.d); break;
-
-
- case kStrDtId: rp = cmDataStrAlloc(parent,p->u.z); break;
- case kConstStrDtId: rp = cmDataConstStrAlloc(parent,p->u.cz); break;
-
- case kUCharPtrDtId: rp = cmDataUCharAllocPtr(parent,p->u.ucp,p->cnt); break;
- case kCharPtrDtId: rp = cmDataCharAllocPtr(parent,p->u.cp,p->cnt); break;
- case kUShortPtrDtId: rp = cmDataUShortAllocPtr(parent,p->u.usp,p->cnt); break;
- case kShortPtrDtId: rp = cmDataShortAllocPtr(parent,p->u.sp,p->cnt); break;
- case kUIntPtrDtId: rp = cmDataUIntAllocPtr(parent,p->u.uip,p->cnt); break;
- case kIntPtrDtId: rp = cmDataIntAllocPtr(parent,p->u.ip,p->cnt); break;
- case kULongPtrDtId: rp = cmDataULongAllocPtr(parent,p->u.ulp,p->cnt); break;
- case kLongPtrDtId: rp = cmDataLongAllocPtr(parent,p->u.lp,p->cnt); break;
- case kFloatPtrDtId: rp = cmDataFloatAllocPtr(parent,p->u.fp,p->cnt); break;
- case kDoublePtrDtId: rp = cmDataDoubleAllocPtr(parent,p->u.dp,p->cnt); break;
- case kVoidPtrDtId: rp = cmDataVoidAllocPtr(parent,p->u.vp,p->cnt); break;
-
- case kListDtId:
- case kPairDtId:
- case kRecordDtId:
- {
- rp = _cmDataAllocNode(parent,p->tid);
- cmData_t* cp = p->u.child;
- for(; cp!=NULL; cp=cp->sibling)
- cmDataAppendChild(rp,_cmDataDupl(cp,rp));
- }
- break;
-
- default:
- assert(0);
- }
-
- return rp;
- */
- }
-
- cmData_t* cmDataDupl( const cmData_t* p )
- { return _cmDataDupl(p,NULL); }
-
- cmData_t* cmDataReplace( cmData_t* dst, cmData_t* src )
- {
- if( dst->parent == NULL )
- {
- cmDataUnlinkAndFree(dst);
- src->parent = NULL;
- return src;
- }
-
- cmData_t* parent = dst->parent;
- cmData_t* cp = parent->u.child;
- cmData_t* pp = NULL;
- unsigned i = 0;
- unsigned n = cmDataChildCount(parent);
-
- // locate dst's right sibling
- for(i=0; i<n; ++i,cp=cp->sibling)
- {
-
- if( cp == dst )
- {
- // link in 'src' in place of 'dst'
- src->sibling = dst->sibling;
-
- // free dst
- cmDataUnlinkAndFree(dst);
-
- // update the sibling link to
- if( pp == NULL )
- parent->u.child = src;
- else
- pp->sibling = src;
-
- src->parent = parent;
- break;
- }
- pp = cp;
- }
- return src;
- }
-
-
- unsigned cmDataChildCount( const cmData_t* p )
- {
- if( !cmDataIsStruct(p) )
- return 0;
-
- unsigned n = 0;
- const cmData_t* cp = p->u.child;
- for(; cp!=NULL; cp=cp->sibling)
- ++n;
-
- return n;
- }
-
- cmData_t* cmDataChild( cmData_t* p, unsigned index )
- {
- if( !cmDataIsStruct(p) )
- return NULL;
-
- unsigned n = 0;
- cmData_t* cp = p->u.child;
- for(; cp!=NULL; cp=cp->sibling)
- {
- if( n == index )
- break;
- ++n;
- }
-
- return cp;
- }
-
- cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p )
- {
- assert( cmDataIsStruct(p) );
-
-
- cmDataUnlink(p);
-
- p->u.child = parent->u.child;
- parent->u.child = p;
- p->parent = parent;
- return p;
- }
-
- cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p )
- {
- assert( cmDataIsStruct(parent) );
- assert( parent->cid != kRecordDtId || (parent->cid == kRecordDtId && p->cid==kPairDtId));
-
- cmDataUnlink(p);
-
- cmData_t* cp = parent->u.child;
- if( cp == NULL )
- parent->u.child = p;
- else
- {
- for(; cp!=NULL; cp=cp->sibling)
- if( cp->sibling == NULL )
- {
- cp->sibling = p;
- break;
- }
- }
-
- p->parent = parent;
- p->sibling = NULL;
- return p;
- }
-
- cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p )
- {
- if( !cmDataIsStruct(parent) )
- return NULL;
-
- cmDataUnlink(p);
-
- unsigned n = 0;
- cmData_t* cp = parent->u.child;
- cmData_t* pp = NULL;
- for(; cp!=NULL; cp=cp->sibling)
- {
- if( n == index )
- {
- if( pp == NULL )
- {
- parent->u.child = p;
- p->sibling = NULL;
- }
- else
- {
- p->sibling = pp->sibling;
- pp->sibling = p;
- }
- break;
-
- }
- ++n;
- }
-
- p->parent = parent;
-
- return p;
-
- }
-
-
- void cmDataTest( cmCtx_t* ctx )
- {
-
- }
-
- ////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////////////////
- #ifdef NOT_DEF
- cmDtRC_t _cmDataErrNo = kOkDtRC;
-
- cmData_t cmDataNull = { kInvalidDtId,0,NULL,NULL,0 };
-
- cmDtRC_t _cmDataSetError( unsigned err )
- {
- _cmDataErrNo = err;
- return err;
- }
-
- void _cmDataFreeArray( cmData_t* p )
- {
- if(cmIsFlag(p->flags,kDynPtrDtFl))
- {
- cmMemFree(p->u.vp);
- p->u.vp = NULL;
- p->flags = cmClrFlag(p->flags,kDynPtrDtFl);
- }
- p->tid = kInvalidDtId;
- p->cnt = 0;
- }
-
- void _cmDataFree( cmData_t* p )
- {
- if( p == NULL )
- return;
-
- if( cmDataIsStruct(p) )
- {
- cmData_t* cp = p->u.child;
- for(; cp!=NULL; cp=cp->sibling)
- _cmDataFree(cp);
- }
-
- _cmDataFreeArray(p);
- if( cmIsFlag(p->flags,kDynObjDtFl) )
- cmMemFree(p);
- }
-
- cmData_t* _cmDataAllocNode( cmData_t* parent, cmDataFmtId_t tid )
- {
- cmData_t* p = cmMemAllocZ(cmData_t,1);
- p->tid = tid;
- p->flags = kDynObjDtFl;
- p->parent = parent;
- if( parent != NULL )
- return cmDataAppendChild(parent,p);
- return p;
- }
-
-
- unsigned _cmDataByteCount( const cmData_t* p )
- {
- unsigned n = 0;
-
- switch( p->tid )
- {
- case kInvalidDtId: return 0;
- case kNullDtId: return n;
- case kUCharDtId: return n + sizeof(unsigned char);
- case kCharDtId: return n + sizeof(char);
- case kUShortDtId: return n + sizeof(unsigned short);
- case kShortDtId: return n + sizeof(short);
- case kUIntDtId: return n + sizeof(unsigned int);
- case kIntDtId: return n + sizeof(int);
- case kULongDtId: return n + sizeof(unsigned long);
- case kLongDtId: return n + sizeof(long);
- case kFloatDtId: return n + sizeof(float);
- case kDoubleDtId: return n + sizeof(double);
-
- case kStrDtId: return n + (p->u.z ==NULL ? 0 : strlen(p->u.z) + 1);
- case kConstStrDtId: return n + (p->u.cz==NULL ? 0 : strlen(p->u.cz) + 1);
-
- case kUCharPtrDtId: return n + p->cnt * sizeof(unsigned char);
- case kCharPtrDtId: return n + p->cnt * sizeof(char);
- case kUShortPtrDtId: return n + p->cnt * sizeof(unsigned short);
- case kShortPtrDtId: return n + p->cnt * sizeof(short);
- case kUIntPtrDtId: return n + p->cnt * sizeof(unsigned int);
- case kIntPtrDtId: return n + p->cnt * sizeof(int);
- case kULongPtrDtId: return n + p->cnt * sizeof(unsigned long);
- case kLongPtrDtId: return n + p->cnt * sizeof(long);
- case kFloatPtrDtId: return n + p->cnt * sizeof(float);
- case kDoublePtrDtId: return n + p->cnt * sizeof(double);
- case kVoidPtrDtId: return n + p->cnt * sizeof(char);
-
- default:
- return n;
- }
- assert(0);
- return 0;
- }
-
- bool cmDataIsValue( const cmData_t* p )
- { return kMinValDtId <= p->tid && p->tid <= kMaxValDtId; }
-
- bool cmDataIsPtr( const cmData_t* p )
- { return kMinPtrDtId <= p->tid && p->tid <= kMaxPtrDtId; }
-
- bool cmDataIsStruct( const cmData_t* p )
- { return kMinStructDtId <= p->tid && p->tid <= kMaxStructDtId; }
-
- char cmDataChar( const cmData_t* p ) { assert(p->tid==kCharDtId); return p->u.c; }
- unsigned char cmDataUChar( const cmData_t* p ) { assert(p->tid==kUCharDtId); return p->u.uc; }
- short cmDataShort( const cmData_t* p ) { assert(p->tid==kShortDtId); return p->u.s; }
- unsigned short cmDataUShort( const cmData_t* p ) { assert(p->tid==kUShortDtId); return p->u.us; }
- int cmDataInt( const cmData_t* p ) { assert(p->tid==kIntDtId); return p->u.i; }
- unsigned int cmDataUInt( const cmData_t* p ) { assert(p->tid==kUIntDtId); return p->u.ui; }
- long cmDataLong( const cmData_t* p ) { assert(p->tid==kLongDtId); return p->u.l; }
- unsigned long cmDataULong( const cmData_t* p ) { assert(p->tid==kULongDtId); return p->u.ul; }
- float cmDataFloat( const cmData_t* p ) { assert(p->tid==kFloatDtId); return p->u.f; }
- double cmDataDouble( const cmData_t* p ) { assert(p->tid==kDoubleDtId); return p->u.d; }
- cmChar_t* cmDataStr( const cmData_t* p ) { assert(p->tid==kStrDtId); return p->u.z; }
- const cmChar_t* cmDataConstStr( const cmData_t* p ) { assert(p->tid==kConstStrDtId); return p->u.cz; }
- void* cmDataVoidPtr( const cmData_t* p ) { assert(p->tid==kVoidPtrDtId); return p->u.vp; }
- char* cmDataCharPtr( const cmData_t* p ) { assert(p->tid==kCharPtrDtId); return p->u.cp; }
- unsigned char* cmDataUCharPtr( const cmData_t* p ) { assert(p->tid==kUCharPtrDtId); return p->u.ucp; }
- short* cmDataShortPtr( const cmData_t* p ) { assert(p->tid==kShortPtrDtId); return p->u.sp; }
- unsigned short* cmDataUShortPtr( const cmData_t* p ) { assert(p->tid==kUShortPtrDtId); return p->u.usp; }
- int* cmDataIntPtr( const cmData_t* p ) { assert(p->tid==kIntPtrDtId); return p->u.ip; }
- unsigned int* cmDataUIntPtr( const cmData_t* p ) { assert(p->tid==kUIntPtrDtId); return p->u.uip; }
- long* cmDataLongPtr( const cmData_t* p ) { assert(p->tid==kLongPtrDtId); return p->u.lp; }
- unsigned long* cmDataULongPtr( const cmData_t* p ) { assert(p->tid==kULongPtrDtId); return p->u.ulp; }
- float* cmDataFloatPtr( const cmData_t* p ) { assert(p->tid==kFloatPtrDtId); return p->u.fp; }
- double* cmDataDoublePtr( const cmData_t* p ) { assert(p->tid==kDoublePtrDtId); return p->u.dp; }
-
- cmDtRC_t cmDataGetUChar( const cmData_t* p, unsigned char* vp )
- {
- switch( p->tid )
- {
- case kUCharDtId: *vp = p->u.uc; break;
- case kCharDtId: *vp = (unsigned char)p->u.c; break;
- case kUShortDtId: *vp = (unsigned char)p->u.us; break;
- case kShortDtId: *vp = (unsigned char)p->u.s; break;
- case kUIntDtId: *vp = (unsigned char)p->u.ui; break;
- case kIntDtId: *vp = (unsigned char)p->u.i; break;
- case kULongDtId: *vp = (unsigned char)p->u.ul; break;
- case kLongDtId: *vp = (unsigned char)p->u.l; break;
- case kFloatDtId: *vp = (unsigned char)p->u.f; break;
- case kDoubleDtId: *vp = (unsigned char)p->u.d; break;
- default:
- return _cmDataSetError(kCvtErrDtRC);
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetChar( const cmData_t* p, char* vp )
- {
- switch( p->tid )
- {
- case kUCharDtId: *vp = (char)p->u.uc; break;
- case kCharDtId: *vp = p->u.c; break;
- case kUShortDtId: *vp = (char)p->u.us; break;
- case kShortDtId: *vp = (char)p->u.s; break;
- case kUIntDtId: *vp = (char)p->u.ui; break;
- case kIntDtId: *vp = (char)p->u.i; break;
- case kULongDtId: *vp = (char)p->u.ul; break;
- case kLongDtId: *vp = (char)p->u.l; break;
- case kFloatDtId: *vp = (char)p->u.f; break;
- case kDoubleDtId: *vp = (char)p->u.d; break;
- default:
- return _cmDataSetError(kCvtErrDtRC);
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetShort( const cmData_t* p, short* vp )
- {
- switch( p->tid )
- {
- case kUCharDtId: *vp = (short)p->u.uc; break;
- case kCharDtId: *vp = (short)p->u.c; break;
- case kUShortDtId: *vp = (short)p->u.us; break;
- case kShortDtId: *vp = p->u.s; break;
- case kUIntDtId: *vp = (short)p->u.ui; break;
- case kIntDtId: *vp = (short)p->u.i; break;
- case kULongDtId: *vp = (short)p->u.ul; break;
- case kLongDtId: *vp = (short)p->u.l; break;
- case kFloatDtId: *vp = (short)p->u.f; break;
- case kDoubleDtId: *vp = (short)p->u.d; break;
- default:
- return _cmDataSetError(kCvtErrDtRC);
- }
- return kOkDtRC;
- }
-
-
- cmDtRC_t cmDataGetUShort( const cmData_t* p, unsigned short* vp )
- {
- switch( p->tid )
- {
- case kUCharDtId: *vp = (unsigned short)p->u.uc; break;
- case kCharDtId: *vp = (unsigned short)p->u.c; break;
- case kUShortDtId: *vp = p->u.us; break;
- case kShortDtId: *vp = (unsigned short)p->u.s; break;
- case kUIntDtId: *vp = (unsigned short)p->u.ui; break;
- case kIntDtId: *vp = (unsigned short)p->u.i; break;
- case kULongDtId: *vp = (unsigned short)p->u.ul; break;
- case kLongDtId: *vp = (unsigned short)p->u.l; break;
- case kFloatDtId: *vp = (unsigned short)p->u.f; break;
- case kDoubleDtId: *vp = (unsigned short)p->u.d; break;
- default:
- return _cmDataSetError(kCvtErrDtRC);
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetInt( const cmData_t* p, int* vp )
- {
-
- switch( p->tid )
- {
- case kUCharDtId: *vp = (int)p->u.uc; break;
- case kCharDtId: *vp = (int)p->u.c; break;
- case kUShortDtId: *vp = (int)p->u.us; break;
- case kShortDtId: *vp = (int)p->u.s; break;
- case kUIntDtId: *vp = (int)p->u.ui; break;
- case kIntDtId: *vp = p->u.i; break;
- case kULongDtId: *vp = (int)p->u.ul; break;
- case kLongDtId: *vp = (int)p->u.l; break;
- case kFloatDtId: *vp = (int)p->u.f; break;
- case kDoubleDtId: *vp = (int)p->u.d; break;
- default:
- return _cmDataSetError(kCvtErrDtRC);
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetUInt( const cmData_t* p, unsigned int* vp )
- {
- switch( p->tid )
- {
- case kUCharDtId: *vp = (unsigned int)p->u.uc; break;
- case kCharDtId: *vp = (unsigned int)p->u.c; break;
- case kUShortDtId: *vp = (unsigned int)p->u.us; break;
- case kShortDtId: *vp = (unsigned int)p->u.s; break;
- case kUIntDtId: *vp = p->u.ui; break;
- case kIntDtId: *vp = (unsigned int)p->u.i; break;
- case kULongDtId: *vp = (unsigned int)p->u.ul; break;
- case kLongDtId: *vp = (unsigned int)p->u.l; break;
- case kFloatDtId: *vp = (unsigned int)p->u.f; break;
- case kDoubleDtId: *vp = (unsigned int)p->u.d; break;
- default:
- return _cmDataSetError(kCvtErrDtRC);
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetLong( const cmData_t* p, long* vp )
- {
- switch( p->tid )
- {
- case kUCharDtId: *vp = (long)p->u.uc; break;
- case kCharDtId: *vp = (long)p->u.c; break;
- case kUShortDtId: *vp = (long)p->u.us; break;
- case kShortDtId: *vp = (long)p->u.s; break;
- case kUIntDtId: *vp = (long)p->u.ui; break;
- case kIntDtId: *vp = (long)p->u.i; break;
- case kULongDtId: *vp = (long)p->u.ul; break;
- case kLongDtId: *vp = p->u.l; break;
- case kFloatDtId: *vp = (long)p->u.f; break;
- case kDoubleDtId: *vp = (long)p->u.d; break;
- default:
- return _cmDataSetError(kCvtErrDtRC);
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetULong( const cmData_t* p, unsigned long* vp )
- {
- switch( p->tid )
- {
- case kUCharDtId: *vp = (unsigned long)p->u.uc; break;
- case kCharDtId: *vp = (unsigned long)p->u.c; break;
- case kUShortDtId: *vp = (unsigned long)p->u.us; break;
- case kShortDtId: *vp = (unsigned long)p->u.s; break;
- case kUIntDtId: *vp = (unsigned long)p->u.ui; break;
- case kIntDtId: *vp = (unsigned long)p->u.i; break;
- case kULongDtId: *vp = p->u.ul; break;
- case kLongDtId: *vp = (unsigned long)p->u.l; break;
- case kFloatDtId: *vp = (unsigned long)p->u.f; break;
- case kDoubleDtId: *vp = (unsigned long)p->u.d; break;
- default:
- return _cmDataSetError(kCvtErrDtRC);
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetFloat( const cmData_t* p, float* vp )
- {
-
- switch( p->tid )
- {
- case kUCharDtId: *vp = (float)p->u.uc; break;
- case kCharDtId: *vp = (float)p->u.c; break;
- case kUShortDtId: *vp = (float)p->u.us; break;
- case kShortDtId: *vp = (float)p->u.s; break;
- case kUIntDtId: *vp = (float)p->u.ui; break;
- case kIntDtId: *vp = (float)p->u.i; break;
- case kULongDtId: *vp = (float)p->u.ul; break;
- case kLongDtId: *vp = (float)p->u.l; break;
- case kFloatDtId: *vp = p->u.f; break;
- case kDoubleDtId: *vp = (float)p->u.d; break;
- default:
- return _cmDataSetError(kCvtErrDtRC);
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetDouble( const cmData_t* p, double* vp )
- {
- switch( p->tid )
- {
- case kUCharDtId: *vp = (double)p->u.uc; break;
- case kCharDtId: *vp = (double)p->u.c; break;
- case kUShortDtId: *vp = (double)p->u.us; break;
- case kShortDtId: *vp = (double)p->u.s; break;
- case kUIntDtId: *vp = (double)p->u.ui; break;
- case kIntDtId: *vp = (double)p->u.i; break;
- case kULongDtId: *vp = (double)p->u.ul; break;
- case kLongDtId: *vp = (double)p->u.l; break;
- case kFloatDtId: *vp = (double)p->u.f; break;
- case kDoubleDtId: *vp = p->u.d; break;
- default:
- return _cmDataSetError(kCvtErrDtRC);
- }
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataGetStr( const cmData_t* p, cmChar_t** vp )
- {
- if( p->tid == kStrDtId || p->tid == kConstStrDtId)
- {
- *vp = (p->tid == kStrDtId || p->tid == kConstStrDtId) ? p->u.z : NULL;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- cmDtRC_t cmDataGetConstStr( const cmData_t* p, const cmChar_t** vp )
- {
- if( p->tid == kStrDtId || p->tid == kConstStrDtId)
- {
- *vp = (p->tid == kStrDtId || p->tid == kConstStrDtId) ? p->u.cz : NULL;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- cmDtRC_t cmDataGetVoidPtr( const cmData_t* p, void** vp )
- {
- if( kMinPtrDtId <= p->tid && p->tid <= kMaxPtrDtId )
- {
- *vp = ( kMinPtrDtId <= p->tid && p->tid <= kMaxPtrDtId ) ? p->u.vp : NULL;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- cmDtRC_t cmDataGetCharPtr( const cmData_t* p, char** vp )
- {
- if( p->tid == kCharPtrDtId || p->tid == kUCharPtrDtId )
- {
- *vp = (p->tid == kCharPtrDtId || p->tid == kUCharPtrDtId) ? p->u.cp : NULL;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- cmDtRC_t cmDataGetUCharPtr( const cmData_t* p, unsigned char** vp )
- {
- if( p->tid == kCharPtrDtId || p->tid == kUCharPtrDtId )
- {
- *vp = (p->tid == kCharPtrDtId || p->tid == kUCharPtrDtId) ? p->u.ucp : NULL;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- cmDtRC_t cmDataGetShortPtr( const cmData_t* p, short** vp )
- {
- if( p->tid == kShortPtrDtId || p->tid == kUShortPtrDtId )
- {
- *vp = (p->tid == kShortPtrDtId || p->tid == kUShortPtrDtId ) ? p->u.sp : NULL;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- cmDtRC_t cmDataGetUShortPtr( const cmData_t* p, unsigned short** vp )
- {
- if( p->tid == kShortPtrDtId || p->tid == kUShortPtrDtId )
- {
- *vp = (p->tid == kShortPtrDtId || p->tid == kUShortPtrDtId ) ? p->u.usp : NULL;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- cmDtRC_t cmDataGetIntPtr( const cmData_t* p, int** vp )
- {
- if( p->tid == kIntPtrDtId || p->tid == kUIntPtrDtId )
- {
- *vp = (p->tid == kIntPtrDtId || p->tid == kUIntPtrDtId ) ? p->u.ip : NULL;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- cmDtRC_t cmDataGetUIntPtr( const cmData_t* p, unsigned int** vp )
- {
- if( p->tid == kIntPtrDtId || p->tid == kUIntPtrDtId )
- {
- *vp = (p->tid == kIntPtrDtId || p->tid == kUIntPtrDtId ) ? p->u.uip : NULL;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- cmDtRC_t cmDataGetLongPtr( const cmData_t* p, long** vp )
- {
- if( p->tid == kLongPtrDtId || p->tid == kULongPtrDtId )
- {
- *vp = (p->tid == kLongPtrDtId || p->tid == kULongPtrDtId ) ? p->u.lp : NULL;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- cmDtRC_t cmDataGetULongPtr( const cmData_t* p, unsigned long** vp )
- {
- if( p->tid == kLongPtrDtId || p->tid == kULongPtrDtId )
- {
- *vp = (p->tid == kLongPtrDtId || p->tid == kULongPtrDtId ) ? p->u.ulp : NULL;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- cmDtRC_t cmDataGetFloatPtr( const cmData_t* p, float** vp )
- {
- if( p->tid == kFloatPtrDtId )
- {
- *vp = p->u.fp;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- cmDtRC_t cmDataGetDoublePtr( const cmData_t* p, double** vp )
- {
- if( p->tid == kDoublePtrDtId )
- {
- *vp = p->u.dp;
- return kOkDtRC;
- }
- return _cmDataSetError(kCvtErrDtRC);
- }
-
- // Set the value of an existing data object.
- cmData_t* cmDataSetNull( cmData_t* p )
- {
- _cmDataFreeArray(p);
- p->tid = kNullDtId;
- return p;
- }
-
- cmData_t* cmDataSetChar( cmData_t* p, char v )
- {
- _cmDataFreeArray(p);
- p->tid = kCharDtId;
- p->u.c = v;
- return p;
- }
-
- cmData_t* cmDataSetUChar( cmData_t* p, unsigned char v )
- {
- _cmDataFreeArray(p);
- p->tid = kUCharDtId;
- p->u.uc = v;
- return p;
- }
-
- cmData_t* cmDataSetShort( cmData_t* p, short v )
- {
- _cmDataFreeArray(p);
- p->tid = kShortDtId;
- p->u.s = v;
- return p;
- }
-
- cmData_t* cmDataSetUShort( cmData_t* p, unsigned short v )
- {
- _cmDataFreeArray(p);
- p->tid = kUShortDtId;
- p->u.us = v;
- return p;
- }
-
- cmData_t* cmDataSetInt( cmData_t* p, int v )
- {
- _cmDataFreeArray(p);
- p->tid = kCharDtId;
- p->u.c = v;
- return p;
- }
-
- cmData_t* cmDataSetUInt( cmData_t* p, unsigned int v )
- {
- _cmDataFreeArray(p);
- p->tid = kUIntDtId;
- p->u.ui = v;
- return p;
- }
-
- cmData_t* cmDataSetLong( cmData_t* p, long v )
- {
- _cmDataFreeArray(p);
- p->tid = kLongDtId;
- p->u.l = v;
- return p;
- }
-
- cmData_t* cmDataSetULong( cmData_t* p, unsigned long v )
- {
- _cmDataFreeArray(p);
- p->tid = kULongDtId;
- p->u.ul = v;
- return p;
- }
-
- cmData_t* cmDataSetFloat( cmData_t* p, float v )
- {
- _cmDataFreeArray(p);
- p->tid = kFloatDtId;
- p->u.f = v;
- return p;
- }
-
- cmData_t* cmDataSetDouble( cmData_t* p, double v )
- {
- _cmDataFreeArray(p);
- p->tid = kDoubleDtId;
- p->u.d = v;
- return p;
- }
-
- cmData_t* cmDataSetStr( cmData_t* p, cmChar_t* s )
- {
- _cmDataFreeArray(p);
- p->tid = kStrDtId;
- p->u.z = s;
- return p;
- }
-
- cmData_t* cmDataSetConstStr( cmData_t* p, const cmChar_t* s )
- {
- _cmDataFreeArray(p);
- p->tid = kConstStrDtId;
- p->u.cz = s;
- return p;
- }
-
- // Set the value of an existing data object to an external array.
- // The array is not copied.
- cmData_t* cmDataSetVoidPtr( cmData_t* p, void* vp, unsigned cnt )
- {
- cmDataSetCharPtr(p,(char*)vp,cnt);
- p->tid = kVoidPtrDtId;
- return p;
- }
-
- cmData_t* cmDataSetCharPtr( cmData_t* p, char* vp, unsigned cnt )
- {
- _cmDataFreeArray(p);
- p->tid = kCharPtrDtId;
- p->u.cp = vp;
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetUCharPtr( cmData_t* p, unsigned char* vp, unsigned cnt )
- {
- _cmDataFreeArray(p);
- p->tid = kUCharPtrDtId;
- p->u.ucp = vp;
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetShortPtr( cmData_t* p, short* vp, unsigned cnt )
- {
- _cmDataFreeArray(p);
- p->tid = kShortPtrDtId;
- p->u.sp = vp;
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetUShortPtr( cmData_t* p, unsigned short* vp, unsigned cnt )
- {
- _cmDataFreeArray(p);
- p->tid = kUShortPtrDtId;
- p->u.usp = vp;
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetIntPtr( cmData_t* p, int* vp, unsigned cnt )
- {
- _cmDataFreeArray(p);
- p->tid = kCharPtrDtId;
- p->u.ip = vp;
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetUIntPtr( cmData_t* p, unsigned int* vp, unsigned cnt )
- {
- _cmDataFreeArray(p);
- p->tid = kUIntPtrDtId;
- p->u.uip = vp;
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetLongPtr( cmData_t* p, long* vp, unsigned cnt )
- {
- _cmDataFreeArray(p);
- p->tid = kLongPtrDtId;
- p->u.lp = vp;
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetULongPtr( cmData_t* p, unsigned long* vp, unsigned cnt )
- {
- _cmDataFreeArray(p);
- p->tid = kULongPtrDtId;
- p->u.ulp = vp;
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetFloatPtr( cmData_t* p, float* vp, unsigned cnt )
- {
- _cmDataFreeArray(p);
- p->tid = kFloatPtrDtId;
- p->u.fp = vp;
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetDoublePtr( cmData_t* p, double* vp, unsigned cnt )
- {
- _cmDataFreeArray(p);
- p->tid = kDoublePtrDtId;
- p->u.dp = vp;
- p->cnt = cnt;
- return p;
- }
-
- // Set the value of an existing array based data object.
- // Allocate the internal array and copy the array into it.
- cmData_t* cmDataSetStrAllocN( cmData_t* p, const cmChar_t* s, unsigned charCnt )
- {
- if( cmIsFlag(p->flags,kDynPtrDtFl) )
- cmMemResizeStrN(p->u.z,s,charCnt);
- else
- {
- _cmDataFreeArray(p);
- p->u.z = cmMemAllocStrN(s,charCnt);
- }
- p->tid = kStrDtId;
- p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
- return p;
- }
-
- cmData_t* cmDataSetStrAlloc( cmData_t* p, const cmChar_t* s )
- { return cmDataSetStrAllocN(p,s,strlen(s)); }
-
- cmData_t* cmDataSetConstStrAllocN( cmData_t* p, const cmChar_t* s, unsigned charCnt )
- { return cmDataSetStrAllocN(p,s,charCnt); }
-
- cmData_t* cmDataSetConstStrAlloc( cmData_t* p, const cmChar_t* s )
- { return cmDataSetStrAlloc(p,s); }
-
- cmData_t* cmDataSetVoidAllocPtr( cmData_t* p, const void* vp, unsigned cnt )
- { return cmDataSetCharAllocPtr(p,(char*)vp,cnt); }
-
- cmData_t* cmDataSetCharAllocPtr( cmData_t* p, const char* vp, unsigned cnt )
- {
- if( cmIsFlag(p->flags,kDynPtrDtFl) )
- p->u.cp = cmMemResize(char, p->u.cp, cnt );
- else
- {
- _cmDataFreeArray(p);
- p->u.cp = cmMemAlloc(char, cnt );
- }
-
- memcpy(p->u.cp,vp,sizeof(char)*cnt);
- p->tid = kCharPtrDtId;
- p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetUCharAllocPtr( cmData_t* p, const unsigned char* vp, unsigned cnt )
- {
- if( cmIsFlag(p->flags,kDynPtrDtFl) )
- p->u.ucp = cmMemResize(unsigned char, p->u.ucp, cnt );
- else
- {
- _cmDataFreeArray(p);
- p->u.ucp = cmMemAlloc(unsigned char, cnt );
- }
- memcpy(p->u.ucp,vp,sizeof(unsigned char)*cnt);
- p->tid = kUCharPtrDtId;
- p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetShortAllocPtr( cmData_t* p, const short* vp, unsigned cnt )
- {
- if( cmIsFlag(p->flags,kDynPtrDtFl) )
- p->u.sp = cmMemResize(short, p->u.sp, cnt );
- else
- {
- _cmDataFreeArray(p);
- p->u.sp = cmMemAlloc(short, cnt );
- }
- memcpy(p->u.sp,vp,sizeof(short)*cnt);
- p->tid = kShortPtrDtId;
- p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetUShortAllocPtr( cmData_t* p, const unsigned short* vp, unsigned cnt )
- {
- if( cmIsFlag(p->flags,kDynPtrDtFl) )
- p->u.usp = cmMemResize(unsigned short, p->u.usp, cnt );
- else
- {
- _cmDataFreeArray(p);
- p->u.usp = cmMemAlloc(unsigned short, cnt );
- }
- memcpy(p->u.usp,vp,sizeof(unsigned short)*cnt);
- p->tid = kUShortPtrDtId;
- p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetIntAllocPtr( cmData_t* p, const int* vp, unsigned cnt )
- {
- if( cmIsFlag(p->flags,kDynPtrDtFl) )
- p->u.ip = cmMemResize(int, p->u.ip, cnt );
- else
- {
- _cmDataFreeArray(p);
- p->u.ip = cmMemAlloc(int, cnt );
- }
- memcpy(p->u.ip,vp,sizeof(int)*cnt);
- p->tid = kIntPtrDtId;
- p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
- p->cnt = cnt;
- return p;
- }
-
- cmData_t* cmDataSetUIntAllocPtr( cmData_t* p, const unsigned int* vp, unsigned cnt )
- {
- if( cmIsFlag(p->flags,kDynPtrDtFl) )
- p->u.uip = cmMemResize(unsigned int, p->u.uip, cnt );
- else
- {
- _cmDataFreeArray(p);
- p->u.uip = cmMemAlloc(unsigned int, cnt );
- }
- memcpy(p->u.uip,vp,sizeof(unsigned int)*cnt);
- p->tid = kUIntPtrDtId;
- p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
- p->cnt = cnt;
- return p;
- }
-
-
- cmData_t* cmDataSetLongAllocPtr( cmData_t* p, const long* vp, unsigned cnt )
- {
- if( cmIsFlag(p->flags,kDynPtrDtFl) )
- p->u.lp = cmMemResize(long, p->u.lp, cnt );
- else
- {
- _cmDataFreeArray(p);
- p->u.lp = cmMemAlloc(long, cnt );
- }
- memcpy(p->u.lp,vp,sizeof(long)*cnt);
- p->tid = kLongPtrDtId;
- p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
- p->cnt = cnt;
- return p;
- }
-
-
- cmData_t* cmDataSetULongAllocPtr( cmData_t* p, const unsigned long* vp, unsigned cnt )
- {
- if( cmIsFlag(p->flags,kDynPtrDtFl) )
- p->u.ulp = cmMemResize(unsigned long, p->u.ulp, cnt );
- else
- {
- _cmDataFreeArray(p);
- p->u.ulp = cmMemAlloc(unsigned long, cnt );
- }
- memcpy(p->u.ulp,vp,sizeof(unsigned long)*cnt);
- p->tid = kULongPtrDtId;
- p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
- p->cnt = cnt;
- return p;
- }
-
-
- cmData_t* cmDataSetFloatAllocPtr( cmData_t* p, const float* vp, unsigned cnt )
- {
- if( cmIsFlag(p->flags,kDynPtrDtFl) )
- p->u.fp = cmMemResize(float, p->u.fp, cnt );
- else
- {
- _cmDataFreeArray(p);
- p->u.fp = cmMemAlloc(float, cnt );
- }
- memcpy(p->u.fp,vp,sizeof(float)*cnt);
- p->tid = kFloatPtrDtId;
- p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
- p->cnt = cnt;
- return p;
- }
-
-
- cmData_t* cmDataSetDoubleAllocPtr( cmData_t* p, const double* vp, unsigned cnt )
- {
- if( cmIsFlag(p->flags,kDynPtrDtFl) )
- p->u.dp = cmMemResize(double, p->u.dp, cnt );
- else
- {
- _cmDataFreeArray(p);
- p->u.dp = cmMemAlloc(double, cnt );
- }
- memcpy(p->u.dp,vp,sizeof(double)*cnt);
- p->tid = kDoublePtrDtId;
- p->flags = cmSetFlag(p->flags,kDynPtrDtFl);
- p->cnt = cnt;
- return p;
- }
-
-
-
- // Dynamically allocate a data object and set it's value.
- cmData_t* cmDataAllocNull( cmData_t* parent )
- { return _cmDataAllocNode(parent,kNullDtId); }
-
- cmData_t* cmDataAllocChar( cmData_t* parent, char v )
- {
- cmData_t* p = _cmDataAllocNode(parent,kCharDtId);
- cmDataSetChar(p,v);
- return p;
- }
-
- cmData_t* cmDataAllocUChar( cmData_t* parent, unsigned char v )
- {
- cmData_t* p = _cmDataAllocNode(parent,kUCharDtId);
- cmDataSetUChar(p,v);
- return p;
- }
-
- cmData_t* cmDataAllocShort( cmData_t* parent, short v )
- {
- cmData_t* p = _cmDataAllocNode(parent,kShortDtId);
- cmDataSetShort(p,v);
- return p;
- }
-
- cmData_t* cmDataAllocUShort( cmData_t* parent, unsigned short v )
- {
- cmData_t* p = _cmDataAllocNode(parent,kUShortDtId);
- cmDataSetUShort(p,v);
- return p;
- }
-
- cmData_t* cmDataAllocInt( cmData_t* parent, int v )
- {
- cmData_t* p = _cmDataAllocNode(parent,kIntDtId);
- cmDataSetInt(p,v);
- return p;
- }
-
- cmData_t* cmDataAllocUInt( cmData_t* parent, unsigned int v )
- {
- cmData_t* p = _cmDataAllocNode(parent,kUIntDtId);
- cmDataSetUInt(p,v);
- return p;
- }
-
- cmData_t* cmDataAllocLong( cmData_t* parent, long v )
- {
- cmData_t* p = _cmDataAllocNode(parent,kLongDtId);
- cmDataSetLong(p,v);
- return p;
- }
-
- cmData_t* cmDataAllocULong( cmData_t* parent, unsigned long v )
- {
- cmData_t* p = _cmDataAllocNode(parent,kULongDtId);
- cmDataSetULong(p,v);
- return p;
- }
-
- cmData_t* cmDataAllocFloat( cmData_t* parent, float v )
- {
- cmData_t* p = _cmDataAllocNode(parent,kFloatDtId);
- cmDataSetFloat(p,v);
- return p;
- }
-
- cmData_t* cmDataAllocDouble( cmData_t* parent, double v )
- {
- cmData_t* p = _cmDataAllocNode(parent,kDoubleDtId);
- cmDataSetDouble(p,v);
- return p;
- }
-
-
- // Dynamically allocate a data object and set its array value to an external
- // array. The data is not copied.
- cmData_t* cmDataAllocStr( cmData_t* parent, cmChar_t* str )
- {
- cmData_t* p = _cmDataAllocNode(parent,kStrDtId);
- cmDataSetStr(p,str);
- return p;
- }
-
- cmData_t* cmDataAllocConstStr( cmData_t* parent, const cmChar_t* str )
- {
- cmData_t* p = _cmDataAllocNode(parent,kConstStrDtId);
- cmDataSetConstStr(p,str);
- return p;
- }
-
- cmData_t* cmDataAllocCharPtr( cmData_t* parent, char* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kCharPtrDtId);
- cmDataSetCharPtr(p,(char*)v,cnt);
- return p;
- }
-
- cmData_t* cmDataAllocUCharPtr( cmData_t* parent, unsigned char* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kUCharPtrDtId);
- cmDataSetUCharPtr(p,(unsigned char*)v,cnt);
- return p;
- }
-
- cmData_t* cmDataAllocShortPtr( cmData_t* parent, short* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kShortPtrDtId);
- cmDataSetShortPtr(p,(short*)v,cnt);
- return p;
- }
-
- cmData_t* cmDataAllocUShortPtr( cmData_t* parent, unsigned short* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kUShortPtrDtId);
- cmDataSetUShortPtr(p,(unsigned short*)v,cnt);
- return p;
- }
-
- cmData_t* cmDataAllocIntPtr( cmData_t* parent, int* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kIntPtrDtId);
- cmDataSetIntPtr(p,(int*)v,cnt);
- return p;
- }
-
- cmData_t* cmDataAllocUIntPtr( cmData_t* parent, unsigned int* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kUIntPtrDtId);
- cmDataSetUIntPtr(p,(unsigned int*)v,cnt);
- return p;
- }
-
- cmData_t* cmDataAllocLongPtr( cmData_t* parent, long* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kLongPtrDtId);
- cmDataSetLongPtr(p,(long*)v,cnt);
- return p;
- }
-
- cmData_t* cmDataAllocULongPtr( cmData_t* parent, unsigned long* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kULongPtrDtId);
- cmDataSetULongPtr(p,(unsigned long*)v,cnt);
- return p;
- }
-
- cmData_t* cmDataAllocFloatPtr( cmData_t* parent, float* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kFloatPtrDtId);
- cmDataSetFloatPtr(p,(float*)v,cnt);
- return p;
- }
-
- cmData_t* cmDataAllocDoublePtr( cmData_t* parent, double* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kDoublePtrDtId);
- cmDataSetDoublePtr(p,(double*)v,cnt);
- return p;
- }
-
- cmData_t* cmDataAllocVoidPtr( cmData_t* parent, void* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kVoidPtrDtId);
- cmDataSetCharPtr(p,(char*)v,cnt);
- p->tid = kVoidPtrDtId;
- return p;
- }
-
-
-
- // Dynamically allocate a data object and its array value.
- // v[cnt] is copied into the allocated array.
- cmData_t* cmDataStrAlloc( cmData_t* parent, cmChar_t* str )
- {
- cmData_t* p = _cmDataAllocNode(parent,kStrDtId);
- cmDataSetStrAlloc(p,str);
- return p;
- }
-
- cmData_t* cmDataConstStrAllocN( cmData_t* parent, const cmChar_t* str, unsigned charCnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kConstStrDtId);
- cmDataSetConstStrAllocN(p,str,charCnt);
- return p;
- }
-
-
- cmData_t* cmDataConstStrAlloc( cmData_t* parent, const cmChar_t* str )
- {
- cmData_t* p = _cmDataAllocNode(parent,kConstStrDtId);
- cmDataSetConstStrAlloc(p,str);
- return p;
- }
-
- cmData_t* cmDataCharAllocPtr( cmData_t* parent, const char* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kCharPtrDtId);
- cmDataSetCharAllocPtr(p, v, cnt );
- return p;
- }
-
- cmData_t* cmDataUCharAllocPtr( cmData_t* parent, const unsigned char* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kUCharPtrDtId);
- cmDataSetUCharAllocPtr(p, v, cnt );
- return p;
- }
-
- cmData_t* cmDataShortAllocPtr( cmData_t* parent, const short* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kShortPtrDtId);
- cmDataSetShortAllocPtr(p, v, cnt );
- return p;
- }
-
- cmData_t* cmDataUShortAllocPtr( cmData_t* parent, const unsigned short* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kUShortPtrDtId);
- cmDataSetUShortAllocPtr(p, v, cnt );
- return p;
- }
-
- cmData_t* cmDataIntAllocPtr( cmData_t* parent, const int* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kIntPtrDtId);
- cmDataSetIntAllocPtr(p, v, cnt );
- return p;
- }
-
- cmData_t* cmDataUIntAllocPtr( cmData_t* parent, const unsigned int* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kUIntPtrDtId);
- cmDataSetUIntAllocPtr(p, v, cnt );
- return p;
- }
-
- cmData_t* cmDataLongAllocPtr( cmData_t* parent, const long* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kLongPtrDtId);
- cmDataSetLongAllocPtr(p, v, cnt );
- return p;
- }
-
- cmData_t* cmDataULongAllocPtr( cmData_t* parent, const unsigned long* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kULongPtrDtId);
- cmDataSetULongAllocPtr(p, v, cnt );
- return p;
- }
-
- cmData_t* cmDataFloatAllocPtr( cmData_t* parent, const float* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kFloatPtrDtId);
- cmDataSetFloatAllocPtr(p, v, cnt );
- return p;
- }
-
- cmData_t* cmDataDoubleAllocPtr( cmData_t* parent, const double* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kDoublePtrDtId);
- cmDataSetDoubleAllocPtr(p, v, cnt );
- return p;
- }
-
-
- cmData_t* cmDataVoidAllocPtr( cmData_t* parent, const void* v, unsigned cnt )
- {
- cmData_t* p = _cmDataAllocNode(parent,kVoidPtrDtId);
- cmDataSetCharAllocPtr(p, (const char*)v, cnt );
- p->tid = kVoidPtrDtId;
- return p;
- }
-
- void cmDataFree( cmData_t* p )
- {
- _cmDataFree(p);
- }
-
- cmData_t* cmDataUnlink( cmData_t* p )
- {
- if( p->parent == NULL )
- return p;
-
- assert( cmDataIsStruct(p->parent) );
-
- cmData_t* cp = p->u.child;
- cmData_t* pp = NULL;
- for(; cp!=NULL; cp=cp->sibling)
- if( cp == p )
- {
- if( pp == NULL )
- p->parent->u.child = p->sibling;
- else
- pp->sibling = cp->sibling;
- }
- return p;
- }
-
- void cmDataUnlinkAndFree( cmData_t* p )
- {
- cmDataUnlink(p);
- cmDataFree(p);
- }
-
- cmData_t* _cmDataDupl( const cmData_t* p, cmData_t* parent )
- {
- cmData_t* rp = NULL;
-
- switch( p->tid )
- {
- case kNullDtId: rp = cmDataAllocNull(parent); break;
- case kUCharDtId: rp = cmDataAllocUChar(parent,p->u.uc); break;
- case kCharDtId: rp = cmDataAllocChar(parent,p->u.c); break;
- case kUShortDtId: rp = cmDataAllocShort(parent,p->u.us); break;
- case kShortDtId: rp = cmDataAllocUShort(parent,p->u.s); break;
- case kUIntDtId: rp = cmDataAllocUInt(parent,p->u.i); break;
- case kIntDtId: rp = cmDataAllocInt(parent,p->u.ui); break;
- case kULongDtId: rp = cmDataAllocULong(parent,p->u.ul); break;
- case kLongDtId: rp = cmDataAllocLong(parent,p->u.l); break;
- case kFloatDtId: rp = cmDataAllocFloat(parent,p->u.f); break;
- case kDoubleDtId: rp = cmDataAllocDouble(parent,p->u.d); break;
-
- case kStrDtId: rp = cmDataStrAlloc(parent,p->u.z); break;
- case kConstStrDtId: rp = cmDataConstStrAlloc(parent,p->u.cz); break;
- case kUCharPtrDtId: rp = cmDataUCharAllocPtr(parent,p->u.ucp,p->cnt); break;
- case kCharPtrDtId: rp = cmDataCharAllocPtr(parent,p->u.cp,p->cnt); break;
- case kUShortPtrDtId: rp = cmDataUShortAllocPtr(parent,p->u.usp,p->cnt); break;
- case kShortPtrDtId: rp = cmDataShortAllocPtr(parent,p->u.sp,p->cnt); break;
- case kUIntPtrDtId: rp = cmDataUIntAllocPtr(parent,p->u.uip,p->cnt); break;
- case kIntPtrDtId: rp = cmDataIntAllocPtr(parent,p->u.ip,p->cnt); break;
- case kULongPtrDtId: rp = cmDataULongAllocPtr(parent,p->u.ulp,p->cnt); break;
- case kLongPtrDtId: rp = cmDataLongAllocPtr(parent,p->u.lp,p->cnt); break;
- case kFloatPtrDtId: rp = cmDataFloatAllocPtr(parent,p->u.fp,p->cnt); break;
- case kDoublePtrDtId: rp = cmDataDoubleAllocPtr(parent,p->u.dp,p->cnt); break;
- case kVoidPtrDtId: rp = cmDataVoidAllocPtr(parent,p->u.vp,p->cnt); break;
-
- case kListDtId:
- case kPairDtId:
- case kRecordDtId:
- {
- rp = _cmDataAllocNode(parent,p->tid);
- cmData_t* cp = p->u.child;
- for(; cp!=NULL; cp=cp->sibling)
- cmDataAppendChild(rp,_cmDataDupl(cp,rp));
- }
- break;
-
- default:
- assert(0);
- }
-
- return rp;
- }
-
- cmData_t* cmDataDupl( const cmData_t* p )
- { return _cmDataDupl(p,NULL); }
-
- cmData_t* cmDataReplace( cmData_t* dst, cmData_t* src )
- {
- if( dst->parent == NULL )
- {
- cmDataUnlinkAndFree(dst);
- src->parent = NULL;
- return src;
- }
-
- cmData_t* parent = dst->parent;
- cmData_t* cp = parent->u.child;
- cmData_t* pp = NULL;
- unsigned i = 0;
- unsigned n = cmDataChildCount(parent);
-
- // locate dst's right sibling
- for(i=0; i<n; ++i,cp=cp->sibling)
- {
-
- if( cp == dst )
- {
- // link in 'src' in place of 'dst'
- src->sibling = dst->sibling;
-
- // free dst
- cmDataUnlinkAndFree(dst);
-
- // update the sibling link to
- if( pp == NULL )
- parent->u.child = src;
- else
- pp->sibling = src;
-
- src->parent = parent;
- break;
- }
- pp = cp;
- }
- return src;
- }
-
-
- unsigned cmDataChildCount( const cmData_t* p )
- {
- if( !cmDataIsStruct(p) )
- return 0;
-
- unsigned n = 0;
- const cmData_t* cp = p->u.child;
- for(; cp!=NULL; cp=cp->sibling)
- ++n;
-
- return n;
- }
-
- cmData_t* cmDataChild( cmData_t* p, unsigned index )
- {
- if( !cmDataIsStruct(p) )
- return NULL;
-
- unsigned n = 0;
- cmData_t* cp = p->u.child;
- for(; cp!=NULL; cp=cp->sibling)
- {
- if( n == index )
- break;
- ++n;
- }
-
- return cp;
- }
-
- cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p )
- {
- assert( cmDataIsStruct(p) );
-
-
- cmDataUnlink(p);
-
- p->u.child = parent->u.child;
- parent->u.child = p;
- p->parent = parent;
- return p;
- }
-
- cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p )
- {
- assert( cmDataIsStruct(parent) );
- assert( parent->tid != kRecordDtId || (parent->tid == kRecordDtId && p->tid==kPairDtId));
-
- cmDataUnlink(p);
-
- cmData_t* cp = parent->u.child;
- if( cp == NULL )
- parent->u.child = p;
- else
- {
- for(; cp!=NULL; cp=cp->sibling)
- if( cp->sibling == NULL )
- {
- cp->sibling = p;
- break;
- }
- }
-
- p->parent = parent;
- p->sibling = NULL;
- return p;
- }
-
- cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p )
- {
- if( !cmDataIsStruct(parent) )
- return NULL;
-
- cmDataUnlink(p);
-
- unsigned n = 0;
- cmData_t* cp = parent->u.child;
- cmData_t* pp = NULL;
- for(; cp!=NULL; cp=cp->sibling)
- {
- if( n == index )
- {
- if( pp == NULL )
- {
- parent->u.child = p;
- p->sibling = NULL;
- }
- else
- {
- p->sibling = pp->sibling;
- pp->sibling = p;
- }
- break;
-
- }
- ++n;
- }
-
- p->parent = parent;
-
- return p;
-
- }
-
- //----------------------------------------------------------------------------
-
- bool _cmDataPairIsValid( const cmData_t* p )
- {
- assert( p->tid == kPairDtId );
-
- bool fl = p->u.child == NULL || p->u.child->sibling == NULL || p->u.child->sibling->sibling!=NULL;
- return !fl;
- }
-
- // Get the key/value of a pair
- cmData_t* cmDataPairKey( cmData_t* p )
- {
- assert( _cmDataPairIsValid(p) );
- return p->u.child;
- }
-
- unsigned cmDataPairKeyId( cmData_t* p )
- {
- assert( _cmDataPairIsValid(p) );
- unsigned id = cmInvalidId;
- cmDataGetUInt(p->u.child,&id);
- return id;
- }
-
- const cmChar_t* cmDataPairKeyLabel( cmData_t* p )
- {
- assert( _cmDataPairIsValid(p) );
- const cmChar_t* label = NULL;
- cmDataGetConstStr(p->u.child,&label);
- return label;
- }
-
-
- cmData_t* cmDataPairValue( cmData_t* p )
- {
- assert( _cmDataPairIsValid(p) );
- return p->u.child->sibling;
- }
-
- // Set the key or value of an existing pair node.
- cmData_t* cmDataPairSetValue( cmData_t* p, cmData_t* value )
- {
- assert( _cmDataPairIsValid(p) );
- cmDataReplace( cmDataPairValue(p), value );
- return p;
- }
-
-
- cmData_t* cmDataPairSetKey( cmData_t* p, cmData_t* key )
- {
- assert( _cmDataPairIsValid(p) );
- cmDataReplace( cmDataPairValue(p), key );
- return p;
- }
-
- cmData_t* cmDataPairSetKeyId( cmData_t* p, unsigned id )
- {
- assert( _cmDataPairIsValid(p) );
- cmDataSetUInt(p->u.child,id);
- return p;
- }
-
- cmData_t* cmDataPairSetKeyLabel( cmData_t* p, const cmChar_t* label )
- {
- assert( _cmDataPairIsValid(p) );
- cmDataSetConstStrAlloc(p->u.child,label);
- return p;
- }
-
-
- cmData_t* cmDataMakePair( cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t* value )
- {
- _cmDataFree(p);
- p->tid = kPairDtId;
- p->parent = parent;
- p->flags = 0;
- p->u.child = NULL;
- cmDataAppendChild(p,key);
- cmDataAppendChild(p,value);
- return p;
- }
-
- // Dynamically allocate a pair node
- cmData_t* cmDataAllocPair( cmData_t* parent, const cmData_t* key, const cmData_t* value )
- {
- cmData_t* p = _cmDataAllocNode(parent,kPairDtId);
- cmData_t* kp = cmDataDupl(key);
- cmData_t* vp = cmDataDupl(value);
- cmDataPrependChild(p,vp);
- cmDataPrependChild(p,kp);
- return p;
- }
-
- cmData_t* cmDataAllocPairId(cmData_t* parent, unsigned keyId, cmData_t* value )
- {
- cmData_t* p = _cmDataAllocNode(parent,kPairDtId);
- cmDataAllocUInt(p,keyId);
- cmDataAppendChild(p,value);
- return p;
- }
-
- cmData_t* cmDataAllocPairLabel( cmData_t* parent, const cmChar_t *label, cmData_t* value )
- {
- cmData_t* p = _cmDataAllocNode(parent,kPairDtId);
- cmDataConstStrAlloc(p,label);
- cmDataAppendChild(p,value);
- return p;
- }
-
- cmData_t* cmDataAllocPairLabelN(cmData_t* parent, const cmChar_t* label, unsigned charCnt, cmData_t* value)
- {
- cmData_t* p = _cmDataAllocNode(parent,kPairDtId);
- cmDataConstStrAllocN(p,label,charCnt);
- cmDataAppendChild(p,value);
- return p;
- }
-
-
- //----------------------------------------------------------------------------
-
- unsigned cmDataListCount(const cmData_t* p )
- { return cmDataChildCount(p); }
-
- cmData_t* cmDataListEle( cmData_t* p, unsigned index )
- { return cmDataChild(p,index); }
-
- cmData_t* cmDataListMake( cmData_t* parent, cmData_t* p )
- {
- _cmDataFree(p);
- p->parent = parent;
- p->tid = kListDtId;
- p->flags = 0;
- p->u.child = NULL;
- return p;
- }
-
- cmData_t* cmDataListAlloc( cmData_t* parent)
- { return _cmDataAllocNode(parent,kListDtId); }
-
- cmDtRC_t _cmDataParseArgV( cmData_t* parent, va_list vl, cmData_t** vpp )
- {
- cmDtRC_t rc = kOkDtRC;
- cmData_t* vp = NULL;
- unsigned tid = va_arg(vl,unsigned);
-
- switch(tid)
- {
- case kInvalidDtId: rc = kEolDtRC; break;
- case kNullDtId: vp = cmDataAllocNull(parent); break;
- case kUCharDtId: vp = cmDataAllocUChar( parent,va_arg(vl,int)); break;
- case kCharDtId: vp = cmDataAllocChar( parent,va_arg(vl,int)); break;
- case kUShortDtId: vp = cmDataAllocUShort( parent,va_arg(vl,int)); break;
- case kShortDtId: vp = cmDataAllocShort( parent,va_arg(vl,int)); break;
- case kUIntDtId: vp = cmDataAllocUInt( parent,va_arg(vl,unsigned int)); break;
- case kIntDtId: vp = cmDataAllocInt( parent,va_arg(vl,int)); break;
- case kULongDtId: vp = cmDataAllocULong( parent,va_arg(vl,unsigned long)); break;
- case kLongDtId: vp = cmDataAllocLong( parent,va_arg(vl,long)); break;
- case kFloatDtId: vp = cmDataAllocFloat( parent,va_arg(vl,double)); break;
- case kDoubleDtId: vp = cmDataAllocDouble( parent,va_arg(vl,double)); break;
-
- case kStrDtId: vp = cmDataStrAlloc( parent,va_arg(vl,cmChar_t*)); break;
- case kConstStrDtId: vp = cmDataConstStrAlloc( parent,va_arg(vl,const cmChar_t*)); break;
-
- case kUCharPtrDtId:
- {
- unsigned char* p = va_arg(vl,unsigned char*);
- vp = cmDataUCharAllocPtr(parent, p, va_arg(vl,unsigned));
- }
- break;
-
- case kCharPtrDtId:
- {
- char* p = va_arg(vl,char*);
- vp = cmDataCharAllocPtr(parent, p, va_arg(vl,unsigned));
- }
- break;
-
- case kUShortPtrDtId:
- {
- unsigned short* p = va_arg(vl,unsigned short*);
- vp = cmDataUShortAllocPtr(parent, p, va_arg(vl,unsigned));
- }
- break;
-
- case kShortPtrDtId:
- {
- short* p = va_arg(vl,short*);
- vp = cmDataShortAllocPtr(parent, p, va_arg(vl,unsigned));
- }
- break;
-
- case kUIntPtrDtId:
- {
- unsigned int* p = va_arg(vl,unsigned int*);
- vp = cmDataUIntAllocPtr(parent, p, va_arg(vl,unsigned));
- }
- break;
-
- case kIntPtrDtId:
- {
- int * p = va_arg(vl,int*);
- vp = cmDataIntAllocPtr(parent, p, va_arg(vl,unsigned));
- }
- break;
-
- case kULongPtrDtId:
- {
- unsigned long* p = va_arg(vl,unsigned long*);
- vp = cmDataULongAllocPtr(parent, p, va_arg(vl,unsigned));
- }
- break;
-
- case kLongPtrDtId:
- {
- long* p = va_arg(vl,long*);
- vp = cmDataLongAllocPtr(parent, p, va_arg(vl,unsigned));
- }
- break;
-
- case kFloatPtrDtId:
- {
- float* p = va_arg(vl,float*);
- vp = cmDataFloatAllocPtr(parent, p, va_arg(vl,unsigned));
- }
- break;
-
- case kDoublePtrDtId:
- {
- double* p = va_arg(vl,double*);
- vp = cmDataDoubleAllocPtr(parent,p, va_arg(vl,unsigned));
- }
- break;
-
- case kVoidPtrDtId:
- {
- void* p = va_arg(vl,void*);
- vp = cmDataVoidAllocPtr(parent, p, va_arg(vl,unsigned));
- }
- break;
-
- case kListDtId:
- case kPairDtId:
- case kRecordDtId:
- vp = _cmDataAllocNode(parent,tid);
- break;
-
- default:
- _cmDataSetError(kVarArgErrDtRC);
- break;
- }
-
- *vpp = vp;
-
- return rc;
- }
-
- cmData_t* _cmDataListParseV(cmData_t* parent, va_list vl )
- {
- cmData_t* p = NULL;
- bool contFl = true;
-
- while( contFl )
- {
- cmData_t* vp;
- cmDtRC_t rc = _cmDataParseArgV(parent, vl, &vp);
-
- if(rc != kOkDtRC || cmDataAppendChild(parent,vp)==NULL )
- contFl = false;
-
- }
- return p;
- }
-
- cmData_t* cmDataListAllocV(cmData_t* parent, va_list vl )
- {
- cmData_t* p = cmDataListAlloc(parent);
- _cmDataListParseV(p, vl );
- return p;
- }
-
- cmData_t* cmDataListAllocA(cmData_t* parent, ... )
- {
- va_list vl;
- va_start(vl,parent);
- cmData_t* p = cmDataListAllocV(parent,vl);
- va_end(vl);
- return p;
- }
-
-
- cmData_t* cmDataListAppendEle( cmData_t* p, cmData_t* ele )
- {
- assert(p->tid == kListDtId);
- return cmDataAppendChild(p,ele);
- }
-
- cmData_t* cmDataListAppendEleN(cmData_t* p, cmData_t* ele[], unsigned n )
- {
- assert(p->tid == kListDtId);
-
- cmData_t* rp = NULL;
- unsigned i;
- for(i=0; i<n; ++i)
- {
- cmData_t* ep = cmDataAppendChild(p,ele[i]);
- if( rp == NULL )
- rp = ep;
- }
- return rp;
- }
-
- cmDtRC_t cmDataListAppendV( cmData_t* p, va_list vl )
- {
- if( _cmDataListParseV(p, vl ) == NULL )
- return _cmDataErrNo;
-
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataListAppend( cmData_t* p, ... )
- {
- va_list vl;
- va_start(vl,p);
- cmDtRC_t rc = cmDataListAppendV(p,vl);
- va_end(vl);
- return rc;
- }
-
- cmData_t* cmDataListInsertEle( cmData_t* p, unsigned index, cmData_t* ele )
- { return cmDataInsertChild(p,index,ele); }
-
- cmData_t* cmDataListInsertEleN(cmData_t* p, unsigned index, cmData_t* ele[], unsigned n )
- {
- unsigned i;
- for(i=0; i<n; ++i)
- cmDataListInsertEle(p,index+i,ele[i]);
- return p;
- }
-
-
- //----------------------------------------------------------------------------
- unsigned cmDataRecdCount( const cmData_t* p )
- {
- assert( p->tid == kRecordDtId );
- return cmDataChildCount(p);
- }
-
- cmData_t* cmDataRecdEle( cmData_t* p, unsigned index )
- {
- assert( p->tid == kRecordDtId );
- cmData_t* cp = cmDataChild(p,index);
- assert( p->tid == kPairDtId );
- return cp;
- }
-
- cmData_t* cmDataRecdValueFromIndex( cmData_t* p, unsigned index )
- {
- assert( p->tid == kRecordDtId );
- cmData_t* cp = cmDataChild(p,index);
- assert( p->tid == kPairDtId );
- return cmDataPairValue(cp);
- }
-
- cmData_t* cmDataRecdValueFromId( cmData_t* p, unsigned id )
- {
- assert( p->tid == kRecordDtId );
- cmData_t* cp = p->u.child;
- for(; cp!=NULL; cp=cp->sibling)
- if( cmDataPairKeyId(cp) == id )
- break;
-
- assert( cp!=NULL && cp->tid==kPairDtId );
-
- return cmDataPairValue(cp);
- }
-
- cmData_t* cmDataRecdValueFromLabel( cmData_t* p, const cmChar_t* label )
- {
- assert( p->tid == kRecordDtId );
- cmData_t* cp = p->u.child;
- for(; cp!=NULL; cp=cp->sibling)
- {
- const cmChar_t* lp = cmDataPairKeyLabel(cp);
-
- if( lp!=NULL && strcmp(lp,label)==0 )
- break;
- }
- assert( cp!=NULL && cp->tid==kPairDtId );
-
- return cmDataPairValue(cp);
- }
-
- cmData_t* cmDataRecdKey( cmData_t* p, unsigned index )
- {
- assert( p->tid == kRecordDtId );
- cmData_t* cp = cmDataChild(p,index);
- assert( p->tid == kPairDtId );
- return cmDataPairKey(cp);
- }
-
- unsigned cmDataRecdKeyId( cmData_t* p, unsigned index )
- {
- cmData_t* kp = cmDataRecdKey(p,index);
- unsigned id = cmInvalidId;
- cmDataGetUInt(kp,&id);
- return id;
- }
-
- const cmChar_t* cmDataRecdKeyLabel( cmData_t* p, unsigned index )
- {
- cmData_t* kp = cmDataRecdKey(p,index);
- const cmChar_t* label = NULL;
- cmDataGetConstStr(kp,&label);
- return label;
- }
-
- cmData_t* cmDataRecdMake( cmData_t* parent, cmData_t* p )
- {
- _cmDataFree(p);
- p->parent = parent;
- p->tid = kRecordDtId;
- p->flags = 0;
- p->u.child = NULL;
- return p;
- }
-
- cmData_t* cmDataRecdAlloc(cmData_t* parent)
- { return _cmDataAllocNode(parent,kRecordDtId); }
-
- cmData_t* cmDataRecdAppendPair( cmData_t* p, cmData_t* pair )
- {
- assert( p!=NULL && p->tid==kRecordDtId);
- cmDataAppendChild(p,pair);
- return p;
- }
-
-
- cmDtRC_t _cmDataRecdParseInputV(cmData_t* parent, unsigned idFl, va_list vl )
- {
- assert( parent != NULL && parent->tid == kRecordDtId );
- bool contFl = true;
- cmDtRC_t rc = kOkDtRC;
-
- // for each record field
- while( contFl )
- {
- cmData_t* vp = NULL;
- unsigned id = cmInvalidId;
- const cmChar_t* label = NULL;
-
- // parse the field idenfier
- if( idFl )
- id = va_arg(vl,unsigned); // numeric field identifier
- else
- label = va_arg(vl,const char*); // text field label identifier
-
- // validate the field identifier
- if( (idFl && id==kInvalidDtId) || (!idFl && label==NULL) )
- break;
-
- // parse the field data
- if((rc =_cmDataParseArgV( NULL, vl, &vp )) != kOkDtRC )
- {
- contFl = false;
- }
- else
- {
- // create the field pair
- if( idFl )
- cmDataAllocPairId(parent,id,vp);
- else
- cmDataAllocPairLabel(parent,label,vp);
- }
- }
- return rc;
- }
-
- cmData_t* cmDataRecdAllocLabelV( cmData_t* parent, va_list vl )
- {
- cmData_t* p = cmDataRecdAlloc(parent);
- cmDtRC_t rc = _cmDataRecdParseInputV(p, false, vl );
- if( rc != kOkDtRC )
- {
- cmDataFree(p);
- p = NULL;
- }
- return p;
- }
-
- cmData_t* cmDataRecdAllocLabelA( cmData_t* parent, ... )
- {
- va_list vl;
- va_start(vl,parent);
- cmData_t* p = cmDataRecdAllocLabelV(parent,vl);
- va_end(vl);
- return p;
- }
-
- cmData_t* cmDataRecdAllocIdV( cmData_t* parent, va_list vl )
- {
- cmData_t* p = cmDataRecdAlloc(parent);
- cmDtRC_t rc = _cmDataRecdParseInputV(p, true, vl );
- if( rc != kOkDtRC )
- {
- cmDataFree(p);
- p = NULL;
- }
- return p;
- }
-
- cmData_t* cmDataRecdAllocIdA( cmData_t* parent, ... )
- {
- va_list vl;
- va_start(vl,parent);
- cmData_t* p = cmDataRecdAllocIdV(parent,vl);
- va_end(vl);
- return p;
- }
-
- cmDtRC_t _cmDataRecdParseV(cmData_t* p, bool idFl, cmErr_t* err, unsigned errRC, va_list vl )
- {
- bool contFl = true;
- cmDtRC_t rc = kOkDtRC;
-
- while( contFl )
- {
- unsigned id;
- const char* label;
-
- // parse the field idenfier
- if( idFl )
- id = va_arg(vl,unsigned); // numeric field identifier
- else
- label = va_arg(vl,const char*); // text field label identifier
-
- // validate the field identifier
- if( (idFl && id==kInvalidDtId) || (!idFl && label==NULL) )
- break;
-
- cmDataFmtId_t typeId = va_arg(vl,unsigned);
- void* v = va_arg(vl,void*);
- cmData_t* np = NULL;
- bool optFl = cmIsFlag(typeId,kOptArgDtFl);
- cmDtRC_t rc0 = kOkDtRC;
-
- typeId = cmClrFlag(typeId,kOptArgDtFl);
-
- if( idFl )
- np = cmDataRecdValueFromLabel( p, label );
- else
- np = cmDataRecdValueFromId( p, id );
-
- // if the field was not found
- if( np == NULL )
- {
- if(optFl)
- continue;
-
- if( err != NULL )
- {
- if( idFl )
- cmErrMsg(err,errRC,"The required field (id=%i) was not found.",id);
- else
- cmErrMsg(err,errRC,"The required field '%s' was not found.",cmStringNullGuard(label));
- }
-
- rc = kMissingFieldDtRC;
- }
-
- switch(typeId)
- {
- case kNullDtId:
- break;
-
- case kUCharDtId:
- rc0 = cmDataGetUChar(np,(unsigned char*)v);
- break;
-
- case kCharDtId:
- rc0 = cmDataGetChar(np,(char*)v);
- break;
-
- case kUShortDtId:
- rc0 = cmDataGetUShort(np,(unsigned short*)v);
- break;
-
- case kShortDtId:
- rc0 = cmDataGetShort(np,(short*)v);
- break;
-
- case kUIntDtId:
- rc0 = cmDataGetUInt(np,(unsigned int*)v);
- break;
-
- case kIntDtId:
- rc0 = cmDataGetInt(np,(int*)v);
- break;
-
- case kULongDtId:
- rc0 = cmDataGetULong(np,(unsigned long*)v);
- break;
-
- case kLongDtId:
- rc0 = cmDataGetLong(np,(long*)v);
- break;
-
- case kFloatDtId:
- rc0 = cmDataGetFloat(np,(float*)v);
- break;
-
- case kDoubleDtId:
- rc0 = cmDataGetDouble(np,(double*)v);
- break;
-
- case kStrDtId:
- rc0 = cmDataGetStr(np,(char**)v);
- break;
-
- case kConstStrDtId:
- rc0 = cmDataGetConstStr(np,(const char**)v);
- break;
-
- case kUCharPtrDtId:
- rc0 = cmDataGetUCharPtr(np,(unsigned char**)v);
- break;
-
- case kCharPtrDtId:
- rc0 = cmDataGetCharPtr(np,(char**)v);
- break;
-
- case kUShortPtrDtId:
- rc0 = cmDataGetUShortPtr(np,(unsigned short**)v);
- break;
-
- case kShortPtrDtId:
- rc0 = cmDataGetShortPtr(np,(short**)v);
- break;
-
- case kUIntPtrDtId:
- rc0 = cmDataGetUIntPtr(np,(unsigned int**)v);
- break;
-
- case kIntPtrDtId:
- rc0 = cmDataGetIntPtr(np,(int**)v);
- break;
-
- case kULongPtrDtId:
- rc0 = cmDataGetULongPtr(np,(unsigned long**)v);
- break;
-
- case kLongPtrDtId:
- rc0 = cmDataGetLongPtr(np,(long**)v);
- break;
-
- case kFloatPtrDtId:
- rc0 = cmDataGetFloatPtr(np,(float**)v);
- break;
-
- case kDoublePtrDtId:
- rc0 = cmDataGetDoublePtr(np,(double**)v);
- break;
-
- case kVoidPtrDtId:
- rc0 = cmDataGetVoidPtr(np,(void**)v);
- break;
-
- case kListDtId:
- case kPairDtId:
- case kRecordDtId:
- if( np->tid != typeId )
- rc0 = _cmDataSetError(kCvtErrDtRC);
- else
- *(cmData_t**)v = np;
- break;
-
- default:
- rc0 = _cmDataSetError(kVarArgErrDtRC);
- assert(0);
- }
-
- if( rc0 != kOkDtRC && err!=NULL)
- {
- if( idFl )
- cmErrMsg(err,errRC,"Unable to convert field (id=%i) to requested type.",id);
- else
- cmErrMsg(err,errRC,"Unable to convert field '%s' to requisted type.",cmStringNullGuard(label));
-
- rc = rc0;
- }
- }
-
- return rc;
- }
-
- cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl )
- { return _cmDataRecdParseV(p,false,err,errRC,vl); }
-
- cmDtRC_t cmDataRecdParseLabel(cmData_t* p, cmErr_t* err, unsigned errRC, ... )
- {
- va_list vl;
- va_start(vl,errRC);
- cmDtRC_t rc = cmDataRecdParseLabelV(p,err,errRC,vl);
- va_end(vl);
- return rc;
- }
-
- cmDtRC_t cmDataRecdParseIdV(cmData_t* p, cmErr_t* err, unsigned errRC, va_list vl )
- { return _cmDataRecdParseV(p,true,err,errRC,vl); }
-
- cmDtRC_t cmDataRecdParseId(cmData_t* p, cmErr_t* err, unsigned errRC, ... )
- {
- va_list vl;
- va_start(vl,errRC);
- cmDtRC_t rc = cmDataRecdParseIdV(p,err,errRC,vl);
- va_end(vl);
- return rc;
- }
-
-
-
- //============================================================================
- //============================================================================
- //============================================================================
-
- unsigned _cmDataSerializeNodeByteCount( const cmData_t* p )
- {
- unsigned n = 0;
-
- // all serialized data ele's begin with a cmDataFmtId_t
- n += sizeof(cmDataFmtId_t);
-
- // arrays then have a count of bytes and structures have a child count
- if( cmDataIsPtr(p) || cmDataIsStruct(p) )
- n += sizeof(unsigned);
-
- // then the data itself takes a variable number of bytes
- n += _cmDataByteCount(p);
-
- return n;
- }
-
- unsigned cmDataSerializeByteCount( const cmData_t* p )
- {
- unsigned bn = 0;
-
- // if this data type has a child then calculate it's size
- if( kMinStructDtId <= p->tid && p->tid <= kMaxStructDtId && p->u.child != NULL )
- bn = cmDataSerializeByteCount(p->u.child);
-
- // if this data type has siblings get their type
- cmData_t* dp = p->u.child;
- for(; dp != NULL; dp=dp->sibling )
- bn += cmDataSerializeByteCount(dp->sibling);
-
-
- //
- return bn + _cmDataSerializeNodeByteCount(p);
- }
-
- char* _cmDataSerializeWriteArray( cmData_t* np, char* dp, const char* ep )
- {
- unsigned byteCnt = _cmDataByteCount(np);
-
- *((unsigned*)dp) = byteCnt;
- dp += sizeof(unsigned);
-
- memcpy(dp,np->u.vp,byteCnt);
- dp += byteCnt;
-
- return dp;
- }
-
- char* _cmDataSerializeWriteStruct( cmData_t* np, char* dp, const char* ep )
- {
- *((unsigned*)dp) = cmDataChildCount(np);
- dp += sizeof(unsigned);
-
- return dp;
- }
-
-
- char* _cmDataSerializeWrite( cmData_t* np, char* dp, const char* ep )
- {
- assert( dp + _cmDataSerializeNodeByteCount(np) <= ep );
-
- *((cmDataFmtId_t*)dp) = np->tid;
- dp += sizeof(cmDataFmtId_t);
-
- switch( np->tid )
- {
- case kNullDtId: break;
- case kUCharDtId: *((unsigned char*)dp) = cmDataUChar(np); dp+=sizeof(unsigned char); break;
- case kCharDtId: *((char*)dp) = cmDataChar(np); dp+=sizeof(char); break;
- case kUShortDtId: *((unsigned short*)dp) = cmDataUShort(np); dp+=sizeof(unsigned short); break;
- case kShortDtId: *((short*)dp) = cmDataShort(np); dp+=sizeof(short); break;
- case kUIntDtId: *((unsigned int*)dp) = cmDataUInt(np); dp+=sizeof(unsigned int); break;
- case kIntDtId: *((int*)dp) = cmDataInt(np); dp+=sizeof(int); break;
- case kULongDtId: *((unsigned long*)dp) = cmDataULong(np); dp+=sizeof(unsigned long); break;
- case kLongDtId: *((long*)dp) = cmDataLong(np); dp+=sizeof(long); break;
- case kFloatDtId: *((float*)dp) = cmDataFloat(np); dp+=sizeof(float); break;
- case kDoubleDtId: *((double*)dp) = cmDataDouble(np); dp+=sizeof(double); break;
- case kStrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kConstStrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kUCharPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kCharPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kUShortPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kShortPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kUIntPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kIntPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kULongPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kLongPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kFloatPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kDoublePtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kVoidPtrDtId: dp = _cmDataSerializeWriteArray(np,dp,ep); break;
- case kListDtId: dp = _cmDataSerializeWriteStruct(np,dp,ep); break;
- case kPairDtId: dp = _cmDataSerializeWriteStruct(np,dp,ep); break;
- case kRecordDtId: dp = _cmDataSerializeWriteStruct(np,dp,ep); break;
- default:
- { assert(0); }
- }
- return dp;
- }
-
- char* _cmDataSerialize( const cmData_t* p, char* buf, const char* ep )
- {
- /*
- buf = _cmDataSerializeWrite(p,buf,ep);
-
- // if this data type has a child then write the child
- if( kMinStructDtId <= p->tid && p->tid <= kMaxStructDtId && p->u.child != NULL )
- buf = _cmDataSerialize(p->u.child,buf,ep);
-
- // if this data type has siblings then write sibings
- cmData_t* dp = p->u.child;
- for(; dp != NULL; dp=dp->sibling )
- buf = cmDataSerialize(dp->sibling,buf,ep);
-
- return buf;
- */
- return NULL;
- }
-
- cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt )
- {
- /*
- const char* ep = (char*)p + bufByteCnt;
- buf = _cmDataSerialize(p,buf,bufByteCnt);
- assert( buf <= ep );
- */
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataDeserialize( const void* buf, unsigned bufByteCnt, cmData_t** pp )
- {
- return kOkDtRC;
- }
-
- //============================================================================
- //============================================================================
- //============================================================================
- enum
- {
- kLCurlyLexTId = kUserLexTId + 1,
- kRCurlyLexTId,
- kLParenLexTId,
- kRParenLexTId,
- kLBrackLexTId,
- kRBrackLexTId,
- kColonLexTId,
- kCommaLexTId,
- };
-
- typedef struct
- {
- unsigned id;
- const cmChar_t* label;
- } cmDtToken_t;
-
- cmDtToken_t _cmDtTokenArray[] =
- {
- { kLCurlyLexTId, "{" },
- { kRCurlyLexTId, "}" },
- { kLBrackLexTId, "[" },
- { kRBrackLexTId, "]" },
- { kLParenLexTId, "(" },
- { kRParenLexTId, ")" },
- { kColonLexTId, ":" },
- { kCommaLexTId, "," },
- { kErrorLexTId,""}
-
- };
-
- typedef struct
- {
- cmErr_t err;
- cmLexH lexH;
- cmStackH_t stH;
-
- } cmDataParser_t;
-
-
- cmDataParserH_t cmDataParserNullHandle = cmSTATIC_NULL_HANDLE;
-
- cmDataParser_t* _cmDataParserHandleToPtr( cmDataParserH_t h )
- {
- cmDataParser_t* p = (cmDataParser_t*)h.h;
- assert( p!= NULL );
- return p;
- }
-
- cmDtRC_t _cmDataParserDestroy( cmDataParser_t* p )
- {
- if( cmLexFinal(&p->lexH) != kOkLexRC )
- cmErrMsg(&p->err,kLexFailDtRC,"Lexer release failed.");
-
- if( cmStackFree(&p->stH) != kOkStRC )
- cmErrMsg(&p->err,kParseStackFailDtRC,"The data object parser stack release failed.");
-
- cmMemFree(p);
-
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataParserCreate( cmCtx_t* ctx, cmDataParserH_t* hp )
- {
- cmDtRC_t rc;
- unsigned i;
-
- if((rc = cmDataParserDestroy(hp)) != kOkDtRC )
- return rc;
-
- cmDataParser_t* p = cmMemAllocZ(cmDataParser_t,1);
-
- cmErrSetup(&p->err,&ctx->rpt,"Data Parser");
-
- if(cmLexIsValid(p->lexH = cmLexInit(NULL,0,0,&ctx->rpt))==false)
- {
- rc = cmErrMsg(&p->err, kLexFailDtRC, "The data object parser lexer create failed.");
- goto errLabel;
- }
-
- for(i=0; _cmDtTokenArray[i].id != kErrorLexTId; ++i)
- if( cmLexRegisterToken(p->lexH, _cmDtTokenArray[i].id, _cmDtTokenArray[i].label) != kOkLexRC )
- {
- rc = cmErrMsg(&p->err,kLexFailDtRC,"The data object parser lexer could not register the '%s' token.",_cmDtTokenArray[i].label);
- goto errLabel;
- }
-
- if( cmStackAlloc(ctx, &p->stH, 1024, 1024, sizeof(cmData_t*)) != kOkStRC )
- {
- rc = cmErrMsg(&p->err,kParseStackFailDtRC,"The data object parser stack create failed.");
- goto errLabel;
- }
-
- hp->h = p;
-
- errLabel:
- if( rc != kOkDtRC )
- _cmDataParserDestroy(p);
-
- return kOkDtRC;
- }
-
- cmDtRC_t cmDataParserDestroy( cmDataParserH_t* hp )
- {
- cmDtRC_t rc=kOkDtRC;
-
- if( hp==NULL || cmDataParserIsValid(*hp)==false )
- return rc;
-
- cmDataParser_t* p = _cmDataParserHandleToPtr(*hp);
-
- if((rc = _cmDataParserDestroy(p)) != kOkDtRC )
- return rc;
-
- hp->h = NULL;
-
- return kOkDtRC;
- }
-
-
- bool cmDataParserIsValid( cmDataParserH_t h )
- { return h.h != NULL; }
-
-
-
- // {
- // id0 : scalar_value
- // id1 : ( heterogenous, array, value )
- // id2 : [ homogeneous array values ]
- // id3 :
- // }
-
-
- // flags describing the expected next token
- enum
- {
- kValueExpFl = 0x01,
- kIdExpFl = 0x02,
- kColonExpFl = 0x04,
- kCommaExpFl = 0x08
- };
-
- typedef struct
- {
- cmData_t* dp;
- } cmDataStEle_t;
-
- typedef struct
- {
- cmDataParser_t* p;
- cmData_t* cnp;
- unsigned flags;
- cmChar_t* tmpStr;
-
- unsigned arrayCnt;
- void* arrayMem;
-
- } cmDataParserCtx_t;
-
- cmDtRC_t _cmDpSyntaxErrV( cmDataParserCtx_t* c, const cmChar_t* fmt, va_list vl )
- {
- cmChar_t* s0 = NULL;
- cmChar_t* s1 = NULL;
- s0 = cmTsVPrintfP(s0,fmt,vl);
- s1 = cmMemAllocStrN(cmLexTokenText(c->p->lexH),cmLexTokenCharCount(c->p->lexH));
- cmDtRC_t rc = cmErrMsg(&c->p->err,kSyntaxErrDtRC,"Syntax error on line %i column:%i token:'%s'. %s",cmLexCurrentLineNumber(c->p->lexH),cmLexCurrentColumnNumber(c->p->lexH),s1,cmStringNullGuard(s0));
- cmMemFree(s0);
- cmMemFree(s1);
- return rc;
- }
-
- cmDtRC_t _cmDpSyntaxErr( cmDataParserCtx_t* c, const cmChar_t* fmt, ... )
- {
- va_list vl;
- va_start(vl,fmt);
- cmDtRC_t rc = _cmDpSyntaxErrV(c,fmt,vl);
- va_end(vl);
- return rc;
- }
-
- cmDtRC_t _cmDpPopStack( cmDataParserCtx_t* c, cmData_t** pp )
- {
- const void* vp;
- if((vp = cmStackTop(c->p->stH)) == NULL )
- return _cmDpSyntaxErr(c,"Stack underflow.");
-
- if( cmStackPop(c->p->stH,1) != kOkStRC )
- return _cmDpSyntaxErr(c,"Stack pop failed.");
-
- *pp = *(cmData_t**)vp;
-
- //printf("pop: %p\n",*pp);
-
- return kOkDtRC;
- }
-
- cmDtRC_t _cmDpPushStack( cmDataParserCtx_t* c, cmData_t* np )
- {
- //printf("push:%p\n",np);
-
- // store the current node
- if( cmStackPush(c->p->stH, &np, 1 ) != kOkStRC )
- return _cmDpSyntaxErr(c,"Parser stack push failed.");
-
- return kOkDtRC;
- }
-
- cmDtRC_t _cmDpStoreArrayEle( cmDataParserCtx_t* c, void* dp, unsigned eleByteCnt, unsigned tid )
- {
- if( c->cnp->tid == kVoidPtrDtId )
- c->cnp->tid = tid;
- else
- if( c->cnp->tid != tid )
- return _cmDpSyntaxErr(c,"Mixed types were detected in an array list.");
-
- unsigned newByteCnt = (c->cnp->cnt+1)*eleByteCnt;
- char* vp = cmMemResizeP(char, c->cnp->u.vp, newByteCnt);
-
- memcpy(vp + c->cnp->cnt*eleByteCnt,dp,eleByteCnt);
- c->cnp->u.vp = vp;
- c->cnp->cnt += 1;
-
- c->flags = kValueExpFl | kCommaExpFl;
-
- return kOkDtRC;
- }
-
- cmDtRC_t _cmDataParserOpenPair( cmDataParserCtx_t* c )
- {
- cmDtRC_t rc = kOkDtRC;
-
- assert( c->cnp->tid == kRecordDtId );
-
- // create a pair with a 'null' value which will be replaced when the pair's value is parsed
- cmData_t* nnp = cmDataAllocNull(NULL);
- cmData_t* pnp = cmDataAllocPairLabelN( c->cnp, cmLexTokenText(c->p->lexH), cmLexTokenCharCount(c->p->lexH), nnp );
-
- // store the current node
- if((rc = _cmDpPushStack(c,c->cnp)) != kOkDtRC )
- return rc;
-
- // make the new pair the current node
- c->cnp = pnp;
-
- // pair openings must be followed by a colon.
- c->flags = kColonExpFl;
-
- return rc;
- }
-
- cmDtRC_t _cmDataParserClosePair( cmDataParserCtx_t* c )
- {
- cmDtRC_t rc;
-
- // make the pair's parent record the current node
- if((rc = _cmDpPopStack(c, &c->cnp )) != kOkDtRC )
- return rc;
-
- // pairs only occur in records
- if( c->cnp->tid != kRecordDtId )
- return _cmDpSyntaxErr(c,"A 'pair' end was found outside of a 'record'.");
-
- // pairs must be followed by id's or comma's
- c->flags = kIdExpFl | kCommaExpFl;
-
- return rc;
- }
-
- cmDtRC_t _cmDpStoreValue( cmDataParserCtx_t* c, cmData_t* np, const cmChar_t* typeLabel )
- {
- assert( np != NULL );
-
- cmDtRC_t rc = kOkDtRC;
-
- switch( c->cnp->tid )
- {
- case kPairDtId:
-
- // assign the new node as the value of the pair
- cmDataPairSetValue(c->cnp,np);
-
- // close the values parent pair
- rc = _cmDataParserClosePair(c);
- break;
-
- case kListDtId:
- cmDataAppendChild(c->cnp,np);
- c->flags = kValueExpFl;
- break;
-
- default:
- rc = _cmDpSyntaxErr(c,"A '%s' value was found outside of a valid container.",typeLabel);
-
- // Free the new data node because it was not attached and will
- // otherwise be lost
- cmDataFree(np);
-
- }
-
- c->flags |= kCommaExpFl;
-
- return rc;
- }
-
- cmDtRC_t _cmDataParserReal( cmDataParserCtx_t* c )
- {
- cmDtRC_t rc = kOkDtRC;
- bool floatFl = cmLexTokenIsSinglePrecision(c->p->lexH);
- double dval;
- float fval;
-
- if( floatFl )
- fval = cmLexTokenFloat(c->p->lexH);
- else
- dval = cmLexTokenDouble(c->p->lexH);
-
-
- if( cmDataIsPtr(c->cnp) )
- {
- if( floatFl )
- rc = _cmDpStoreArrayEle(c,&fval,sizeof(fval),kFloatPtrDtId);
- else
- rc = _cmDpStoreArrayEle(c,&dval,sizeof(dval),kDoublePtrDtId);
- }
- else
- {
- cmData_t* np = floatFl ? cmDataAllocFloat(NULL,fval) : cmDataAllocDouble(NULL,dval);
- rc = _cmDpStoreValue(c,np,"real");
- }
- return rc;
- }
-
- cmDtRC_t _cmDataParserInt( cmDataParserCtx_t* c )
- {
- cmDtRC_t rc = kOkDtRC;
- int val = cmLexTokenInt(c->p->lexH);
- bool unsignedFl = cmLexTokenIsUnsigned(c->p->lexH);
-
- if( cmDataIsPtr(c->cnp) )
- rc = _cmDpStoreArrayEle(c,&val,sizeof(val),unsignedFl ? kUIntPtrDtId : kIntPtrDtId);
- else
- {
- cmData_t* np = unsignedFl ? cmDataAllocUInt(NULL,val) : cmDataAllocInt(NULL,val);
- rc = _cmDpStoreValue(c,np,"int");
- }
-
- return rc;
- }
-
- cmDtRC_t _cmDataParserString( cmDataParserCtx_t* c )
- {
- // if we are expecting a pair label
- if( cmIsFlag(c->flags,kIdExpFl) )
- return _cmDataParserOpenPair(c);
-
- // otherwise a 'value' must be expected
- if( cmIsNotFlag(c->flags,kValueExpFl) )
- return _cmDpSyntaxErr(c,"Unexpected string.");
-
- cmData_t* np = cmDataConstStrAllocN(NULL,cmLexTokenText(c->p->lexH), cmLexTokenCharCount(c->p->lexH));
-
- return _cmDpStoreValue(c,np,"string");
- }
-
- cmDtRC_t _cmDataParserOpenRecd( cmDataParserCtx_t* c )
- {
- cmDtRC_t rc = kOkDtRC;
-
- // records are values - so we must be expecting a value
- if( cmIsFlag(c->flags,kValueExpFl) == false )
- return _cmDpSyntaxErr(c,"Unexpected '{'.");
-
- // store the current node
- if((rc = _cmDpPushStack(c,c->cnp)) != kOkDtRC )
- return rc;
-
- // alloc a new record and make it the current node
- if( (c->cnp = cmDataRecdAlloc(NULL)) == NULL )
- return _cmDpSyntaxErr(c,"'recd' allocate failed.");
-
- // new records must be followed by an id token.
- c->flags = kIdExpFl;
-
- return rc;
- }
-
- cmDtRC_t _cmDataParserCloseContainer( cmDataParserCtx_t* c, const cmChar_t* typeLabelStr )
- {
- cmDtRC_t rc;
-
- cmData_t* np = c->cnp;
-
- // make the parent node the new current node
- if((rc = _cmDpPopStack(c,&c->cnp)) != kOkDtRC )
- return rc;
-
- return _cmDpStoreValue(c,np,typeLabelStr);
- }
-
- cmDtRC_t _cmDataParserCloseRecd( cmDataParserCtx_t* c )
- {
- assert( c->cnp->tid == kRecordDtId );
-
- return _cmDataParserCloseContainer(c,"record");
- }
-
- cmDtRC_t _cmDataParserOpenList( cmDataParserCtx_t* c )
- {
- cmDtRC_t rc = kOkDtRC;
-
- // lists are values - so we must be expecting a value
- if( cmIsFlag(c->flags,kValueExpFl) == false )
- return _cmDpSyntaxErr(c,"Unexpected '('.");
-
- // store the current node
- if((rc = _cmDpPushStack(c,c->cnp)) != kOkDtRC )
- return rc;
-
- // create a new list
- if( (c->cnp = cmDataListAlloc(NULL)) == NULL )
- return _cmDpSyntaxErr(c,"'list' allocate failed.");
-
- // new lists must be followed by a value
- c->flags = kValueExpFl;
-
- return rc;
- }
-
- cmDtRC_t _cmDataParserCloseList( cmDataParserCtx_t* c )
- {
- assert( c->cnp->tid == kListDtId );
- return _cmDataParserCloseContainer(c,"list");
- }
-
- cmDtRC_t _cmDataParserOpenArray( cmDataParserCtx_t* c )
- {
- cmDtRC_t rc = kOkDtRC;
-
- // arrays are values - so we must be expecting a value
- if( cmIsFlag(c->flags,kValueExpFl) == false )
- return _cmDpSyntaxErr(c,"Unexpected '('.");
-
- // store the current node
- if((rc = _cmDpPushStack(c,c->cnp)) != kOkDtRC )
- return rc;
-
- // create a new array
- if( (c->cnp = cmDataVoidAllocPtr(NULL, NULL, 0 )) == NULL )
- return _cmDpSyntaxErr(c,"'array' allocate failed.");
-
- // new arrays must be followed by a value
- c->flags = kValueExpFl;
-
- return rc;
-
- }
-
- cmDtRC_t _cmDataParserCloseArray( cmDataParserCtx_t* c )
- {
- assert( cmDataIsPtr(c->cnp) );
-
- return _cmDataParserCloseContainer(c,"array");
- }
-
- cmDtRC_t _cmDataParserOnColon( cmDataParserCtx_t* c )
- {
- // colons only follow field identifiers and are always followed by values.
- if( cmIsFlag(c->flags,kColonExpFl) == false )
- return _cmDpSyntaxErr(c,"Unexpected colon.");
-
- c->flags = kValueExpFl;
-
- return kOkDtRC;
- }
-
- cmDtRC_t _cmDataParserOnComma( cmDataParserCtx_t* c )
- {
- // comma's may be found in three places:
- // 1) following field values
- // 2) between list values
- // 3) between array values
- // comma's are always followed by values
- if( cmIsFlag(c->flags,kCommaExpFl) == false )
- return _cmDpSyntaxErr(c, "Unexpected comma.");
-
- c->flags = kValueExpFl;
-
- return kOkDtRC;
- }
-
-
- cmDtRC_t cmDataParserExec( cmDataParserH_t h, const cmChar_t* text, cmData_t** pp )
- {
- cmDtRC_t rc = kOkDtRC;
- cmDataParser_t* p = _cmDataParserHandleToPtr(h);
- unsigned tokenId;
- cmDataParserCtx_t ctx;
- cmData_t* root = cmDataRecdAlloc(NULL);
- ctx.cnp = root;
- ctx.p = p;
- ctx.flags = kIdExpFl;
-
- if( cmLexSetTextBuffer(p->lexH,text,strlen(text)) != kOkLexRC )
- return cmErrMsg(&p->err,kLexFailDtRC,"The data object lexer failed during reset.");
-
- cmStackClear(p->stH,false);
-
- while(rc==kOkDtRC && (tokenId = cmLexGetNextToken(p->lexH)) != kEofLexTId )
- {
- switch(tokenId)
- {
- case kRealLexTId: // real number (contains a decimal point or is in scientific notation)
- rc = _cmDataParserReal(&ctx);
- break;
-
- case kIntLexTId: // decimal integer
- case kHexLexTId: // hexidecimal integer
- rc = _cmDataParserInt(&ctx);
- break;
-
- case kIdentLexTId: // identifiers are treated as strings
- case kQStrLexTId: // quoted string
- rc = _cmDataParserString(&ctx);
- break;
-
- case kLCurlyLexTId: // a new record is starting
- rc = _cmDataParserOpenRecd(&ctx);
- break;
-
- case kRCurlyLexTId: // the current record is finished
- rc = _cmDataParserCloseRecd(&ctx);
- break;
-
- case kLParenLexTId: // a list is starting
- rc = _cmDataParserOpenList(&ctx);
- break;
-
- case kRParenLexTId: // a list is finished
- rc = _cmDataParserCloseList(&ctx);
- break;
-
- case kLBrackLexTId: // an array is starting
- rc = _cmDataParserOpenArray(&ctx);
- break;
-
- case kRBrackLexTId: // an array is ending
- rc = _cmDataParserCloseArray(&ctx);
- break;
-
- case kColonLexTId: // the previous id was a field id
- rc = _cmDataParserOnColon(&ctx);
- break;
-
- case kCommaLexTId: // comma sep. for array or fields
- rc = _cmDataParserOnComma(&ctx);
- break;
-
- case kBlockCmtLexTId: // block comment
- case kLineCmtLexTId: // line comment
- case kErrorLexTId: // the lexer was unable to identify the current token
- case kUnknownLexTId: // the token is of an unknown type (only used when kReturnUnknownLexFl is set)
- case kEofLexTId: // the lexer reached the end of input
- case kSpaceLexTId: // white space
- {
- 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));
- goto errLabel;
- }
- }
- }
-
- errLabel:
-
- if( rc == kOkDtRC )
- *pp = ctx.cnp;
- else
- {
- if( ctx.cnp != root )
- cmDataUnlinkAndFree(ctx.cnp);
-
- cmDataUnlinkAndFree(root);
- }
- return rc;
- }
-
- //============================================================================
- //============================================================================
- //============================================================================
-
- #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)
-
- void _cmDataPrintIndent( cmRpt_t* rpt, unsigned indent )
- {
- unsigned j=0;
- for(; j<indent; ++j)
- cmRptPrintf(rpt," ");
- }
-
- void _cmDataPrint( const cmData_t* p, cmRpt_t* rpt, unsigned indent )
- {
- cmData_t* cp;
-
- //_cmDataPrintIndent(rpt,indent);
-
- switch(p->tid)
- {
- case kNullDtId: cmRptPrintf(rpt,"<null>"); break;
- case kUCharDtId: cmRptPrintf(rpt,"%c ",cmDataUChar(p)); break;
- case kCharDtId: cmRptPrintf(rpt,"%c ",cmDataChar(p)); break;
- case kUShortDtId: cmRptPrintf(rpt,"%i ",cmDataUShort(p)); break;
- case kShortDtId: cmRptPrintf(rpt,"%i ",cmDataShort(p)); break;
- case kUIntDtId: cmRptPrintf(rpt,"%i ",cmDataUInt(p)); break;
- case kIntDtId: cmRptPrintf(rpt,"%i ",cmDataInt(p)); break;
- case kULongDtId: cmRptPrintf(rpt,"%i ",cmDataULong(p)); break;
- case kLongDtId: cmRptPrintf(rpt,"%i ",cmDataLong(p)); break;
- case kFloatDtId: cmRptPrintf(rpt,"%f ",cmDataFloat(p)); break;
- case kDoubleDtId: cmRptPrintf(rpt,"%f ",cmDataDouble(p)); break;
-
- case kStrDtId: cmRptPrintf(rpt,"%s ",cmDataStr(p)); break;
- case kConstStrDtId: cmRptPrintf(rpt,"%s ",cmDataConstStr(p)); break;
-
- case kUCharPtrDtId: parr(rpt,"%c ",cmDataUCharPtr(p), p->cnt); break;
- case kCharPtrDtId: parr(rpt,"%c ",cmDataCharPtr(p), p->cnt); break;
- case kUShortPtrDtId: parr(rpt,"%i ",cmDataUShortPtr(p),p->cnt); break;
- case kShortPtrDtId: parr(rpt,"%i ",cmDataShortPtr(p), p->cnt); break;
- case kUIntPtrDtId: parr(rpt,"%i ",cmDataUIntPtr(p), p->cnt); break;
- case kIntPtrDtId: parr(rpt,"%i ",cmDataIntPtr(p), p->cnt); break;
- case kULongPtrDtId: parr(rpt,"%i ",cmDataULongPtr(p), p->cnt); break;
- case kLongPtrDtId: parr(rpt,"%i ",cmDataLongPtr(p), p->cnt); break;
- case kFloatPtrDtId: parr(rpt,"%f ",cmDataFloatPtr(p), p->cnt); break;
- case kDoublePtrDtId: parr(rpt,"%f ",cmDataDoublePtr(p),p->cnt); break;
-
- case kVoidPtrDtId: cmRptPrintf(rpt,"<void:%i>",p->cnt); break;
-
- case kPairDtId:
- _cmDataPrint(p->u.child,rpt,indent);
- cmRptPrintf(rpt," : ");
- _cmDataPrint(p->u.child->sibling,rpt,indent);
- cmRptPrintf(rpt,"\n");
- break;
-
- case kListDtId:
- cmRptPrintf(rpt,"(\n");
- indent += 2;
- cp = p->u.child;
- for(; cp!=NULL; cp=cp->sibling)
- {
- _cmDataPrintIndent(rpt,indent);
- _cmDataPrint(cp,rpt,indent);
- cmRptPrintf(rpt,"\n");
- }
- indent -= 2;
- _cmDataPrintIndent(rpt,indent);
- cmRptPrintf(rpt,")\n");
- break;
-
- case kRecordDtId:
- cmRptPrintf(rpt,"{\n");
- indent += 2;
- cp = p->u.child;
- for(; cp!=NULL; cp=cp->sibling)
- {
- _cmDataPrintIndent(rpt,indent);
- _cmDataPrint(cp,rpt, indent);
- }
- indent -= 2;
- _cmDataPrintIndent(rpt,indent);
- cmRptPrintf(rpt,"}\n");
- break;
-
- default:
- break;
- }
- }
-
- void cmDataPrint( const cmData_t* p, cmRpt_t* rpt )
- { _cmDataPrint(p,rpt,0); }
-
-
- cmDtRC_t cmDataParserTest( cmCtx_t* ctx )
- {
- cmDtRC_t rc = kOkDtRC;
- cmDataParserH_t h = cmDataParserNullHandle;
- cmErr_t err;
- cmData_t* dp = NULL;
-
- const cmChar_t text[] =
- {
- //0 1 2 3
- //0123456789012345678901234567890123
- "f0:1.23 f1:\"hey\" f2:( a b c ) f3:[ 0f 1f 2f ]"
- //"f0:1.23 f1:\"hey\""
- };
-
- cmErrSetup(&err,&ctx->rpt,"Data Parser Tester");
-
- if((rc = cmDataParserCreate(ctx, &h )) != kOkDtRC )
- {
- rc = cmErrMsg(&err,rc,"Data parser create failed.");
- goto errLabel;
- }
-
- if( cmDataParserExec(h,text,&dp) != kOkDtRC )
- rc = cmErrMsg(&err,rc,"Data parser exec failed.");
- else
- if( dp != NULL )
- cmDataPrint(dp,&ctx->rpt);
-
-
- errLabel:
- if( cmDataParserDestroy( &h ) != kOkDtRC )
- {
- rc = cmErrMsg(&err,rc,"Data parser destroy failed.");
- goto errLabel;
- }
-
- cmDataFree(dp);
-
- return rc;
- }
-
-
- void cmDataTest( cmCtx_t* ctx )
- {
- float farr[] = { 1.23, 45.6, 7.89 };
-
- cmDataParserTest(ctx);
- return;
-
- cmData_t* d0 = cmDataRecdAllocLabelA(NULL,
- "name",kConstStrDtId,"This is a string.",
- "id", kUIntDtId, 21,
- "real",kFloatDtId, 1.23,
- "arr", kFloatPtrDtId, farr, 3,
- NULL);
-
- cmDataPrint(d0,&ctx->rpt);
- cmDataFree(d0);
-
- cmData_t* d1 = cmDataListAllocA(NULL,
- kUIntDtId, 53,
- kStrDtId, "Blah blah",
- kFloatPtrDtId, farr, 3,
- kInvalidDtId );
-
-
- cmDataPrint(d1,&ctx->rpt);
- cmDataFree(d1);
-
-
-
- cmRptPrintf(&ctx->rpt,"Done!.\n");
- }
-
- #endif
|