Simulant  21.12-194
A portable game engine for Windows, OSX, Linux, Dreamcast, and PSP
tree_node.h
1 #pragma once
2 
3 #include <functional>
4 #include <cstdint>
5 #include <iterator>
6 
7 #include "../macros.h"
8 #include "../generic/check_signature.h"
9 
10 /* Basic tree node class with sibling and parent/child access */
11 
12 namespace smlt {
13 
14 template<bool>
15 class DescendentIterator;
16 
17 class TreeNode {
18  friend class DescendentIterator<false>;
19  friend class DescendentIterator<true>;
20 
21 public:
22  TreeNode();
23  virtual ~TreeNode();
24 
25  void set_parent(TreeNode* node);
26  void add_child(TreeNode* node);
27  void remove_from_parent();
28 
29  bool is_root() const { return !parent_; }
30  bool is_leaf() const { return first_child_ == nullptr; }
31  TreeNode* parent() const { return parent_; }
32 
33  uint32_t child_count() const;
34 
35  TreeNode* first_child() const { return first_child_; }
36  TreeNode* next_node() const { return next_; }
37  TreeNode* previous_node() const { return prev_; }
38 
39 protected:
40  TreeNode* root_ = nullptr;
41  TreeNode* parent_ = nullptr;
42  TreeNode* first_child_ = nullptr;
43 
44  TreeNode* prev_ = this;
45  TreeNode* next_ = this;
46 
47  TreeNode* detach(); //< Detach from all other nodes, return the first orphaned child (if any)
48  TreeNode* last_child() const;
49 
50  virtual void on_parent_set(TreeNode* oldp, TreeNode* newp) {
51  _S_UNUSED(oldp);
52  _S_UNUSED(newp);
53  }
54 };
55 
56 
57 }
smlt::DescendentIterator
Definition: descendent_iterator.h:11
smlt::TreeNode
Definition: tree_node.h:17
smlt
Definition: animation.cpp:25