From c305b4b4daebe26751ffef7be9bdca5655d40e30 Mon Sep 17 00:00:00 2001 From: kevin Date: Sat, 21 Oct 2023 09:58:51 -0400 Subject: [PATCH] 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) ); } --- cwObject.cpp | 4 ++-- cwObject.h | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/cwObject.cpp b/cwObject.cpp index 518ca04..a84a6c8 100644 --- a/cwObject.cpp +++ b/cwObject.cpp @@ -746,10 +746,10 @@ cw::object_t* cw::newObject( const char* v, object_t* parent) { return _objCreateValueNode( 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) { diff --git a/cwObject.h b/cwObject.h index c69a848..67e6205 100644 --- a/cwObject.h +++ b/cwObject.h @@ -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)...); // ... 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 rc_t set( const char* label, const T& value ) {