Public Types | Public Member Functions | Protected Member Functions | Protected Attributes

mitk::ReferenceCountWatcher Class Reference

Keeps track of the reference count of an object even if it is destroyed. More...

#include <mitkReferenceCountWatcher.h>

List of all members.

Public Types

typedef
itk::SimpleMemberCommand
< ReferenceCountWatcher
CommandType

Public Member Functions

 mitkClassMacro (ReferenceCountWatcher, itk::Object)
 ReferenceCountWatcher (itk::Object *o, const char *comment="")
 Constructor requiring object to be watched and allowing an optional comment.
 ~ReferenceCountWatcher ()
 Destructor: remove observer.
int GetReferenceCount () const
 Return the reference count of the watched object or 0 if it has been destroyed.
virtual const char * GetComment () const
 Return the optional string comment.

Protected Member Functions

void DeleteObserver ()
 Callback called on itk::DeleteEvent() of wathched object.

Protected Attributes

itk::Object * m_Object
 Object to be watched.
std::string m_Comment
 Optional comment, e.g. for debugging output.
bool m_Deleted
 If true, m_Object is no longer valid and the returned reference count will be 0.
CommandType::Pointer m_DeleteCommand
 itk::Command to get a notification when the object is deleted.
unsigned long m_ObserverTag

Detailed Description

Keeps track of the reference count of an object even if it is destroyed.

Example usage:

//##   SomeFilter* filter = GetSomeFilter();
//##   ReferenceCountWatcher::Pointer filterWatcher;
//##   filterWatcher = new ReferenceCountWatcher(filter, "name of filter");
//##   filterWatcher->GetReferenceCount();
//## 

Definition at line 35 of file mitkReferenceCountWatcher.h.


Member Typedef Documentation

Definition at line 38 of file mitkReferenceCountWatcher.h.


Constructor & Destructor Documentation

mitk::ReferenceCountWatcher::ReferenceCountWatcher ( itk::Object *  o,
const char *  comment = "" 
) [inline]

Constructor requiring object to be watched and allowing an optional comment.

Definition at line 65 of file mitkReferenceCountWatcher.h.

References DeleteObserver(), m_DeleteCommand, m_Object, and m_ObserverTag.

                                                              : m_Object(o), m_Comment(comment), m_Deleted(false), m_ObserverTag(0)
  {
    m_DeleteCommand = CommandType::New();
    m_DeleteCommand->SetCallbackFunction(this, &ReferenceCountWatcher::DeleteObserver);
    if(m_Object!=NULL)
      m_ObserverTag = m_Object->AddObserver(itk::DeleteEvent(), m_DeleteCommand);
    m_ReferenceCountLock.Lock();
    m_ReferenceCount = 0;
    m_ReferenceCountLock.Unlock();
  }
mitk::ReferenceCountWatcher::~ReferenceCountWatcher (  ) [inline]

Destructor: remove observer.

Definition at line 77 of file mitkReferenceCountWatcher.h.

References m_Deleted, m_Object, and m_ObserverTag.

  {
    if((m_Deleted == false) && (m_Object != NULL))
    {
      m_Object->RemoveObserver(m_ObserverTag);
    }
  }

Member Function Documentation

void mitk::ReferenceCountWatcher::DeleteObserver (  ) [inline, protected]

Callback called on itk::DeleteEvent() of wathched object.

Definition at line 100 of file mitkReferenceCountWatcher.h.

References m_Deleted.

Referenced by ReferenceCountWatcher().

  {
    m_Deleted = true;
  }
virtual const char* mitk::ReferenceCountWatcher::GetComment (  ) const [virtual]

Return the optional string comment.

int mitk::ReferenceCountWatcher::GetReferenceCount (  ) const [inline]

Return the reference count of the watched object or 0 if it has been destroyed.

Definition at line 87 of file mitkReferenceCountWatcher.h.

References m_Deleted, and m_Object.

  {
    if(m_Object == NULL) return -1;
    if(m_Deleted) return 0;
    return m_Object->GetReferenceCount();
  }
mitk::ReferenceCountWatcher::mitkClassMacro ( ReferenceCountWatcher  ,
itk::Object   
)

Member Data Documentation

std::string mitk::ReferenceCountWatcher::m_Comment [protected]

Optional comment, e.g. for debugging output.

Definition at line 49 of file mitkReferenceCountWatcher.h.

CommandType::Pointer mitk::ReferenceCountWatcher::m_DeleteCommand [protected]

itk::Command to get a notification when the object is deleted.

Definition at line 59 of file mitkReferenceCountWatcher.h.

Referenced by ReferenceCountWatcher().

If true, m_Object is no longer valid and the returned reference count will be 0.

Definition at line 54 of file mitkReferenceCountWatcher.h.

Referenced by DeleteObserver(), GetReferenceCount(), and ~ReferenceCountWatcher().

itk::Object* mitk::ReferenceCountWatcher::m_Object [protected]

Object to be watched.

Definition at line 45 of file mitkReferenceCountWatcher.h.

Referenced by GetReferenceCount(), ReferenceCountWatcher(), and ~ReferenceCountWatcher().

unsigned long mitk::ReferenceCountWatcher::m_ObserverTag [protected]

Definition at line 104 of file mitkReferenceCountWatcher.h.

Referenced by ReferenceCountWatcher(), and ~ReferenceCountWatcher().


The documentation for this class was generated from the following file:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines