diff --git a/src/movers/mover.cpp b/src/movers/mover.cpp index c4a7875..234ddfc 100644 --- a/src/movers/mover.cpp +++ b/src/movers/mover.cpp @@ -22,6 +22,12 @@ #include namespace cloonel { + ///-------------------------------------------------------------------------- + ///-------------------------------------------------------------------------- + Mover::~Mover() noexcept { + m_placeables.RemoveAll(); + } + ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- void Mover::Update (float parDelta) { diff --git a/src/movers/mover.hpp b/src/movers/mover.hpp index 7da8776..e0e6a63 100644 --- a/src/movers/mover.hpp +++ b/src/movers/mover.hpp @@ -35,7 +35,7 @@ namespace cloonel { }; Mover ( void ) = default; - virtual ~Mover ( void ) noexcept = default; + virtual ~Mover ( void ) noexcept; virtual void Update ( float parDelta ); PlaceableTicketType RegisterPlaceable ( Placeable* parPlaceable, PlaceableTicketType parParent=ObserversManager::Ticket_Null ); diff --git a/src/observersmanager.hpp b/src/observersmanager.hpp index 59c1c54..3d1c865 100644 --- a/src/observersmanager.hpp +++ b/src/observersmanager.hpp @@ -73,6 +73,7 @@ namespace cloonel { TicketType Add ( T parObserver, TicketType parParent=Ticket_Null ); void Remove ( TicketType parTicket ) noexcept; + void RemoveAll ( void ) noexcept; void Update ( TicketType parTicket, T parObserver ); std::size_t size ( void ) const { return m_tree.size(); } iterator begin ( void ) { return iterator(m_tree.begin(), &TicketedWrapperToItm); } @@ -132,6 +133,19 @@ namespace cloonel { --m_nextTicket; } + ///-------------------------------------------------------------------------- + ///-------------------------------------------------------------------------- + template + void ObserversManager::RemoveAll() noexcept { + if (not m_tree.empty()) { + for (typename TreeType::sibling_iterator it(m_tree.begin()), itEND(m_tree.end()); it != itEND; ++it) { + const TicketType ticket = it->ticket; + this->Remove(ticket); + } + assert(m_tree.empty()); + } + } + ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template