IGSTK
igstkObject.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Image Guided Surgery Software Toolkit
4  Module: $RCSfile: igstkObject.h,v $
5  Language: C++
6  Date: $Date: 2011-01-18 21:40:17 $
7  Version: $Revision: 1.9 $
8 
9  Copyright (c) ISC Insight Software Consortium. All rights reserved.
10  See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __igstkObject_h
18 #define __igstkObject_h
19 
20 
21 #include "itkObject.h"
22 #include "itkLogger.h"
23 
24 #include "igstkLogger.h"
25 #include "igstkMacros.h"
26 
27 
28 namespace igstk
29 {
40 class Object : public ::itk::Object
41 {
42 
43 public:
44 
48  typedef Object Self;
49  typedef ::itk::Object Superclass;
50  typedef ::itk::SmartPointer< Self > Pointer;
51  typedef ::itk::SmartPointer< const Self > ConstPointer;
52 
53  igstkTypeMacro( Object, ::itk::Object );
55 
56  typedef igstk::Logger LoggerType;
57 
59  void SetLogger( LoggerType * logger );
60 
61  void RemoveObserver(unsigned long tag) const;
62 
63 protected:
64 
65  LoggerType * GetLogger() const;
66 
67 
68 protected:
69 
72  Object(void);
73 
74  virtual ~Object(void);
75 
77  virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const;
78 
82  const ::igstk::Object * object, unsigned long tag );
83 
86 
87 private:
88 
89  typedef ::igstk::Object ObservedObjectType;
90  typedef std::pair< const ObservedObjectType *,
91  unsigned long> ObservedObjectTagPair;
92  typedef std::list< ObservedObjectTagPair > ObservedObjectPairContainer;
93  typedef ::itk::MemberCommand< Self > DeleteEventCommandType;
94  typedef ::itk::EventObject EventType;
95 
96  mutable LoggerType::Pointer m_Logger;
97  ObservedObjectPairContainer m_ObservedObjectPairContainer;
98  DeleteEventCommandType::Pointer m_ObservedObjectDeleteReceptor;
99 
105  void ObservedObjectDeleteProcessing(const itk::Object* caller,
106  const EventType& event );
107 
108  // Put this here so we can share typedefs.
109  class ObservedObjectTagPairObjectMatchPredicate
110  {
111  public:
112  ObservedObjectTagPairObjectMatchPredicate( const itk::Object* obj )
113  : m_TargetObject( obj )
114  {
115  }
116 
117  bool operator()( const igstk::Object::ObservedObjectTagPair& objTagPair )
118  {
119  if (objTagPair.first == m_TargetObject)
120  {
121  return true;
122  }
123  else
124  {
125  return false;
126  }
127  }
128 
129  private:
130  const itk::Object* m_TargetObject;
131  };
132 
133 };
134 
135 } // end of namespace igstk
136 
137 #endif //__igstk_Object_h_
#define igstkTypeMacro(thisClass, superclass)
Type Macro defines the GetNameOfClass() method for every class where it is invoked.
Definition: igstkMacros.h:128
Object(void)
Constructor is protected in order to enforce the use of the New() operator.
void RemoveObserver(unsigned long tag) const
virtual void PrintSelf(std::ostream &os, itk::Indent indent) const
Print the object information.
Base class for all the IGSTK classes.
Definition: igstkObject.h:40
::itk::SmartPointer< Self > Pointer
Definition: igstkLogger.h:42
Object Self
General Typedefs.
Definition: igstkObject.h:48
void RemoveFromObservedObjects()
Remove observers that this object may have connected to other objects.
defines standard system-wide macros, constants, and other common parameters in the IGSTK Library...
#define igstkNewMacro(x)
New Macro creates a new object of a class that is using SmartPointers.
Definition: igstkMacros.h:115
void SetLogger(LoggerType *logger)
Connect the Logger for this class.
::itk::SmartPointer< Self > Pointer
Definition: igstkObject.h:50
virtual ~Object(void)
::itk::Object Superclass
Definition: igstkObject.h:49
igstk::Logger LoggerType
Definition: igstkObject.h:54
::itk::SmartPointer< const Self > ConstPointer
Definition: igstkObject.h:51
LoggerType * GetLogger() const
Class used for handling logging tasks.
Definition: igstkLogger.h:36
void RegisterObservedObject(const ::igstk::Object *object, unsigned long tag)
Register observed objects in an internal array so that they can be disconnected upon destruction...