13 #include "itkCommand.h" 34 typedef itk::SimpleMemberCommand<ReferenceCountWatcher>
CommandType;
62 : m_Object(o), m_Comment(comment), m_Deleted(false),
m_ObserverTag(0)
64 m_DeleteCommand = CommandType::New();
66 if (m_Object !=
nullptr)
67 m_ObserverTag = m_Object->AddObserver(itk::DeleteEvent(), m_DeleteCommand);
74 if ((m_Deleted ==
false) && (m_Object !=
nullptr))
84 if (m_Object ==
nullptr)
88 return m_Object->GetReferenceCount();
93 itkGetStringMacro(Comment);
itk::Object * m_Object
Object to be watched.
~ReferenceCountWatcher() override
Destructor: remove observer.
DataCollection - Class to facilitate loading/accessing structured data.
unsigned long m_ObserverTag
bool m_Deleted
If true, m_Object is no longer valid and the returned reference count will be 0.
std::string m_Comment
Optional comment, e.g. for debugging output.
itk::SimpleMemberCommand< ReferenceCountWatcher > CommandType
ReferenceCountWatcher(itk::Object *o, const char *comment="")
Constructor requiring object to be watched and allowing an optional comment.
Keeps track of the reference count of an object even if it is destroyed.
#define mitkClassMacroItkParent(className, SuperClassName)
int GetReferenceCount() const override
Return the reference count of the watched object or 0 if it has been destroyed.
void DeleteObserver()
Callback called on itk::DeleteEvent() of wathched object.
CommandType::Pointer m_DeleteCommand
itk::Command to get a notification when the object is deleted.