From 72b959690f848ba9e66671ae643a57ec86737c4c Mon Sep 17 00:00:00 2001 From: kpl Date: Mon, 27 Jan 2020 17:48:17 -0500 Subject: [PATCH] cwObject.h/cpp : Added list_ele(). --- cwObject.cpp | 16 ++++++++++++++-- cwObject.h | 11 +++++------ 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/cwObject.cpp b/cwObject.cpp index 790c043..cb922a1 100644 --- a/cwObject.cpp +++ b/cwObject.cpp @@ -371,11 +371,23 @@ const struct cw::object_str* cw::object_t::find( const char* label ) const if((ch = o->find(label)) != nullptr ) return ch; } - } - + } return nullptr; } +const struct cw::object_str* cw::object_t::list_ele( unsigned idx ) const +{ + if( is_list() ) + { + unsigned i = 0; + for(object_t* o=u.children; o!=nullptr; o=o->sibling,++i) + if( i == idx ) + return o; + } + return nullptr; +} + + void cw::object_t::print(const print_ctx_t* c) const { diff --git a/cwObject.h b/cwObject.h index 471b120..36496c8 100644 --- a/cwObject.h +++ b/cwObject.h @@ -35,8 +35,6 @@ namespace cw }; typedef unsigned objTypeId_t; - - enum { @@ -102,10 +100,10 @@ namespace cw inline bool is_value_container() const { return type != nullptr && cwIsFlag(type->flags,kValueContainerFl); } // Containers have children and use the object.u.children pointer. - inline bool is_container() const { return type != nullptr && cwIsFlag(type->flags,kContainerFl); } - inline bool is_pair() const { return type != nullptr && type->id == kPairTId; } - inline bool is_dict() const { return type != nullptr && type->id == kDictTId; } - inline bool is_list() const { return type != nullptr && type->id == kListTId; } + inline bool is_container() const { return type != nullptr && cwIsFlag(type->flags,kContainerFl); } + inline bool is_pair() const { return type != nullptr && type->id == kPairTId; } + inline bool is_dict() const { return type != nullptr && type->id == kDictTId; } + inline bool is_list() const { return type != nullptr && type->id == kListTId; } rc_t value( void* dst, unsigned dstTypeId ); rc_t value( char& v ) const; @@ -124,6 +122,7 @@ namespace cw const char* pair_label() const; const struct object_str* pair_value() const; const struct object_str* find( const char* label ) const; + const struct object_str* list_ele( unsigned idx ) const; template< typename T > rc_t get( const char* label, T& v ) const