cmData.h/c : Addd cmDataRecdParseXXX() functions. Added beginning
modifications to include function which report errors without using the global variable _cmDataErrNo.
This commit is contained in:
parent
42a9f19166
commit
55fe26deb2
179
cmData.c
179
cmData.c
@ -1730,7 +1730,7 @@ cmData_t* cmRecdAppendPair( cmData_t* p, cmData_t* pair )
|
||||
}
|
||||
|
||||
|
||||
cmDtRC_t _cmDataRecdParseV(cmData_t* parent, unsigned idFl, va_list vl )
|
||||
cmDtRC_t _cmDataRecdParseInputV(cmData_t* parent, unsigned idFl, va_list vl )
|
||||
{
|
||||
assert( parent != NULL && parent->tid == kRecordDtId );
|
||||
bool contFl = true;
|
||||
@ -1750,7 +1750,7 @@ cmDtRC_t _cmDataRecdParseV(cmData_t* parent, unsigned idFl, va_list vl )
|
||||
label = va_arg(vl,const char*); // text field label identifier
|
||||
|
||||
// validate the field identifier
|
||||
if( id==kInvalidDtId || label==NULL )
|
||||
if( id==kInvalidDtId && label==NULL )
|
||||
break;
|
||||
|
||||
// parse the field data
|
||||
@ -1773,7 +1773,7 @@ cmDtRC_t _cmDataRecdParseV(cmData_t* parent, unsigned idFl, va_list vl )
|
||||
cmData_t* cmDataRecdAllocLabelV( cmData_t* parent, va_list vl )
|
||||
{
|
||||
cmData_t* p = cmRecdAlloc(parent);
|
||||
cmDtRC_t rc = _cmDataRecdParseV(p, false, vl );
|
||||
cmDtRC_t rc = _cmDataRecdParseInputV(p, false, vl );
|
||||
if( rc != kOkDtRC )
|
||||
{
|
||||
cmDataFree(p);
|
||||
@ -1794,7 +1794,7 @@ cmData_t* cmDataRecdAllocLabelA( cmData_t* parent, ... )
|
||||
cmData_t* cmDataRecdAllocIdV( cmData_t* parent, va_list vl )
|
||||
{
|
||||
cmData_t* p = cmRecdAlloc(parent);
|
||||
cmDtRC_t rc = _cmDataRecdParseV(p, true, vl );
|
||||
cmDtRC_t rc = _cmDataRecdParseInputV(p, true, vl );
|
||||
if( rc != kOkDtRC )
|
||||
{
|
||||
cmDataFree(p);
|
||||
@ -1812,6 +1812,177 @@ cmData_t* cmDataRecdAllocIdA( cmData_t* parent, ... )
|
||||
return p;
|
||||
}
|
||||
|
||||
cmDtRC_t _cmDataRecdParseV(cmData_t* p, bool idFl, cmErr_t* err, 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( id==kInvalidDtId && label==NULL )
|
||||
break;
|
||||
|
||||
cmDataFmtId_t typeId = va_arg(vl,unsigned);
|
||||
void* v = va_arg(vl,void*);
|
||||
cmData_t* np = NULL;
|
||||
|
||||
if( idFl )
|
||||
np = cmDataRecdValueFromLabel( p, label );
|
||||
else
|
||||
np = cmDataRecdValueFromId( p, id );
|
||||
|
||||
switch(typeId)
|
||||
{
|
||||
case kNullDtId:
|
||||
break;
|
||||
|
||||
case kUCharDtId:
|
||||
*((unsigned char*)v) = cmDataGetUChar(np);
|
||||
break;
|
||||
|
||||
case kCharDtId:
|
||||
*((char*)v) = cmDataGetChar(np);
|
||||
break;
|
||||
|
||||
case kUShortDtId:
|
||||
*((unsigned short*)v) = cmDataGetUShort(np);
|
||||
break;
|
||||
|
||||
case kShortDtId:
|
||||
*((short*)v) = cmDataGetShort(np);
|
||||
break;
|
||||
|
||||
case kUIntDtId:
|
||||
*((unsigned int*)v) = cmDataGetUInt(np);
|
||||
break;
|
||||
|
||||
case kIntDtId:
|
||||
*((int*)v) = cmDataGetInt(np);
|
||||
break;
|
||||
|
||||
case kULongDtId:
|
||||
*((unsigned long*)v) = cmDataGetULong(np);
|
||||
break;
|
||||
|
||||
case kLongDtId:
|
||||
*((long*)v) = cmDataGetLong(np);
|
||||
break;
|
||||
|
||||
case kFloatDtId:
|
||||
*((float*)v) = cmDataGetFloat(np);
|
||||
break;
|
||||
|
||||
case kDoubleDtId:
|
||||
*((double*)v) = cmDataGetDouble(np);
|
||||
break;
|
||||
|
||||
case kStrDtId:
|
||||
*((char**)v) = cmDataGetStr(np);
|
||||
break;
|
||||
|
||||
case kConstStrDtId:
|
||||
*((const char**)v) = cmDataGetConstStr(np);
|
||||
break;
|
||||
|
||||
case kUCharPtrDtId:
|
||||
*((unsigned char**)v) = cmDataGetUCharPtr(np);
|
||||
break;
|
||||
|
||||
case kCharPtrDtId:
|
||||
*((char**)v) = cmDataGetCharPtr(np);
|
||||
break;
|
||||
|
||||
case kUShortPtrDtId:
|
||||
*((unsigned short**)v) = cmDataGetUShortPtr(np);
|
||||
break;
|
||||
|
||||
case kShortPtrDtId:
|
||||
*((short**)v) = cmDataGetShortPtr(np);
|
||||
break;
|
||||
|
||||
case kUIntPtrDtId:
|
||||
*((unsigned int**)v) = cmDataGetUIntPtr(np);
|
||||
break;
|
||||
|
||||
case kIntPtrDtId:
|
||||
*((int**)v) = cmDataGetIntPtr(np);
|
||||
break;
|
||||
|
||||
case kULongPtrDtId:
|
||||
*((unsigned long**)v) = cmDataGetULongPtr(np);
|
||||
break;
|
||||
|
||||
case kLongPtrDtId:
|
||||
*((long**)v) = cmDataGetLongPtr(np);
|
||||
break;
|
||||
|
||||
case kFloatPtrDtId:
|
||||
*((float**)v) = cmDataGetFloatPtr(np);
|
||||
break;
|
||||
|
||||
case kDoublePtrDtId:
|
||||
*((double**)v) = cmDataGetDoublePtr(np);
|
||||
break;
|
||||
|
||||
case kVoidPtrDtId:
|
||||
*((void**)v) = cmDataGetDoublePtr(np);
|
||||
break;
|
||||
|
||||
case kListDtId:
|
||||
case kPairDtId:
|
||||
case kRecordDtId:
|
||||
if( np->tid != typeId )
|
||||
_cmDataSetError(kCvtErrDtRC);
|
||||
else
|
||||
*(cmData_t**)v = np;
|
||||
break;
|
||||
|
||||
default:
|
||||
_cmDataSetError(kVarArgErrDtRC);
|
||||
assert(0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, va_list vl )
|
||||
{ return _cmDataRecdParseV(p,false,err,vl); }
|
||||
|
||||
cmDtRC_t cmDataRecdParseLabel(cmData_t* p, cmErr_t* err, ... )
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl,err);
|
||||
cmDtRC_t rc = cmDataRecdParseLabelV(p,err,vl);
|
||||
va_end(vl);
|
||||
return rc;
|
||||
}
|
||||
|
||||
cmDtRC_t cmDataRecdParseIdV(cmData_t* p, cmErr_t* err, va_list vl )
|
||||
{ return _cmDataRecdParseV(p,true,err,vl); }
|
||||
|
||||
cmDtRC_t cmDataRecdParseId(cmData_t* p, cmErr_t* err, ... )
|
||||
{
|
||||
va_list vl;
|
||||
va_start(vl,err);
|
||||
cmDtRC_t rc = cmDataRecdParseIdV(p,err,vl);
|
||||
va_end(vl);
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
unsigned cmDataSerializeByteCount( const cmData_t* p )
|
||||
{
|
||||
|
40
cmData.h
40
cmData.h
@ -204,6 +204,31 @@ extern "C" {
|
||||
double* cmDataDoublePtr( const cmData_t* p );
|
||||
|
||||
|
||||
// Get the value of an object with conversion.
|
||||
cmDtRC_t cmDataGetCharE( const cmData_t* p, char* v );
|
||||
cmDtRC_t cmDataGetUCharE( const cmData_t* p, unsigned char* v );
|
||||
cmDtRC_t cmDataGetShortE( const cmData_t* p, short* v );
|
||||
cmDtRC_t cmDataGetUShortE( const cmData_t* p, unsigned short* v );
|
||||
cmDtRC_t cmDataGetIntE( const cmData_t* p, int* v );
|
||||
cmDtRC_t cmDataGetUIntE( const cmData_t* p, unsigned int* v );
|
||||
cmDtRC_t cmDataGetLongE( const cmData_t* p, long* v );
|
||||
cmDtRC_t cmDataGetULongE( const cmData_t* p, unsigned long* v );
|
||||
cmDtRC_t cmDataGetFloatE( const cmData_t* p, float* v );
|
||||
cmDtRC_t cmDataGetDoubleE( const cmData_t* p, double* v );
|
||||
cmDtRC_t cmDataGetStrE( const cmData_t* p, char** v );
|
||||
cmDtRC_t cmDataGetConstStrE( const cmData_t* p, const char** v );
|
||||
cmDtRC_t cmDataGetVoidPtrE( const cmData_t* p, void** v );
|
||||
cmDtRC_t cmDataGetCharPtrE( const cmData_t* p, char** v );
|
||||
cmDtRC_t cmDataGetUCharPtrE( const cmData_t* p, unsigned char** v );
|
||||
cmDtRC_t cmDataGetShortPtrE( const cmData_t* p, short** v );
|
||||
cmDtRC_t cmDataGetUShortPtrE( const cmData_t* p, unsigned short** v );
|
||||
cmDtRC_t cmDataGetIntPtrE( const cmData_t* p, int** v );
|
||||
cmDtRC_t cmDataGetUIntPtrE( const cmData_t* p, unsigned int** v );
|
||||
cmDtRC_t cmDataGetLongPtrE( const cmData_t* p, long** v );
|
||||
cmDtRC_t cmDataGetULongPtrE( const cmData_t* p, unsigned long** v );
|
||||
cmDtRC_t cmDataGetFloatPtrE( const cmData_t* p, float** v );
|
||||
cmDtRC_t cmDataGetDoublePtrE( const cmData_t* p, double** v );
|
||||
|
||||
// Get the value of an object with conversion.
|
||||
char cmDataGetChar( const cmData_t* p );
|
||||
unsigned char cmDataGetUChar( const cmData_t* p );
|
||||
@ -230,6 +255,7 @@ extern "C" {
|
||||
double* cmDataGetDoublePtr( const cmData_t* p );
|
||||
|
||||
|
||||
|
||||
// Set the value of an existing scalar data object.
|
||||
cmData_t* cmDataSetNull( cmData_t* p );
|
||||
cmData_t* cmDataSetChar( cmData_t* p, char v );
|
||||
@ -479,9 +505,9 @@ extern "C" {
|
||||
|
||||
// Var-args fmt:
|
||||
// <label|id> <typeId> <value> {<cnt>}
|
||||
// scalar types: <value> is literal,<cnt> is not included
|
||||
// null has no <value> or <cnt>
|
||||
// ptr types: <value> is pointer,<cnt> is element count
|
||||
// scalar types: <value> is literal,<cnt> is not included
|
||||
// null type has no <value> or <cnt>
|
||||
// ptr types: <value> is pointer, <cnt> is element count
|
||||
// struct types: <value> is cmData_t, <cnt> is not included
|
||||
// Indicate the end of argument list by setting <typeId> to kInvalidDtId.
|
||||
// The memory for array based data types is dynamically allocated.
|
||||
@ -491,8 +517,12 @@ extern "C" {
|
||||
cmData_t* cmDataRecdAllocIdV( cmData_t* parent, va_list vl );
|
||||
cmData_t* cmDataRecdAllocIdA( cmData_t* parent, ... );
|
||||
|
||||
|
||||
|
||||
// Extract the data in a record to C variables.
|
||||
// <label|id> <typeId> <pointer>
|
||||
cmDtRC_t cmDataRecdParseLabelV(cmData_t* p, cmErr_t* err, va_list vl );
|
||||
cmDtRC_t cmDataRecdParseLabel( cmData_t* p, cmErr_t* err, ... );
|
||||
cmDtRC_t cmDataRecdParseIdV( cmData_t* p, cmErr_t* err, va_list vl );
|
||||
cmDtRC_t cmDataRecdParseId( cmData_t* p, cmErr_t* err, ... );
|
||||
|
||||
unsigned cmDataSerializeByteCount( const cmData_t* p );
|
||||
cmDtRC_t cmDataSerialize( const cmData_t* p, void* buf, unsigned bufByteCnt );
|
||||
|
Loading…
Reference in New Issue
Block a user