added access on tag_name and tag_value

This commit is contained in:
2025-08-23 14:37:36 +02:00
parent 769ad2b002
commit 3a5fbad33e
14 changed files with 89 additions and 32 deletions

View File

@@ -43,16 +43,16 @@ namespace znode
// forward declaration of base class zbasic_node ...
//template<class str_t>
//template<typename str_t>
//class zbasic_node;
// ... used here for conveniance typedef
//template<class str_t>
//template<typename str_t>
//using zshared_node = std::shared_ptr<zbasic_node<str_t>>;
//! einfache tree-klasse, besonderheit: der nutzlast-string-type ist templated.
template<class str_t>
template<typename str_t>
class zbasic_node : public zid, public zpayload<str_t>, public std::enable_shared_from_this<zbasic_node<str_t>>
{
@@ -400,7 +400,7 @@ namespace znode
virtual void begin()
{}
template<class str_t>
template<typename str_t>
void for_each_node( zbasic_node<str_t>* node );
virtual void end()

View File

@@ -40,7 +40,7 @@ model: muss ich wirklich jeden attibute node einzeln angeben?
*/
namespace znode
{
template<class str_t>
template<typename str_t>
class znode_factory
{

View File

@@ -21,7 +21,7 @@
namespace znode
{
template<class T>
template<typename T>
struct znode_iterator
{
using iterator_category = std::forward_iterator_tag;

View File

@@ -9,7 +9,7 @@
namespace znode
{
template<class str_t>
template<typename str_t>
class zstringmap : public std::map<str_t,str_t>
{
@@ -38,7 +38,7 @@ namespace znode
};
template<class str_t>
template<typename str_t>
class zpayload
{
@@ -52,7 +52,10 @@ namespace znode
// __fixme: should this be a vector? or a maptor?
//using zattributes = std::map<str_t, zvalue>;
using zattributes = zstringmap<str_t>;
using callmap_ref = std::map<str_t, str_cref (zpayload<str_t>::*)() const>;
using callmap_ptr = std::map<str_t, str_ptr (zpayload<str_t>::*)() const>;
static const str_t cTagName; // = "TagName";
static const str_t cType;// = "Type";
static const str_t cName;// = "Name";
static const str_t cValue;// = "Value";
@@ -188,6 +191,22 @@ namespace znode
return true;
}
const zvalue& fixed_attribute(str_cref key ) const
{
static callmap_ref s_fixed_attributes
{
{ cTagName, &zpayload::tag_name },
{ cValue, &zpayload::tag_value }
};
auto it = s_fixed_attributes.find(key);
if (it != s_fixed_attributes.end())
return (this->*(it->second))();
return s_dummy_value;
}
const zvalue& attribute(str_cref key ) const
{
if( !xstr_is_empty( key ) )
@@ -201,7 +220,24 @@ namespace znode
return result;
}
}
return s_dummy_value;
//return s_dummy_value;
return fixed_attribute( key );
}
const zvalue& fixed_attribute_ptr(str_cref key ) const
{
static callmap_ptr s_fixed_attributes_ptr
{
{ cTagName, &zpayload<str_t>::tag_name_ptr },
{ cValue, &zpayload<str_t>::tag_value_ptr }
};
auto it = s_fixed_attributes_ptr.find(key);
if (it != s_fixed_attributes_ptr.end() )
(this->*(it->second))();
return &s_dummy_value;
}
const zvalue* attribute_ptr(str_cref key ) const
@@ -217,6 +253,7 @@ namespace znode
return &result;
}
}
//return fixed_attribute_ptr( key );
return &s_dummy_value;
}
@@ -259,7 +296,7 @@ namespace znode
};
// init statics
template<class str_t>
template<typename str_t>
str_t zpayload<str_t>::s_dummy_value;
}

View File

@@ -6,7 +6,7 @@
//using znode_vector = std::vector<zplain_node*>;
template<class T>
template<typename T>
class znode_vector : public std::vector<T*>
{