/*************************************************************************** source::worx xtree Copyright © 2024-2025 c.holzheuer christoph.holzheuer@gmail.com This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. ***************************************************************************/ #ifndef XQNODE_H #define XQNODE_H #include #include #include #include #include #include #include #include #include // Overload the operator<< for QString and std::ostream std::ostream& operator<<(std::ostream& os, const QString& obj); // raw node using XQNode = znode::zbasic_node; // default shared node using XQNodePtr = std::shared_ptr>; // const ref on XQNodePtr, ok but what its good for? //using const XQNodePtr& = const XQNodePtr&; /* class XQBasicSheetNode : public znode::zbasic_node { public: //... }; using XQSheetNode = std::shared_ptr; using XQSheetNodeCRef = const XQSheetNode&; */ /// /// __fix /// sollte man einen XQNodePtr einführen, um 'setAttr()' von /// setAttr() unterscheiden zu können? /// /// nice try. (siehe oben). Haut aber so nicht hin, node.children() gibt wieder /// Pointer auf die Basisklasse zurück, ( vgl. XQItemList -> QList. /// Erst dass behandeln! /// // weak pointer to znode, used for parent() using XQWeakNode = std::weak_ptr>; // the node factory using XQNodeFactory = znode::znode_factory; class XQNodeList : public znode::zbasic_node::znode_list { friend class XQSimpleClipBoard; public: XQNodeList() = default; virtual ~XQNodeList() = default; }; class XNodeIterator { public: using iterator_category = std::forward_iterator_tag; using value_type = XQNode; using difference_type = std::ptrdiff_t; using pointer = XQNode*; using reference = XQNode&; XNodeIterator() = default; XNodeIterator(XQNodePtr root) { if (root) { _stack.push(root); } } reference operator*() const { return *_stack.top(); } pointer operator->() const { return _stack.top().get(); } XNodeIterator& operator++() { auto node = _stack.top(); _stack.pop(); for (auto it = node->children().rbegin(); it != node->children().rend(); ++it) { _stack.push(*it); } return *this; } XNodeIterator operator++(int) { XNodeIterator tmp = *this; ++(*this); return tmp; } bool operator==(const XNodeIterator& other) const { return _stack == other._stack; } bool operator!=(const XNodeIterator& other) const { return !(*this == other); } private: std::stack _stack; }; // Define the tree class with begin and end methods class XTree { public: XTree(XQNodePtr root) : _root(root) {} XNodeIterator begin() { return XNodeIterator(_root); } XNodeIterator end() { return XNodeIterator(); } private: XQNodePtr _root; }; //void inspect( XQNodePtr node, int offSet=0 ); void inspect( const XQNodePtr& node, int indent=0 ); Q_DECLARE_METATYPE(XQNodePtr); #endif // XQNODE_H