cwObject.h : Fixed bug where type CString was confused for type String. Added comments, and error messages.
This commit is contained in:
parent
4d5dadf0b9
commit
6670a961be
26
cwObject.cpp
26
cwObject.cpp
@ -90,8 +90,25 @@ namespace cw
|
||||
return cwLogError(kInvalidArgRC, "There is no conversion from '%s' to '%s'.", _objTypeIdToLabel(tid), o->type->label);
|
||||
}
|
||||
|
||||
rc_t _objTypeValueFromCString( const object_t* o, unsigned tid, void* dst )
|
||||
{
|
||||
if( tid == kCStringTId )
|
||||
{
|
||||
*(const char**)dst = o->u.str;
|
||||
return kOkRC;
|
||||
}
|
||||
return _objTypeValueFromNonValue(o,tid,dst);
|
||||
}
|
||||
|
||||
rc_t _objTypeValueFromString( const object_t* o, unsigned tid, void* dst )
|
||||
{
|
||||
// When objects are parsed all strings are non-const. therefore when a string is retrieved
|
||||
// from an object the string will always be non-const - but the type of the variable
|
||||
// to receive the value may be const - we detect this here and redirect to the 'const char*'
|
||||
// version of the function.
|
||||
if( tid == kCStringTId )
|
||||
return _objTypeValueFromCString(o,tid,dst);
|
||||
|
||||
if( tid == kStringTId )
|
||||
{
|
||||
*(char**)dst = o->u.str;
|
||||
@ -100,6 +117,7 @@ namespace cw
|
||||
return _objTypeValueFromNonValue(o,tid,dst);
|
||||
}
|
||||
|
||||
|
||||
rc_t _objTypeValueFromVect( const object_t* o, unsigned tid, void* dst )
|
||||
{ return _objTypeValueFromNonValue(o,tid,dst); }
|
||||
|
||||
@ -279,7 +297,7 @@ namespace cw
|
||||
{ kFloatTId, "float", 0, _objTypeFree, _objTypeValueFromFloat, _objTypePrintFloat, _objTypeToStringFloat },
|
||||
{ kDoubleTId, "double", 0, _objTypeFree, _objTypeValueFromDouble, _objTypePrintDouble, _objTypeToStringDouble },
|
||||
{ kStringTId, "string", 0, _objTypeFreeString, _objTypeValueFromString, _objTypePrintString, _objTypeToStringString },
|
||||
{ kCStringTId, "cstring", 0, _objTypeFree, _objTypeValueFromString, _objTypePrintString, _objTypeToStringString },
|
||||
{ kCStringTId, "cstring", 0, _objTypeFree, _objTypeValueFromCString, _objTypePrintString, _objTypeToStringString },
|
||||
{ kVectTId, "vect", 0, _objTypeFree, _objTypeValueFromVect, _objTypePrintVect, _objTypeToStringVect },
|
||||
{ kPairTId, "pair", kContainerFl | kValueContainerFl, _objTypeFree, _objTypeValueFromNonValue, _objTypePrintPair, _objTypeToStringPair },
|
||||
{ kListTId, "list", kContainerFl | kValueContainerFl, _objTypeFree, _objTypeValueFromNonValue, _objTypePrintList, _objTypeToStringList },
|
||||
@ -764,7 +782,11 @@ cw::rc_t cw::objectFromFile( const char* fn, object_t*& objRef )
|
||||
unsigned bufByteCnt = 0;
|
||||
char* buf = NULL;
|
||||
|
||||
if(( buf = file::fnToStr(fn, &bufByteCnt)) != NULL )
|
||||
objRef = nullptr;
|
||||
|
||||
if(( buf = file::fnToStr(fn, &bufByteCnt)) == NULL )
|
||||
rc = cwLogError(kOpFailRC,"File to text buffer conversion failed on '%s'.",cwStringNullGuard(fn));
|
||||
else
|
||||
{
|
||||
rc = objectFromString( buf, objRef );
|
||||
mem::release(buf);
|
||||
|
@ -162,13 +162,16 @@ namespace cw
|
||||
|
||||
rc_t getv() const { return kOkRC; }
|
||||
|
||||
// getv("label0",v0,"label1",v1, ... )
|
||||
template< typename T0, typename T1, typename... ARGS >
|
||||
rc_t getv( T0 label, T1& valRef, ARGS&&... args ) const
|
||||
{
|
||||
rc_t rc;
|
||||
|
||||
if((rc = get(label,valRef)) == kOkRC )
|
||||
rc = getv(std::forward<ARGS>(args)...);
|
||||
if((rc = getv(std::forward<ARGS>(args)...)) != kOkRC )
|
||||
cwLogError(rc,"getv() failed for the pair label:'%s'.",cwStringNullGuard(label));
|
||||
|
||||
return rc;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user