| 1 | #ifndef SEAD_TREENODE_H_ |
| 2 | #define SEAD_TREENODE_H_ |
| 3 | |
| 4 | #include <basis/seadTypes.h> |
| 5 | |
| 6 | namespace sead |
| 7 | { |
| 8 | class TreeNode |
| 9 | { |
| 10 | public: |
| 11 | TreeNode(); |
| 12 | |
| 13 | void clearLinks(); |
| 14 | s32 countChildren() const; |
| 15 | void detachAll(); |
| 16 | void detachSubTree(); |
| 17 | TreeNode* findRoot(); |
| 18 | const TreeNode* findRoot() const; |
| 19 | void insertAfterSelf(TreeNode* node); |
| 20 | void insertBeforeSelf(TreeNode* node); |
| 21 | void pushBackChild(TreeNode* node); |
| 22 | void pushBackSibling(TreeNode* node); |
| 23 | void pushFrontChild(TreeNode* node); |
| 24 | |
| 25 | protected: |
| 26 | void clearChildLinksRecursively_(); |
| 27 | |
| 28 | TreeNode* mParent; |
| 29 | TreeNode* mChild; |
| 30 | TreeNode* mNext; |
| 31 | TreeNode* mPrev; |
| 32 | }; |
| 33 | |
| 34 | template <typename T> |
| 35 | class TTreeNode : public TreeNode |
| 36 | { |
| 37 | public: |
| 38 | TTreeNode() = default; |
| 39 | explicit TTreeNode(T data) : mData(data) {} |
| 40 | |
| 41 | T& value() { return mData; } |
| 42 | const T& value() const { return mData; } |
| 43 | |
| 44 | TTreeNode* parent() const { return static_cast<TTreeNode*>(mParent); } |
| 45 | TTreeNode* child() const { return static_cast<TTreeNode*>(mChild); } |
| 46 | TTreeNode* next() const { return static_cast<TTreeNode*>(mNext); } |
| 47 | TTreeNode* prev() const { return static_cast<TTreeNode*>(mPrev); } |
| 48 | TTreeNode* findRoot() { return static_cast<TTreeNode*>(TreeNode::findRoot()); } |
| 49 | const TTreeNode* findRoot() const { return static_cast<TTreeNode*>(TreeNode::findRoot()); } |
| 50 | void insertAfterSelf(TTreeNode* node) { TreeNode::insertAfterSelf(node); } |
| 51 | void insertBeforeSelf(TTreeNode* node) { TreeNode::insertBeforeSelf(node); } |
| 52 | void pushBackChild(TTreeNode* node) { TreeNode::pushBackChild(node); } |
| 53 | void pushBackSibling(TTreeNode* node) { TreeNode::pushBackSibling(node); } |
| 54 | void pushFrontChild(TTreeNode* node) { TreeNode::pushFrontChild(node); } |
| 55 | |
| 56 | // TODO: probably iterators |
| 57 | |
| 58 | protected: |
| 59 | T mData; |
| 60 | }; |
| 61 | |
| 62 | } // namespace sead |
| 63 | |
| 64 | #endif // SEAD_TREENODE_H_ |
| 65 | |