diff --git a/src/observersmanager.hpp b/src/observersmanager.hpp index b5340ef..db59f0b 100644 --- a/src/observersmanager.hpp +++ b/src/observersmanager.hpp @@ -28,6 +28,14 @@ #include #include +#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(NDEBUG) +# define OBS_MANAGER_LOG +#endif + +#if defined(OBS_MANAGER_LOG) +# include +#endif + namespace cloonel { template class ObserversManager { @@ -61,7 +69,7 @@ namespace cloonel { typedef boost::transform_iterator, TreeIteratorType> iterator; ObserversManager ( void ); - ~ObserversManager ( void ) noexcept = default; + ~ObserversManager ( void ) noexcept; TicketType Add ( T parObserver, TicketType parParent=Ticket_Null ); void Remove ( TicketType parTicket ) noexcept; @@ -85,6 +93,13 @@ namespace cloonel { { } + ///-------------------------------------------------------------------------- + ///-------------------------------------------------------------------------- + template + ObserversManager::~ObserversManager() noexcept { + assert(m_tree.empty()); + } + ///-------------------------------------------------------------------------- ///-------------------------------------------------------------------------- template @@ -95,6 +110,9 @@ namespace cloonel { else m_tree.append_child(GetByTicket_AssertPresent(parParent), TicketedWrapper(parObserver, currTicket)); +#if defined(OBS_MANAGER_LOG) + std::cout << __PRETTY_FUNCTION__ << " registering " << currTicket << " as a child of " << parParent << "\n"; +#endif ++m_nextTicket; return currTicket; } @@ -104,6 +122,11 @@ namespace cloonel { template void ObserversManager::Remove (TicketType parTicket) noexcept { auto deleme = GetByTicket_AssertPresent(parTicket); +#if defined(OBS_MANAGER_LOG) + for (auto it(deleme); it != m_tree.end(); ++it) { + std::cout << __PRETTY_FUNCTION__ << " unregistering " << it->ticket << "\n"; + } +#endif m_tree.erase(deleme); if (parTicket == m_nextTicket - 1) --m_nextTicket; @@ -126,4 +149,7 @@ namespace cloonel { } } //namespace cloonel +#if defined(OBS_MANAGER_LOG) +# undef OBS_MANAGER_LOG +#endif #endif