cwObject.h/cpp : Added putv() and put_numeric_list(). Changed newDictObject() and newListObject()

from:
{ return  _objAllocate( kDictTId, parent); }
to:
{ return _objAppendRightMostNode(parent,  _objAllocate( kDictTId, parent) ); }
This commit is contained in:
kevin 2023-10-21 09:58:51 -04:00
parent 6938e5a278
commit c305b4b4da
2 changed files with 39 additions and 2 deletions

View File

@ -746,10 +746,10 @@ cw::object_t* cw::newObject( const char* v, object_t* parent)
{ return _objCreateValueNode<const char*>( parent, v ); }
cw::object_t* cw::newDictObject( object_t* parent )
{ return _objAllocate( kDictTId, parent); }
{ return _objAppendRightMostNode(parent, _objAllocate( kDictTId, parent) ); }
cw::object_t* cw::newListObject( object_t* parent )
{ return _objAllocate( kListTId, parent ); }
{ return _objAppendRightMostNode(parent, _objAllocate( kListTId, parent) ); }
cw::object_t* cw::newPairObject( const char* label, object_t* value, object_t* parent)
{

View File

@ -88,6 +88,9 @@ namespace cw
} objType_t;
struct object_str* newPairObject( const char* label, struct object_str* v, struct object_str* parent );
struct object_str* newListObject( struct object_str* parent );
typedef struct object_str
{
objType_t* type = nullptr;
@ -246,6 +249,40 @@ namespace cw
{ return newPairObject(label, v, this); }
rc_t _putv() { return kOkRC; }
// getv("label0",v0,"label1",v1, ... )
template< typename T0, typename T1, typename... ARGS >
rc_t _putv( T0 label, const T1& val, ARGS&&... args )
{
insert_pair(label,val);
_putv(std::forward<ARGS>(args)...); // ... recurse to find next label/value pair
return kOkRC;
}
// getv("label0",v0,"label1",v1, ... )
template< typename T0, typename T1, typename... ARGS >
rc_t putv( T0 label, const T1& val, ARGS&&... args )
{ return _putv(label,val,args...); }
template< typename T >
struct object_str* put_numeric_list( const char* label, const T* v, unsigned vN )
{
struct object_str* pair = newPairObject(label,newListObject(nullptr),this)->parent;
struct object_str* list = pair->pair_value();
for(unsigned i=0; i<vN; ++i)
newObject(v[i],list);
return pair;
}
template< typename T>
rc_t set( const char* label, const T& value )
{