added some comments.
This commit is contained in:
@@ -34,7 +34,13 @@
|
||||
namespace znode
|
||||
{
|
||||
|
||||
/// ----------------- snip 8< -----------------------------------------------------------------------------------------------------------------------------
|
||||
/*
|
||||
|
||||
- die payload attributes wird 'drangeerbt'. sollte die nicht besser ge-templatet sein?
|
||||
- die finder sollten besser ausgelagert sein
|
||||
|
||||
*/
|
||||
|
||||
|
||||
// forward declaration of base class zbasic_node ...
|
||||
//template<class str_t>
|
||||
@@ -45,7 +51,7 @@ namespace znode
|
||||
//using zshared_node = std::shared_ptr<zbasic_node<str_t>>;
|
||||
|
||||
|
||||
// main class
|
||||
//! einfache tree-klasse, besonderheit: der nutzlast-string-type ist templated.
|
||||
template<class str_t>
|
||||
class zbasic_node : public zid, public zpayload<str_t>, public std::enable_shared_from_this<zbasic_node<str_t>>
|
||||
{
|
||||
@@ -88,29 +94,30 @@ namespace znode
|
||||
|
||||
public:
|
||||
|
||||
//! shortcut auf std::make_shared...
|
||||
static zshared_node make_node( str_cref arg1, str_cref arg2 = "" , zshared_cref parent = nullptr )
|
||||
{
|
||||
return std::make_shared<zbasic_node>( arg1, arg2, parent );
|
||||
}
|
||||
|
||||
//! leerer konstruktor
|
||||
zbasic_node() = default;
|
||||
|
||||
// ...
|
||||
//! konstruktor mit tag_name und optionalem elternknoten
|
||||
zbasic_node( str_cref tag_name, zshared_cref parent = nullptr )
|
||||
: zpayload<str_t>{tag_name}, _parent{parent}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
// ...
|
||||
//! konstruktor mit tag_name, value und optionalem elternknoten
|
||||
zbasic_node( str_cref tag_name, str_cref value, zshared_cref parent = nullptr )
|
||||
: zpayload<str_t>{tag_name,value}, _parent{parent}
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
//! konstruktor mit tag_name, attributlist und optionalem elternknoten
|
||||
zbasic_node( str_cref tag_name, const str_list& attributes, zshared_cref parent = nullptr )
|
||||
: zbasic_node{tag_name, parent}
|
||||
{
|
||||
@@ -122,16 +129,18 @@ namespace znode
|
||||
}
|
||||
}
|
||||
|
||||
//! default destruktor
|
||||
virtual ~zbasic_node() = default;
|
||||
|
||||
// Kopieren ist hier nicht sinnvoll (Child-Pointer müssen konsistent bleiben)
|
||||
//! kopieren ist hier nicht sinnvoll
|
||||
zbasic_node(const zbasic_node&) = delete;
|
||||
zbasic_node& operator=(const zbasic_node&) = delete;
|
||||
|
||||
// Bewegen geht (shared_from_this bleibt gültig)
|
||||
// 'move' geht (shared_from_this bleibt gültig)
|
||||
zbasic_node(zbasic_node&&) noexcept = default;
|
||||
zbasic_node& operator=(zbasic_node&&) noexcept = default;
|
||||
|
||||
//! erzeugt eine deep-copy von 'mir' _mit_ allen kindknoten
|
||||
virtual zshared_node clone(const zshared_node& parent = nullptr ) const
|
||||
{
|
||||
// copy als shared ptr erzeugen
|
||||
@@ -148,12 +157,13 @@ namespace znode
|
||||
|
||||
}
|
||||
|
||||
// STL-ish traverse iterators
|
||||
//! stl-ish traverse iterators
|
||||
auto begin()
|
||||
{
|
||||
return ziterator(this);
|
||||
}
|
||||
|
||||
//! stl-ish traverse iterators
|
||||
auto end()
|
||||
{
|
||||
return ziterator(nullptr);
|
||||
@@ -162,7 +172,7 @@ namespace znode
|
||||
// ... set_int
|
||||
// ... as_int
|
||||
|
||||
//zweak_node parent()
|
||||
//! erzeugt einen shared_ptr
|
||||
zshared_node parent() const
|
||||
{
|
||||
return _parent.lock();
|
||||
@@ -221,21 +231,29 @@ namespace znode
|
||||
return int(children().size() - 1);
|
||||
}
|
||||
|
||||
//! fügt einen knoten in meine kinderliste ein und macht mich
|
||||
//! zu dessen elternknoten.
|
||||
int add_child_at( int idx, const zshared_node& node )
|
||||
{
|
||||
// _fixme! was ist, wenn da schon ein elternknoten ist?
|
||||
|
||||
_children.insert(children().begin() + idx, node );
|
||||
node->_parent = this->shared_from_this();
|
||||
return int(children().size() - 1);
|
||||
}
|
||||
|
||||
//! fügt einen shard_ptr von 'mir' in die kinderliste meines elternknotens ein.
|
||||
void add_me_at( int offset )
|
||||
{
|
||||
if( parent() )
|
||||
parent()->add_child_at( offset, this->shared_from_this() );
|
||||
else
|
||||
qDebug() << " -- fick2"; // shold throw?
|
||||
throw std::runtime_error("add_me_at(offset): no parent node");
|
||||
|
||||
}
|
||||
|
||||
//! fügt einen shard_ptr von 'mir' in die kinderliste des übergebenen knotens ein
|
||||
//! und macht diesen zu meinem elternknoten.
|
||||
void add_me_at( int offset, const zshared_node& parent_node )
|
||||
{
|
||||
if( parent_node )
|
||||
@@ -244,7 +262,10 @@ namespace znode
|
||||
parent_node->add_child_at( offset, this->shared_from_this() );
|
||||
}
|
||||
else
|
||||
qDebug() << " -- fick4"; // shold throw?
|
||||
{
|
||||
throw std::runtime_error("add_me_at(offset,parent): no parent node");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
int own_pos()
|
||||
@@ -278,14 +299,17 @@ namespace znode
|
||||
return removed;
|
||||
}
|
||||
|
||||
//! entfernt 'mich' aus der kinderliste des elternknotens.
|
||||
void unlink_self()
|
||||
{
|
||||
if(parent())
|
||||
parent()->unlink_child( this->shared_from_this() );
|
||||
else
|
||||
qDebug() << " -- fuck: ";
|
||||
throw std::runtime_error("unlink_self(): no parent node");
|
||||
}
|
||||
|
||||
//! findet den ersten kind-knoten mit dem attribut 'attrkey' welches den
|
||||
//! wert 'attrvalue' hat.
|
||||
zshared_node find_child_by_attribute(str_cref attrkey, str_cref attrvalue )
|
||||
{
|
||||
for( auto child : _children )
|
||||
@@ -297,7 +321,7 @@ namespace znode
|
||||
return zshared_node();
|
||||
}
|
||||
|
||||
|
||||
//
|
||||
zshared_node find_child_by_tag_name(str_cref tagname )
|
||||
{
|
||||
for( auto child : _children )
|
||||
|
Reference in New Issue
Block a user