Assertion that the ObserverManager is empty when it's destroyed and verbosity.
This commit is contained in:
parent
9c660caec6
commit
3f79507beb
1 changed files with 27 additions and 1 deletions
|
@ -28,6 +28,14 @@
|
|||
#include <tree.hh>
|
||||
#include <boost/iterator/transform_iterator.hpp>
|
||||
|
||||
#if defined(__GNUC__) && __GNUC__ >= 2 && !defined(NDEBUG)
|
||||
# define OBS_MANAGER_LOG
|
||||
#endif
|
||||
|
||||
#if defined(OBS_MANAGER_LOG)
|
||||
# include <iostream>
|
||||
#endif
|
||||
|
||||
namespace cloonel {
|
||||
template <typename T>
|
||||
class ObserversManager {
|
||||
|
@ -61,7 +69,7 @@ namespace cloonel {
|
|||
typedef boost::transform_iterator<std::function<T&(TicketedWrapper&)>, 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 <typename T>
|
||||
ObserversManager<T>::~ObserversManager() noexcept {
|
||||
assert(m_tree.empty());
|
||||
}
|
||||
|
||||
///--------------------------------------------------------------------------
|
||||
///--------------------------------------------------------------------------
|
||||
template <typename T>
|
||||
|
@ -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 <typename T>
|
||||
void ObserversManager<T>::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
|
||||
|
|
Loading…
Reference in a new issue