diff --git a/cmData.c b/cmData.c index d965ab9..b1580f8 100644 --- a/cmData.c +++ b/cmData.c @@ -154,26 +154,13 @@ void _cmDataFree( cmData_t* p ) 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) +// Dynamically allocate a new data object. +cmData_t* _cmDataNew(cmData_t* parent, cmDataContainerId_t cid, cmDataTypeId_t tid) { cmData_t* d = cmMemAllocZ(cmData_t,1); - d->tid = kNullDtId; // objects without data are of type 'null'. - d->cid = kScalarDtId; + d->tid = tid; // objects without data are of type 'null'. + d->cid = cid; d->flags = kFreeObjDtFl; d->parent = parent; d->cnt = 0; @@ -181,8 +168,7 @@ cmDtRC_t _cmDataNew(cmData_t* parent, cmData_t** ref) if( parent != NULL ) cmDataAppendChild(parent,d); - *ref = d; - return kOkDtRC; + return d; } @@ -213,14 +199,13 @@ bool cmDataIsStruct( const cmData_t* 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; + if( ref != NULL ) + *ref = NULL; // create a scalar null object - if((rc = _cmDataNew(parent,&d)) != kOkDtRC ) - return rc; + cmData_t* d = _cmDataNew(parent,kScalarDtId,kNullDtId); if( tid!=kStrDtId && tid!=kBlobDtId ) { @@ -241,13 +226,14 @@ cmDtRC_t cmDataNewScalar( cmData_t* parent, cmDataTypeId_t tid, unsigned flags, // set the const flags for the new object d->flags = cmSetFlag(d->flags, flags & (kConstValueDtFl | kConstObjDtFl)); - *ref = d; + if( ref != NULL ) + *ref = d; return rc; } cmDtRC_t cmDataNewNull( cmData_t* parent, unsigned flags, cmData_t** ref ) -{ return _cmDataNew(parent, ref); } +{ *ref = _cmDataNew(parent, kScalarDtId, kNullDtId); return kOkDtRC; } 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 ) @@ -807,13 +793,12 @@ cmDtRC_t cmDataGetDouble( const cmData_t* p, double* vp ) 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; + if( ref != NULL ) + *ref = NULL; // create a new 'null' object - if((rc = _cmDataNew(parent, &d)) != kOkDtRC ) - return rc; + cmData_t* d = _cmDataNew(parent, kScalarDtId, kNullDtId ); // assign the value if((rc = cmDataSetArrayValue(d,tid,vp,eleCnt,flags)) != kOkDtRC ) @@ -822,7 +807,8 @@ cmDtRC_t cmDataNewArray( cmData_t* parent, cmDataTypeId_t tid, void* vp, unsigne // set the flags for the new object d->flags = cmSetFlag(d->flags, flags & (kConstValueDtFl | kConstObjDtFl | kNoCopyDtFl)); - *ref = d; + if( ref != NULL ) + *ref = d; return rc; @@ -1072,6 +1058,7 @@ void cmDataUnlinkAndFree( cmData_t* p ) cmDtRC_t _cmDataDupl( const cmData_t* d, cmData_t* parent, cmData_t** ref ) { + cmDtRC_t rc = kOkDtRC; cmData_t* rp = NULL; *ref = NULL; @@ -1093,11 +1080,17 @@ cmDtRC_t _cmDataDupl( const cmData_t* d, cmData_t* parent, cmData_t** ref ) 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)); + rp = _cmDataNew(parent,d->cid,d->tid); + const cmData_t* cp = d->u.child; + for(; cp!=NULL; cp=cp->sibling) + { + cmData_t* ncp = NULL; + // duplicate the child (ncp) and append it to the parent (rp) + if((rc = _cmDataDupl(cp,rp,&ncp)) == kOkDtRC ) + cmDataAppendChild(rp,ncp); + } } + break; default: @@ -1109,61 +1102,10 @@ cmDtRC_t _cmDataDupl( const cmData_t* d, cmData_t* parent, cmData_t** ref ) *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); } +cmRC_t cmDataDupl( const cmData_t* p, cmData_t** ref ) +{ return _cmDataDupl(p,NULL,ref); } cmData_t* cmDataReplace( cmData_t* dst, cmData_t* src ) { @@ -1203,6 +1145,7 @@ cmData_t* cmDataReplace( cmData_t* dst, cmData_t* src ) } pp = cp; } + return src; } @@ -1312,1381 +1255,11 @@ cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* 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; isibling) - { - - 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 ); + assert( p->cid == kPairDtId && p->tid==kStructDtId ); bool fl = p->u.child == NULL || p->u.child->sibling == NULL || p->u.child->sibling->sibling!=NULL; return !fl; @@ -2711,7 +1284,7 @@ const cmChar_t* cmDataPairKeyLabel( cmData_t* p ) { assert( _cmDataPairIsValid(p) ); const cmChar_t* label = NULL; - cmDataGetConstStr(p->u.child,&label); + cmDataConstStr(p->u.child,&label); return label; } @@ -2748,7 +1321,7 @@ cmData_t* cmDataPairSetKeyId( cmData_t* p, unsigned id ) cmData_t* cmDataPairSetKeyLabel( cmData_t* p, const cmChar_t* label ) { assert( _cmDataPairIsValid(p) ); - cmDataSetConstStrAlloc(p->u.child,label); + cmDataSetConstStr(p->u.child,kNoFlagsDtFl,label); return p; } @@ -2756,7 +1329,8 @@ cmData_t* cmDataPairSetKeyLabel( cmData_t* p, const cmChar_t* label ) cmData_t* cmDataMakePair( cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t* value ) { _cmDataFree(p); - p->tid = kPairDtId; + p->tid = kStructDtId; + p->cid = kPairDtId; p->parent = parent; p->flags = 0; p->u.child = NULL; @@ -2768,9 +1342,14 @@ cmData_t* cmDataMakePair( cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t // 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); + cmData_t* p = _cmDataNew(parent,kPairDtId,kStructDtId); + cmData_t* kp = NULL; + cmData_t* vp = NULL; + + // BUG BUG BUG - must check return value of cmDataDupl() + cmDataDupl(key,&kp); + cmDataDupl(value,&vp); + cmDataPrependChild(p,vp); cmDataPrependChild(p,kp); return p; @@ -2778,24 +1357,27 @@ cmData_t* cmDataAllocPair( cmData_t* parent, const cmData_t* key, const cmData_ cmData_t* cmDataAllocPairId(cmData_t* parent, unsigned keyId, cmData_t* value ) { - cmData_t* p = _cmDataAllocNode(parent,kPairDtId); - cmDataAllocUInt(p,keyId); + cmData_t* p = _cmDataNew(parent,kPairDtId,kStructDtId); + cmDataNewUInt(p,kNoFlagsDtFl,keyId,NULL); 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); + cmData_t* p = _cmDataNew(parent,kPairDtId,kStructDtId); + + // BUG BUG BUG - should check return value + cmDataNewConstStr(p,kNoFlagsDtFl,label,NULL); 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); + cmData_t* p = _cmDataNew(parent,kPairDtId,kStructDtId); + // BUG BUG BUG - should check return value + cmDataNewConstStrN(p,kNoFlagsDtFl,label,charCnt,NULL); cmDataAppendChild(p,value); return p; } @@ -2820,117 +1402,72 @@ cmData_t* cmDataListMake( cmData_t* parent, cmData_t* p ) } cmData_t* cmDataListAlloc( cmData_t* parent) -{ return _cmDataAllocNode(parent,kListDtId); } +{ return _cmDataNew(parent,kListDtId,kStructDtId); } 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); + cmDtRC_t rc = kOkDtRC; + cmData_t* vp = NULL; + cmDataContainerId_t cid = va_arg(vl,unsigned); + cmDataTypeId_t tid = va_arg(vl,unsigned); - switch(tid) + switch(cid) { - 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: + case kInvalidCntDtId: rc = kEolDtRC; break; + + case kScalarDtId: + switch(tid) { - unsigned char* p = va_arg(vl,unsigned char*); - vp = cmDataUCharAllocPtr(parent, p, va_arg(vl,unsigned)); + case kNullDtId: rc = cmDataNewNull( parent,kNoFlagsDtFl,&vp); break; + case kUCharDtId: rc = cmDataNewUChar( parent,kNoFlagsDtFl,va_arg(vl,int),&vp); break; + case kCharDtId: rc = cmDataNewChar( parent,kNoFlagsDtFl,va_arg(vl,int),&vp); break; + case kUShortDtId: rc = cmDataNewUShort( parent,kNoFlagsDtFl,va_arg(vl,int),&vp); break; + case kShortDtId: rc = cmDataNewShort( parent,kNoFlagsDtFl,va_arg(vl,int),&vp); break; + case kUIntDtId: rc = cmDataNewUInt( parent,kNoFlagsDtFl,va_arg(vl,unsigned int),&vp); break; + case kIntDtId: rc = cmDataNewInt( parent,kNoFlagsDtFl,va_arg(vl,int),&vp); break; + case kULongDtId: rc = cmDataNewULong( parent,kNoFlagsDtFl,va_arg(vl,unsigned long),&vp); break; + case kLongDtId: rc = cmDataNewLong( parent,kNoFlagsDtFl,va_arg(vl,long),&vp); break; + case kFloatDtId: rc = cmDataNewFloat( parent,kNoFlagsDtFl,va_arg(vl,double),&vp); break; + case kDoubleDtId: rc = cmDataNewDouble( parent,kNoFlagsDtFl,va_arg(vl,double),&vp); break; + case kStrDtId: rc = cmDataNewStr( parent,kNoFlagsDtFl,va_arg(vl,cmChar_t*),&vp); break; + default: + // BUG BUG BUG - signal an error here + assert(0); + break; } break; - case kCharPtrDtId: + case kArrayDtId: + switch(tid) { - 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)); + case kUCharDtId: rc = cmDataNewUCharArray( parent,va_arg(vl,unsigned char*), va_arg(vl,unsigned),kNoFlagsDtFl,&vp); break; + case kCharDtId: rc = cmDataNewCharArray( parent,va_arg(vl,char*), va_arg(vl,unsigned),kNoFlagsDtFl,&vp); break; + case kUShortDtId: rc = cmDataNewUShortArray( parent,va_arg(vl,unsigned short*),va_arg(vl,unsigned),kNoFlagsDtFl,&vp); break; + case kShortDtId: rc = cmDataNewShortArray( parent,va_arg(vl,short*), va_arg(vl,unsigned),kNoFlagsDtFl,&vp); break; + case kUIntDtId: rc = cmDataNewUIntArray( parent,va_arg(vl,unsigned int*), va_arg(vl,unsigned),kNoFlagsDtFl,&vp); break; + case kIntDtId: rc = cmDataNewIntArray( parent,va_arg(vl,int*), va_arg(vl,unsigned),kNoFlagsDtFl,&vp); break; + case kULongDtId: rc = cmDataNewULongArray( parent,va_arg(vl,unsigned long*), va_arg(vl,unsigned),kNoFlagsDtFl,&vp); break; + case kLongDtId: rc = cmDataNewLongArray( parent,va_arg(vl,long*), va_arg(vl,unsigned),kNoFlagsDtFl,&vp); break; + case kFloatDtId: rc = cmDataNewFloatArray( parent,va_arg(vl,float*), va_arg(vl,unsigned),kNoFlagsDtFl,&vp); break; + case kDoubleDtId: rc = cmDataNewDoubleArray( parent,va_arg(vl,double*), va_arg(vl,unsigned),kNoFlagsDtFl,&vp); break; + case kStrDtId: rc = cmDataNewStrArray( parent,va_arg(vl,cmChar_t**), va_arg(vl,unsigned),kNoFlagsDtFl,&vp); break; + default: + // BUG BUG BUG - signal an error here + + assert(0); + break; } break; case kListDtId: case kPairDtId: case kRecordDtId: - vp = _cmDataAllocNode(parent,tid); + vp = _cmDataNew(parent,cid,kStructDtId); break; default: - _cmDataSetError(kVarArgErrDtRC); + // BUG BUG BUG - signal an error here + assert(0); break; } @@ -2939,49 +1476,62 @@ cmDtRC_t _cmDataParseArgV( cmData_t* parent, va_list vl, cmData_t** vpp ) return rc; } -cmData_t* _cmDataListParseV(cmData_t* parent, va_list vl ) +cmDtRC_t _cmDataListParseV(cmData_t* parent, va_list vl ) { - cmData_t* p = NULL; + cmDtRC_t rc = kOkDtRC; bool contFl = true; while( contFl ) { cmData_t* vp; - cmDtRC_t rc = _cmDataParseArgV(parent, vl, &vp); + + rc = _cmDataParseArgV(parent, vl, &vp); if(rc != kOkDtRC || cmDataAppendChild(parent,vp)==NULL ) contFl = false; } - return p; + + return rc; } -cmData_t* cmDataListAllocV(cmData_t* parent, va_list vl ) +cmRC_t cmDataListAllocV(cmData_t* parent, cmData_t** ref, va_list vl ) { cmData_t* p = cmDataListAlloc(parent); - _cmDataListParseV(p, vl ); - return p; + + cmRC_t rc; + + if((rc = _cmDataListParseV(p, vl )) != kOkDtRC ) + { + cmDataUnlinkAndFree(p); + return rc; + } + + if( ref != NULL ) + *ref = p; + + return rc; } -cmData_t* cmDataListAllocA(cmData_t* parent, ... ) +cmRC_t cmDataListAllocA(cmData_t* parent, cmData_t** ref, ... ) { va_list vl; - va_start(vl,parent); - cmData_t* p = cmDataListAllocV(parent,vl); + va_start(vl,ref); + cmRC_t rc = cmDataListAllocV(parent,ref,vl); va_end(vl); - return p; + return rc; } cmData_t* cmDataListAppendEle( cmData_t* p, cmData_t* ele ) { - assert(p->tid == kListDtId); + assert(p->cid == kListDtId && p->tid==kStructDtId); return cmDataAppendChild(p,ele); } cmData_t* cmDataListAppendEleN(cmData_t* p, cmData_t* ele[], unsigned n ) { - assert(p->tid == kListDtId); + assert(p->cid == kListDtId && p->tid==kStructDtId); cmData_t* rp = NULL; unsigned i; @@ -2996,8 +1546,9 @@ cmData_t* cmDataListAppendEleN(cmData_t* p, cmData_t* ele[], unsigned n ) cmDtRC_t cmDataListAppendV( cmData_t* p, va_list vl ) { - if( _cmDataListParseV(p, vl ) == NULL ) - return _cmDataErrNo; + cmDtRC_t rc; + if((rc = _cmDataListParseV(p, vl )) != kOkDtRC ) + return rc; return kOkDtRC; } @@ -3026,42 +1577,42 @@ cmData_t* cmDataListInsertEleN(cmData_t* p, unsigned index, cmData_t* ele[], uns //---------------------------------------------------------------------------- unsigned cmDataRecdCount( const cmData_t* p ) { - assert( p->tid == kRecordDtId ); + assert( p->cid == kRecordDtId && p->tid==kStructDtId ); return cmDataChildCount(p); } cmData_t* cmDataRecdEle( cmData_t* p, unsigned index ) { - assert( p->tid == kRecordDtId ); + assert( p->cid == kRecordDtId && p->tid==kStructDtId ); cmData_t* cp = cmDataChild(p,index); - assert( p->tid == kPairDtId ); + assert( p->cid == kPairDtId ); return cp; } cmData_t* cmDataRecdValueFromIndex( cmData_t* p, unsigned index ) { - assert( p->tid == kRecordDtId ); + assert( p->cid == kRecordDtId && p->tid==kStructDtId ); cmData_t* cp = cmDataChild(p,index); - assert( p->tid == kPairDtId ); + assert( p->cid == kPairDtId && p->tid==kStructDtId ); return cmDataPairValue(cp); } cmData_t* cmDataRecdValueFromId( cmData_t* p, unsigned id ) { - assert( p->tid == kRecordDtId ); + assert( p->cid == kRecordDtId || p->tid==kStructDtId ); cmData_t* cp = p->u.child; for(; cp!=NULL; cp=cp->sibling) if( cmDataPairKeyId(cp) == id ) break; - assert( cp!=NULL && cp->tid==kPairDtId ); + assert( cp!=NULL && cp->cid==kPairDtId && cp->tid==kStructDtId); return cmDataPairValue(cp); } cmData_t* cmDataRecdValueFromLabel( cmData_t* p, const cmChar_t* label ) { - assert( p->tid == kRecordDtId ); + assert( p->cid == kRecordDtId && p->tid==kStructDtId); cmData_t* cp = p->u.child; for(; cp!=NULL; cp=cp->sibling) { @@ -3070,16 +1621,16 @@ cmData_t* cmDataRecdValueFromLabel( cmData_t* p, const cmChar_t* label if( lp!=NULL && strcmp(lp,label)==0 ) break; } - assert( cp!=NULL && cp->tid==kPairDtId ); + assert( cp!=NULL && cp->cid==kPairDtId && cp->tid==kStructDtId); return cmDataPairValue(cp); } cmData_t* cmDataRecdKey( cmData_t* p, unsigned index ) { - assert( p->tid == kRecordDtId ); + assert( p->cid == kRecordDtId && p->tid==kStructDtId ); cmData_t* cp = cmDataChild(p,index); - assert( p->tid == kPairDtId ); + assert( cp->cid == kPairDtId && cp->tid==kStructDtId); return cmDataPairKey(cp); } @@ -3095,7 +1646,8 @@ const cmChar_t* cmDataRecdKeyLabel( cmData_t* p, unsigned index ) { cmData_t* kp = cmDataRecdKey(p,index); const cmChar_t* label = NULL; - cmDataGetConstStr(kp,&label); + // BUG BUG BUG - test return value + cmDataConstStr(kp,&label); return label; } @@ -3110,11 +1662,11 @@ cmData_t* cmDataRecdMake( cmData_t* parent, cmData_t* p ) } cmData_t* cmDataRecdAlloc(cmData_t* parent) -{ return _cmDataAllocNode(parent,kRecordDtId); } +{ return _cmDataNew(parent,kRecordDtId,kStructDtId); } cmData_t* cmDataRecdAppendPair( cmData_t* p, cmData_t* pair ) { - assert( p!=NULL && p->tid==kRecordDtId); + assert( p!=NULL && p->cid==kRecordDtId && p->tid==kStructDtId); cmDataAppendChild(p,pair); return p; } @@ -3122,7 +1674,7 @@ cmData_t* cmDataRecdAppendPair( cmData_t* p, cmData_t* pair ) cmDtRC_t _cmDataRecdParseInputV(cmData_t* parent, unsigned idFl, va_list vl ) { - assert( parent != NULL && parent->tid == kRecordDtId ); + assert( parent != NULL && parent->cid == kRecordDtId && parent->tid == kStructDtId ); bool contFl = true; cmDtRC_t rc = kOkDtRC; @@ -3140,7 +1692,7 @@ cmDtRC_t _cmDataRecdParseInputV(cmData_t* parent, unsigned idFl, va_list vl ) label = va_arg(vl,const char*); // text field label identifier // validate the field identifier - if( (idFl && id==kInvalidDtId) || (!idFl && label==NULL) ) + if( (idFl && id==cmInvalidId) || (!idFl && label==NULL) ) break; // parse the field data @@ -3209,8 +1761,8 @@ cmDtRC_t _cmDataRecdParseV(cmData_t* p, bool idFl, cmErr_t* err, unsigned errRC, while( contFl ) { - unsigned id; - const char* label; + unsigned id = cmInvalidId; + const char* label = NULL; // parse the field idenfier if( idFl ) @@ -3219,14 +1771,15 @@ cmDtRC_t _cmDataRecdParseV(cmData_t* p, bool idFl, cmErr_t* err, unsigned errRC, label = va_arg(vl,const char*); // text field label identifier // validate the field identifier - if( (idFl && id==kInvalidDtId) || (!idFl && label==NULL) ) + if( (idFl && id==cmInvalidId) || (!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; + cmDataContainerId_t cid = va_arg(vl,unsigned); + cmDataTypeId_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); @@ -4297,4 +2850,3 @@ void cmDataTest( cmCtx_t* ctx ) cmRptPrintf(&ctx->rpt,"Done!.\n"); } -#endif diff --git a/cmData.h b/cmData.h index 86db015..e246944 100644 --- a/cmData.h +++ b/cmData.h @@ -75,7 +75,8 @@ extern "C" { kFloatDtId, // 10 kDoubleDtId, // 11 kStrDtId, // 12 zero terminated string - kBlobDtId // 13 application defined raw memory object + kBlobDtId, // 13 application defined raw memory object + kStructDtId // 14 node is a pair,list, or recd } cmDataTypeId_t; @@ -425,341 +426,6 @@ extern "C" { cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p ); - -//////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////// -//////////////////////////////////////////////////////////////////////////////////////////////// - -#ifdef NOT_DEF - typedef enum - { - kInvalidDtId, - - kMinValDtId, - - kNullDtId = kMinValDtId, - kUCharDtId, - kCharDtId, - kUShortDtId, - kShortDtId, - kUIntDtId, - kIntDtId, - kULongDtId, - kLongDtId, - kFloatDtId, - kDoubleDtId, - - kStrDtId, - kConstStrDtId, - kMaxValDtId = kConstStrDtId, - - kMinPtrDtId, - kUCharPtrDtId = kMinPtrDtId, // cnt=array element count - kCharPtrDtId, - kUShortPtrDtId, - kShortPtrDtId, - kUIntPtrDtId, - kIntPtrDtId, - kULongPtrDtId, - kLongPtrDtId, - kFloatPtrDtId, - kDoublePtrDtId, - kVoidPtrDtId, - kMaxPtrDtId = kVoidPtrDtId, - - kMinStructDtId, - kListDtId = kMinStructDtId, // children nodes are array elements, cnt=child count - kPairDtId, // key/value pairs, cnt=2, first child is key, second is value - kRecordDtId, // children nodes are pairs, cnt=pair count - kMaxStructDtId, - - kOptArgDtFl = 0x80000000 - } cmDataFmtId_t; - - enum - { - kDynObjDtFl = 0x01, // object was dynamically allocated - kDynPtrDtFl = 0x02 // ptr array was dynamically allocated - }; - - typedef struct cmData_str - { - cmDataFmtId_t tid; // data format id - unsigned flags; // - struct cmData_str* parent; // this childs parent - struct cmData_str* sibling; // this childs left sibling - unsigned cnt; // array ele count - - union - { - char c; - unsigned char uc; - short s; - unsigned short us; - int i; - unsigned int ui; - long l; - unsigned long ul; - float f; - double d; - - cmChar_t* z; - const cmChar_t* cz; - - void* vp; - - char* cp; - unsigned char* ucp; - short* sp; - unsigned short* usp; - int* ip; - unsigned int* uip; - long* lp; - unsigned long* ulp; - float* fp; - double* dp; - - - struct cmData_str* child; // first child (array,record,pair) - } u; - - } cmData_t; - - typedef unsigned cmDtRC_t; - - extern cmData_t cmDataNull; - - bool cmDataIsValue( const cmData_t* p ); - bool cmDataIsPtr( const cmData_t* p ); - bool cmDataIsStruct( const cmData_t* p ); // is a pair,list or record - - - bool canConvertType( cmDataFmtId_t srcId, cmDataFmtId_t dstId ); - bool willTruncate( cmDataFmtId_t srcId, cmDataFmtId_t dstId ); - bool canConvertObj( const cmData_t* srcObj, cmData_t* dstObj ); - bool willTruncateObj(const cmData_t* srcObj, cmData_t* dstObj ); - - - - // Get the value of an object without conversion. - // The data type id must match the return type or the - // conversion must be an automatic C conversion. - char cmDataChar( const cmData_t* p ); - unsigned char cmDataUChar( const cmData_t* p ); - short cmDataShort( const cmData_t* p ); - unsigned short cmDataUShort( const cmData_t* p ); - int cmDataInt( const cmData_t* p ); - unsigned int cmDataUInt( const cmData_t* p ); - long cmDataLong( const cmData_t* p ); - unsigned long cmDataULong( const cmData_t* p ); - float cmDataFloat( const cmData_t* p ); - double cmDataDouble( const cmData_t* p ); - cmChar_t* cmDataStr( const cmData_t* p ); - const cmChar_t* cmDataConstStr( const cmData_t* p ); - void* cmDataVoidPtr( const cmData_t* p ); - char* cmDataCharPtr( const cmData_t* p ); - unsigned char* cmDataUCharPtr( const cmData_t* p ); - short* cmDataShortPtr( const cmData_t* p ); - unsigned short* cmDataUShortPtr( const cmData_t* p ); - int* cmDataIntPtr( const cmData_t* p ); - unsigned int* cmDataUIntPtr( const cmData_t* p ); - long* cmDataLongPtr( const cmData_t* p ); - unsigned long* cmDataULongPtr( const cmData_t* p ); - float* cmDataFloatPtr( const cmData_t* p ); - double* cmDataDoublePtr( const cmData_t* p ); - - - // Get the value of an object with conversion. - cmDtRC_t cmDataGetChar( const cmData_t* p, char* v ); - cmDtRC_t cmDataGetUChar( const cmData_t* p, unsigned char* v ); - cmDtRC_t cmDataGetShort( const cmData_t* p, short* v ); - cmDtRC_t cmDataGetUShort( const cmData_t* p, unsigned short* v ); - cmDtRC_t cmDataGetInt( const cmData_t* p, int* v ); - cmDtRC_t cmDataGetUInt( const cmData_t* p, unsigned int* v ); - cmDtRC_t cmDataGetLong( const cmData_t* p, long* v ); - cmDtRC_t cmDataGetULong( const cmData_t* p, unsigned long* v ); - cmDtRC_t cmDataGetFloat( const cmData_t* p, float* v ); - cmDtRC_t cmDataGetDouble( const cmData_t* p, double* v ); - - // Returns the pointer - does not copy the data. - cmDtRC_t cmDataGetStr( const cmData_t* p, char** v ); - cmDtRC_t cmDataGetConstStr( const cmData_t* p, const char** v ); - cmDtRC_t cmDataGetVoidPtr( const cmData_t* p, void** v ); - cmDtRC_t cmDataGetCharPtr( const cmData_t* p, char** v ); - cmDtRC_t cmDataGetUCharPtr( const cmData_t* p, unsigned char** v ); - cmDtRC_t cmDataGetShortPtr( const cmData_t* p, short** v ); - cmDtRC_t cmDataGetUShortPtr( const cmData_t* p, unsigned short** v ); - cmDtRC_t cmDataGetIntPtr( const cmData_t* p, int** v ); - cmDtRC_t cmDataGetUIntPtr( const cmData_t* p, unsigned int** v ); - cmDtRC_t cmDataGetLongPtr( const cmData_t* p, long** v ); - cmDtRC_t cmDataGetULongPtr( const cmData_t* p, unsigned long** v ); - cmDtRC_t cmDataGetFloatPtr( const cmData_t* p, float** v ); - cmDtRC_t cmDataGetDoublePtr( const cmData_t* p, double** v ); - - - // Set the value and type of an existing scalar object. - // These functions begin by releasing any resources held by *p - // prior to resetting the type and value of the object. - cmData_t* cmDataSetNull( cmData_t* p ); - cmData_t* cmDataSetChar( cmData_t* p, char v ); - cmData_t* cmDataSetUChar( cmData_t* p, unsigned char v ); - cmData_t* cmDataSetShort( cmData_t* p, short v ); - cmData_t* cmDataSetUShort( cmData_t* p, unsigned short v ); - cmData_t* cmDataSetInt( cmData_t* p, int v ); - cmData_t* cmDataSetUInt( cmData_t* p, unsigned int v ); - cmData_t* cmDataSetLong( cmData_t* p, long v ); - cmData_t* cmDataSetULong( cmData_t* p, unsigned long v ); - cmData_t* cmDataSetFloat( cmData_t* p, float v ); - cmData_t* cmDataSetDouble( cmData_t* p, double v ); - cmData_t* cmDataSetStr( cmData_t* p, cmChar_t* s ); - cmData_t* cmDataSetConstStr( cmData_t* p, const cmChar_t* s ); - - // Set the type and value of an existing data object to an external array. - // These functions begin by releasing any resources help by *p. - // The array pointed to by 'vp' is not copied or duplicated. - // 'vp' is simply assigned as the data space for the object and therefore must remain - // valid for the life of the object. - cmData_t* cmDataSetVoidPtr( cmData_t* p, void* vp, unsigned cnt ); - cmData_t* cmDataSetCharPtr( cmData_t* p, char* vp, unsigned cnt ); - cmData_t* cmDataSetUCharPtr( cmData_t* p, unsigned char* vp, unsigned cnt ); - cmData_t* cmDataSetShortPtr( cmData_t* p, short* vp, unsigned cnt ); - cmData_t* cmDataSetUShortPtr( cmData_t* p, unsigned short* vp, unsigned cnt ); - cmData_t* cmDataSetIntPtr( cmData_t* p, int* vp, unsigned cnt ); - cmData_t* cmDataSetUIntPtr( cmData_t* p, unsigned int* vp, unsigned cnt ); - cmData_t* cmDataSetLongPtr( cmData_t* p, long* vp, unsigned cnt ); - cmData_t* cmDataSetULongPtr( cmData_t* p, unsigned long* vp, unsigned cnt ); - cmData_t* cmDataSetFloatPtr( cmData_t* p, float* vp, unsigned cnt ); - cmData_t* cmDataSetDoublePtr( cmData_t* p, double* vp, unsigned cnt ); - - // Set the value of an existing array based data object. - // These functions begin by releasing any resources help by *p - // and then dynamically allocate the internal array and copy - // the array data into it. - cmData_t* cmDataSetStrAllocN( cmData_t* p, const cmChar_t* s, unsigned charCnt ); - cmData_t* cmDataSetStrAlloc( cmData_t* p, const cmChar_t* s ); - cmData_t* cmDataSetConstStrAllocN( cmData_t* p, const cmChar_t* s, unsigned charCnt ); - cmData_t* cmDataSetConstStrAlloc( cmData_t* p, const cmChar_t* s ); - cmData_t* cmDataSetVoidAllocPtr( cmData_t* p, const void* vp, unsigned cnt ); - cmData_t* cmDataSetCharAllocPtr( cmData_t* p, const char* vp, unsigned cnt ); - cmData_t* cmDataSetUCharAllocPtr( cmData_t* p, const unsigned char* vp, unsigned cnt ); - cmData_t* cmDataSetShortAllocPtr( cmData_t* p, const short* vp, unsigned cnt ); - cmData_t* cmDataSetUShortAllocPtr( cmData_t* p, const unsigned short* vp, unsigned cnt ); - cmData_t* cmDataSetIntAllocPtr( cmData_t* p, const int* vp, unsigned cnt ); - cmData_t* cmDataSetUIntAllocPtr( cmData_t* p, const unsigned int* vp, unsigned cnt ); - cmData_t* cmDataSetLongAllocPtr( cmData_t* p, const long* vp, unsigned cnt ); - cmData_t* cmDataSetULongAllocPtr( cmData_t* p, const unsigned long* vp, unsigned cnt ); - cmData_t* cmDataSetFloatAllocPtr( cmData_t* p, const float* vp, unsigned cnt ); - cmData_t* cmDataSetDoubleAllocPtr( cmData_t* p, const double* vp, unsigned cnt ); - - - // Dynamically allocate a data object and set it's value. - cmData_t* cmDataAllocNull( cmData_t* parent ); - cmData_t* cmDataAllocChar( cmData_t* parent, char v ); - cmData_t* cmDataAllocUChar( cmData_t* parent, unsigned char v ); - cmData_t* cmDataAllocShort( cmData_t* parent, short v ); - cmData_t* cmDataAllocUShort( cmData_t* parent, unsigned short v ); - cmData_t* cmDataAllocInt( cmData_t* parent, int v ); - cmData_t* cmDataAllocUInt( cmData_t* parent, unsigned int v ); - cmData_t* cmDataAllocLong( cmData_t* parent, long v ); - cmData_t* cmDataAllocULong( cmData_t* parent, unsigned long v ); - cmData_t* cmDataAllocFloat( cmData_t* parent, float v ); - cmData_t* cmDataAllocDouble( cmData_t* parent, double v ); - - // Dynamically allocate a data object and set its array value to an external - // array. v[cnt] is assigned as the internal data space for the object and - // therefore must remain valid for the life of the object. - // See the cmDataXXXAlocPtr() for equivalent functions which dynamically - // allocate the intenal data space. - cmData_t* cmDataAllocStr( cmData_t* parent, cmChar_t* str ); - cmData_t* cmDataAllocConstStr( cmData_t* parent, const cmChar_t* str ); - cmData_t* cmDataAllocCharPtr( cmData_t* parent, char* v, unsigned cnt ); - cmData_t* cmDataAllocUCharPtr( cmData_t* parent, unsigned char* v, unsigned cnt ); - cmData_t* cmDataAllocShortPtr( cmData_t* parent, short* v, unsigned cnt ); - cmData_t* cmDataAllocUShortPtr( cmData_t* parent, unsigned short* v, unsigned cnt ); - cmData_t* cmDataAllocIntPtr( cmData_t* parent, int* v, unsigned cnt ); - cmData_t* cmDataAllocUIntPtr( cmData_t* parent, unsigned int* v, unsigned cnt ); - cmData_t* cmDataAllocLongPtr( cmData_t* parent, long* v, unsigned cnt ); - cmData_t* cmDataAllocULongPtr( cmData_t* parent, unsigned long* v, unsigned cnt ); - cmData_t* cmDataAllocFloatPtr( cmData_t* parent, float* v, unsigned cnt ); - cmData_t* cmDataAllocDoublePtr( cmData_t* parent, double* v, unsigned cnt ); - cmData_t* cmDataAllocVoidPtr( cmData_t* parent, void* v, unsigned cnt ); - - - // Dynamically allocate a data object and its array value. - // These functions dynamically allocate the internal array data space - // and copy v[cnt] into it. - cmData_t* cmDataStrAlloc( cmData_t* parent, cmChar_t* str ); - cmData_t* cmDataConstStrAlloc( cmData_t* parent, const cmChar_t* str ); - cmData_t* cmDataConstStrAllocN( cmData_t* parent, const cmChar_t* str, unsigned charCnt ); - cmData_t* cmDataCharAllocPtr( cmData_t* parent, const char* v, unsigned cnt ); - cmData_t* cmDataUCharAllocPtr( cmData_t* parent, const unsigned char* v, unsigned cnt ); - cmData_t* cmDataShortAllocPtr( cmData_t* parent, const short* v, unsigned cnt ); - cmData_t* cmDataUShortAllocPtr( cmData_t* parent, const unsigned short* v, unsigned cnt ); - cmData_t* cmDataIntAllocPtr( cmData_t* parent, const int* v, unsigned cnt ); - cmData_t* cmDataUIntAllocPtr( cmData_t* parent, const unsigned int* v, unsigned cnt ); - cmData_t* cmDataLongAllocPtr( cmData_t* parent, const long* v, unsigned cnt ); - cmData_t* cmDataULongAllocPtr( cmData_t* parent, const unsigned long* v, unsigned cnt ); - cmData_t* cmDataFloatAllocPtr( cmData_t* parent, const float* v, unsigned cnt ); - cmData_t* cmDataDoubleAllocPtr( cmData_t* parent, const double* v, unsigned cnt ); - cmData_t* cmDataVoidAllocPtr( cmData_t* parent, const void* v, unsigned cnt ); - - //---------------------------------------------------------------------------- - // Structure related functions - // - - // Release an object and any resources held by it. - // Note the this function does not unlink the object - // from it's parent. Use cmDataUnlinkAndFree() - // to remove a object from it's parent list prior - // to releasing it. - void cmDataFree( cmData_t* p ); - - // Unlink 'p' from its parents and siblings. - // Asserts if parent is not a structure. - // Returns 'p'. - cmData_t* cmDataUnlink( cmData_t* p ); - - // Wrapper function to cmDataUnlink() and cmDataFree(). - void cmDataUnlinkAndFree( cmData_t* p ); - - // Replace the 'dst' node with the 'src' node and - // return 'src'. This operation does not duplicate - // 'src' it simply links in 'src' at the location of - // 'dst' and then unlinks and free's 'dst'. - cmData_t* cmDataReplace( cmData_t* dst, cmData_t* src ); - - // Return the count of child nodes. - // 1. Array nodes have one child per array element. - // 2. List nodes have one child pair. - // 3. Pair nodes have two children. - // 4. Leaf nodes have 0 children. - unsigned cmDataChildCount( const cmData_t* p ); - - // Returns the ith child of 'p'. - // Returns NULL if p has no children or index is invalid. - cmData_t* cmDataChild( cmData_t* p, unsigned index ); - - // Prepend 'p' to 'parents' child list. - // The source node 'p' is not duplicated it is simply linked in. - // 'p' is automatically unlinked prior to being prepended. - // Returns 'p'. - cmData_t* cmDataPrependChild(cmData_t* parent, cmData_t* p ); - - // Append 'p' to the end of 'parent' child list. - // The source node 'p' is not duplicated it is simply linked in. - // 'p' is automatically unlinked prior to being appended. - // Returns 'p'. - cmData_t* cmDataAppendChild( cmData_t* parent, cmData_t* p ); - - // Insert 'p' at index. Index must be in the range: - // 0 to cmDataChildCount(parent). - // The source node 'p' is not duplicated it is simply linked in. - // 'p' is automatically unlinked prior to being inserted. - // Returns 'p'. - cmData_t* cmDataInsertChild( cmData_t* parent, unsigned index, cmData_t* p ); - - //---------------------------------------------------------------------------- // Pair related functions // @@ -814,15 +480,15 @@ extern "C" { // Var-args fmt: - // {} + // {} {} // scalar types: is literal, is not included // null has no or - // ptr types: is pointer, is element count - // struct types: is cmData_t, is not included + // array types: is pointer, is element count + // struct types: is cmData_t, and is not included // Indicate the end of argument list by setting to kInvalidDtId. // The memory for array based data types is dynamically allocated. - cmData_t* cmDataListAllocV(cmData_t* parent, va_list vl ); - cmData_t* cmDataListAllocA(cmData_t* parent, ... ); + cmRC_t cmDataListAllocV(cmData_t* parent, cmData_t** ref, va_list vl ); + cmRC_t cmDataListAllocA(cmData_t* parent, cmData_t** ref, ... ); // Returns a ptr to 'ele'. cmData_t* cmDataListAppendEle( cmData_t* p, cmData_t* ele ); @@ -833,9 +499,6 @@ extern "C" { cmData_t* cmDataListInsertEle( cmData_t* p, unsigned index, cmData_t* ele ); cmData_t* cmDataListInsertEleN(cmData_t* p, unsigned index, cmData_t* ele[], unsigned n ); - cmData_t* cmDataListUnlink( cmData_t* p, unsigned index ); - cmData_t* cmDataListFree( cmData_t* p, unsigned index ); - //---------------------------------------------------------------------------- // Record related functions // @@ -866,7 +529,7 @@ extern "C" { // Var-args format: - // {} + // {} {} // scalar types: is literal, is not included // null type: has no or // ptr types: is pointer, is element count @@ -918,7 +581,6 @@ extern "C" { void cmDataPrint( const cmData_t* p, cmRpt_t* rpt ); void cmDataTest( cmCtx_t* ctx ); -#endif #ifdef __cplusplus