Brunot
Loading...
Searching...
No Matches
PathNode.h
Go to the documentation of this file.
1
12// ____ __ __ __
13// /\__ _\/\ \ /\ \/\ \
14// \/_/\ \/\ \ \___ __ \ \ \_\ \ ___ __ __ ____ __
15// \ \ \ \ \ _ `\ /'__`\ \ \ _ \ / __`\/\ \/\ \ /',__\ /'__`\
16// \ \ \ \ \ \ \ \/\ __/ \ \ \ \ \/\ \L\ \ \ \_\ \/\__, `\/\ __/
17// \ \_\ \ \_\ \_\ \____\ \ \_\ \_\ \____/\ \____/\/\____/\ \____\
18// \/_/ \/_/\/_/\/____/ \/_/\/_/\/___/ \/___/ \/___/ \/____/
19
20
21#pragma once
22#include <memory>
23#include <string>
24#include <vector>
25
26
27class GameObject;
28
29namespace gobj
30{
31
32
36struct PathNode : public std::enable_shared_from_this<PathNode>
37{
38 friend GameObject;
39
40
45 {
46 public:
52 path_iterator(GameObject* ptr, std::weak_ptr<PathNode> parent);
53
58 path_iterator() = default;
59
60 // Makes path_iterator stl compliant
61 using difference_type = std::ptrdiff_t;
63
64 // standard iterator functions
65 auto get() const -> GameObject*;
66 auto operator++() -> path_iterator&;
67 auto operator++(int) -> path_iterator;
68 auto operator==(const path_iterator& other) const -> bool;
69 auto operator*() const -> std::add_lvalue_reference_t<GameObject>;
70 auto operator->() const -> GameObject*;
71
72 private:
74 GameObject* data = nullptr;
76 std::weak_ptr<PathNode> pathNode = {};
77 };
78
79 // ensure we are stl compliant
80 static_assert(std::input_iterator<path_iterator>);
81 static_assert(std::sentinel_for<path_iterator, path_iterator>);
82
83protected:
88 [[nodiscard]] auto getBegin() const -> path_iterator;
93 auto setBegin(const path_iterator& begin) -> void;
98 [[nodiscard]] auto getEnd() const -> path_iterator;
103 auto setEnd(const path_iterator& end) -> void;
104
105
110 static auto isNamed(const GameObject& obj, const std::string& name) -> bool;
111
112public:
113 virtual ~PathNode() = default;
114
119 virtual auto begin() -> path_iterator = 0;
124 virtual auto end() -> path_iterator = 0;
136
145
152 virtual auto getNext(GameObject* ptr) -> GameObject* = 0;
153
158 auto appendPathNode(std::shared_ptr<PathNode> nextPath) -> void;
159
160 // static functions
166 static auto getChildren(const GameObject& gobj) -> std::shared_ptr<std::vector<GameObject*>>;
167
168private:
173
174protected:
176 std::shared_ptr<PathNode> next;
177
178};
179
180}
the base class for the engine, most things inherit from this.
Definition GameObject.h:77
iterator type, refers to a GameObject, and holds onto a reference to a PathNode to determine its rang...
Definition PathNode.h:45
path_iterator(GameObject *ptr, std::weak_ptr< PathNode > parent)
Constructor for path_iterator that initializes it pointing to a range of data.
Definition PathNode.cpp:26
path_iterator()=default
Default constructor for path_iterator that initializes it as a sentinel iterator, or a past the end i...
std::ptrdiff_t difference_type
Definition PathNode.h:61
std::weak_ptr< PathNode > pathNode
reference to parent PathNode, which path_iterator uses to determine it's range
Definition PathNode.h:76
GameObject value_type
Definition PathNode.h:62
GameObject * data
Pointer to a GameObject, which path_iterator is currently pointing to.
Definition PathNode.h:74
auto get() const -> GameObject *
Definition PathNode.cpp:32
namespace for things relating to GameObject, other than GameObject itself
Definition Entity.h:229
internal type for computing Paths
Definition PathNode.h:37
auto setEnd(const path_iterator &end) -> void
function to set the cached end of our parent ( or left ) range
Definition PathNode.cpp:89
virtual auto end() -> path_iterator=0
path_iterator end_
Cached past the end iterator of parent ( left ) range.
Definition PathNode.h:172
virtual auto getNext(GameObject *ptr) -> GameObject *=0
Used by PathNode::path_iterator to increment.
auto getEnd() const -> path_iterator
function to get the cached beginning of our parent ( or left ) range
Definition PathNode.cpp:84
auto getBegin() const -> path_iterator
function to get the cached beginning of our parent ( or left ) range
Definition PathNode.cpp:74
auto setBegin(const path_iterator &begin) -> void
function to set the cached beginning of our parent ( or left ) range
Definition PathNode.cpp:79
static auto isNamed(const GameObject &obj, const std::string &name) -> bool
helper function that checks nickname, and then typename if nickname doesn't match used by PathName
Definition PathNode.cpp:116
friend GameObject
Definition PathNode.h:38
auto appendPathNode(std::shared_ptr< PathNode > nextPath) -> void
adds a path to the end of the linked list of paths
Definition PathNode.cpp:94
path_iterator begin_
Caches beginning of parent (left) range.
Definition PathNode.h:170
static auto getChildren(const GameObject &gobj) -> std::shared_ptr< std::vector< GameObject * > >
helper function to get children of GameObjects as a vector of pointers
Definition PathNode.cpp:111
virtual auto begin() -> path_iterator=0
std::shared_ptr< PathNode > next
next Path Node in linked list. Represents the next (right) range
Definition PathNode.h:176