87 std::vector<tgObserver<T> * > m_observers;
90 template <
typename Subject>
93 if (pObserver) { m_observers.push_back(pObserver);
94 pObserver->
onAttach(static_cast<Subject&>(*
this));}
97 template <
typename Subject>
102 const std::size_t n = m_observers.size();
103 for (std::size_t i = 0; i < n; ++i)
106 if (pObserver) { pObserver->
onStep(static_cast<Subject&>(*
this), dt); }
111 template <
typename Subject>
114 const std::size_t n = m_observers.size();
115 for (std::size_t i = 0; i < n; ++i)
118 if (pObserver) { pObserver->
onSetup(static_cast<Subject&>(*
this)); }
122 template <
typename Subject>
125 const std::size_t n = m_observers.size();
126 for (std::size_t i = 0; i < n; ++i)
129 if (pObserver) { pObserver->
onTeardown(static_cast<Subject&>(*
this)); }
132 #endif // TG_SUBJECT_H
Definition of tgObserver class.
virtual void onStep(Subject &subject, double dt)=0
virtual void onTeardown(Subject &subject)
virtual void onSetup(Subject &subject)
virtual void onAttach(Subject &subject)
void attach(tgObserver< T > *pObserver)
void notifyStep(double dt)