has_tree.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* node_tree/has_tree.h - HasTree
  2. * Copyright (C) 2018 caryoscelus
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #ifndef CORE_NODE_TREE_HAS_TREE_H_8C08C191_BA54_5670_B7B1_7199099FB694
  18. #define CORE_NODE_TREE_HAS_TREE_H_8C08C191_BA54_5670_B7B1_7199099FB694
  19. #include <core/std/memory.h>
  20. #include <core/util/nullptr.h>
  21. #include "path.h"
  22. namespace rainynite::core {
  23. class NodeTree;
  24. /**
  25. * NodeTree (weak) holder
  26. */
  27. class HasTree {
  28. public:
  29. /// Pointer to node tree that we use to store tree
  30. using TreePtr = weak_ptr<NodeTree>;
  31. using Index = NodeTree::Index;
  32. HasTree(TreePtr tree_) :
  33. m_tree(tree_)
  34. {}
  35. protected:
  36. shared_ptr<NodeTree> tree() const {
  37. return no_null(m_tree.lock());
  38. }
  39. Index path_to_index(NodeTreePath const& path) const {
  40. return tree_path_to_index(*tree(), path);
  41. }
  42. private:
  43. TreePtr m_tree;
  44. };
  45. } // namespace rainynite::core
  46. #endif