@@ -57,82 +57,6 @@ using GameNode = GameObjectPtr<GameNodeRep>;
5757class GameRep ;
5858using Game = std::shared_ptr<GameRep>;
5959
60- template <class P , class T > class ElementCollection {
61- P m_owner{nullptr };
62- const std::vector<T *> *m_container{nullptr };
63-
64- public:
65- class iterator {
66- P m_owner{nullptr };
67- const std::vector<T *> *m_container{nullptr };
68- size_t m_index{0 };
69-
70- public:
71- using iterator_category = std::bidirectional_iterator_tag;
72- using difference_type = std::ptrdiff_t ;
73- using value_type = GameObjectPtr<T>;
74- using pointer = value_type *;
75- using reference = value_type &;
76-
77- iterator () = default ;
78- iterator (const P &p_owner, const std::vector<T *> *p_container, size_t p_index = 0 )
79- : m_owner(p_owner), m_container(p_container), m_index(p_index)
80- {
81- }
82- iterator (const iterator &) = default ;
83- ~iterator () = default ;
84- iterator &operator =(const iterator &) = default ;
85-
86- bool operator ==(const iterator &p_iter) const
87- {
88- return m_owner == p_iter.m_owner && m_container == p_iter.m_container &&
89- m_index == p_iter.m_index ;
90- }
91- bool operator !=(const iterator &p_iter) const
92- {
93- return m_owner != p_iter.m_owner || m_container != p_iter.m_container ||
94- m_index != p_iter.m_index ;
95- }
96-
97- iterator &operator ++()
98- {
99- m_index++;
100- return *this ;
101- }
102- iterator &operator --()
103- {
104- m_index--;
105- return *this ;
106- }
107- value_type operator *() const { return m_container->at (m_index); }
108- const P &GetOwner () const { return m_owner; }
109- };
110-
111- ElementCollection () = default ;
112- explicit ElementCollection (const P &p_owner, const std::vector<T *> *p_container)
113- : m_owner(p_owner), m_container(p_container)
114- {
115- }
116- ElementCollection (const ElementCollection<P, T> &) = default ;
117- ~ElementCollection () = default ;
118- ElementCollection &operator =(const ElementCollection<P, T> &) = default ;
119-
120- bool operator ==(const ElementCollection<P, T> &p_other) const
121- {
122- return m_owner == p_other.m_owner && m_container == p_other.m_container ;
123- }
124-
125- bool empty () const { return m_container->empty (); }
126- size_t size () const { return m_container->size (); }
127- GameObjectPtr<T> front () const { return m_container->front (); }
128- GameObjectPtr<T> back () const { return m_container->back (); }
129-
130- iterator begin () const { return {m_owner, m_container, 0 }; }
131- iterator end () const { return {m_owner, m_container, (m_owner) ? m_container->size () : 0 }; }
132- iterator cbegin () const { return {m_owner, m_container, 0 }; }
133- iterator cend () const { return {m_owner, m_container, (m_owner) ? m_container->size () : 0 }; }
134- };
135-
13660//
13761// Forward declarations of classes defined elsewhere.
13862//
@@ -491,17 +415,23 @@ class GameNodeRep : public std::enable_shared_from_this<GameNodeRep> {
491415 // / @brief A range class for iterating over a node's (action, child) pairs.
492416 class Actions {
493417 private:
494- GameNode m_owner{nullptr };
418+ const GameNodeRep * m_owner{nullptr };
495419
496420 public:
497421 class iterator ;
498422
499- Actions (const GameNode p_owner);
423+ Actions (const GameNodeRep * p_owner);
500424
501425 iterator begin () const ;
502426 iterator end () const ;
503427 };
504428
429+ GameNodeRep (GameRep *e, GameNodeRep *p);
430+ ~GameNodeRep ();
431+
432+ bool IsValid () const { return m_valid; }
433+ void Invalidate () { m_valid = false ; }
434+
505435 // / @brief Returns a collection for iterating over this node's (action, child) pairs.
506436 Actions GetActions () const ;
507437
@@ -601,9 +531,9 @@ class GameNodeRep::Actions::iterator {
601531 GameNode GetOwner () const ;
602532};
603533
604- inline GameNodeRep::Actions::Actions (GameNode p_owner) : m_owner(p_owner) {}
534+ inline GameNodeRep::Actions::Actions (const GameNodeRep * p_owner) : m_owner(p_owner) {}
605535
606- inline GameNodeRep::Actions GameNodeRep::GetActions () const { return Actions (this ); }
536+ inline GameNodeRep::Actions GameNodeRep::GetActions () const { return { Actions (this )} ; }
607537
608538inline GameNodeRep::Actions::iterator GameNodeRep::Actions::begin () const
609539{
0 commit comments