cwObject.h/cpp : Added list_ele().

This commit is contained in:
kpl 2020-01-27 17:48:17 -05:00
parent 59507913e0
commit 72b959690f
2 changed files with 19 additions and 8 deletions

View File

@ -372,10 +372,22 @@ const struct cw::object_str* cw::object_t::find( const char* label ) const
return ch; return ch;
} }
} }
return nullptr; 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 void cw::object_t::print(const print_ctx_t* c) const
{ {

View File

@ -36,8 +36,6 @@ namespace cw
typedef unsigned objTypeId_t; typedef unsigned objTypeId_t;
enum enum
{ {
kValueContainerFl = 0x01, // root,pair, or list are the only legal value containers kValueContainerFl = 0x01, // root,pair, or list are the only legal value containers
@ -102,10 +100,10 @@ namespace cw
inline bool is_value_container() const { return type != nullptr && cwIsFlag(type->flags,kValueContainerFl); } inline bool is_value_container() const { return type != nullptr && cwIsFlag(type->flags,kValueContainerFl); }
// Containers have children and use the object.u.children pointer. // 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_container() const { return type != nullptr && cwIsFlag(type->flags,kContainerFl); }
inline bool is_pair() const { return type != nullptr && type->id == kPairTId; } 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_dict() const { return type != nullptr && type->id == kDictTId; }
inline bool is_list() const { return type != nullptr && type->id == kListTId; } inline bool is_list() const { return type != nullptr && type->id == kListTId; }
rc_t value( void* dst, unsigned dstTypeId ); rc_t value( void* dst, unsigned dstTypeId );
rc_t value( char& v ) const; rc_t value( char& v ) const;
@ -124,6 +122,7 @@ namespace cw
const char* pair_label() const; const char* pair_label() const;
const struct object_str* pair_value() const; const struct object_str* pair_value() const;
const struct object_str* find( const char* label ) const; const struct object_str* find( const char* label ) const;
const struct object_str* list_ele( unsigned idx ) const;
template< typename T > template< typename T >
rc_t get( const char* label, T& v ) const rc_t get( const char* label, T& v ) const