IGSTK
|
00001 /*========================================================================= 00002 00003 Program: Image Guided Surgery Software Toolkit 00004 Module: $RCSfile: igstkObject.h,v $ 00005 Language: C++ 00006 Date: $Date: 2008-11-17 20:12:25 $ 00007 Version: $Revision: 1.8 $ 00008 00009 Copyright (c) ISC Insight Software Consortium. All rights reserved. 00010 See IGSTKCopyright.txt or http://www.igstk.org/copyright.htm for details. 00011 00012 This software is distributed WITHOUT ANY WARRANTY; without even 00013 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00014 PURPOSE. See the above copyright notices for more information. 00015 00016 =========================================================================*/ 00017 #ifndef __igstkObject_h 00018 #define __igstkObject_h 00019 00020 00021 #include "itkObject.h" 00022 #include "itkLogger.h" 00023 00024 #include "igstkLogger.h" 00025 #include "igstkMacros.h" 00026 00027 00028 namespace igstk 00029 { 00040 class Object : public ::itk::Object 00041 { 00042 00043 public: 00044 00048 typedef Object Self; 00049 typedef ::itk::Object Superclass; 00050 typedef ::itk::SmartPointer< Self > Pointer; 00051 typedef ::itk::SmartPointer< const Self > ConstPointer; 00052 00053 igstkTypeMacro( Object, ::itk::Object ); 00054 igstkNewMacro( Self ); 00055 00056 typedef igstk::Logger LoggerType; 00057 00059 void SetLogger( LoggerType * logger ); 00060 00061 void RemoveObserver(unsigned long tag) const; 00062 00063 protected: 00064 00065 LoggerType * GetLogger() const; 00066 00067 00068 protected: 00069 00072 Object(void); 00073 00074 virtual ~Object(void); 00075 00077 virtual void PrintSelf( std::ostream& os, itk::Indent indent ) const; 00078 00081 void RegisterObservedObject( 00082 const ::igstk::Object * object, unsigned long tag ); 00083 00085 void RemoveFromObservedObjects(); 00086 00087 private: 00088 00089 typedef ::igstk::Object ObservedObjectType; 00090 typedef std::pair< const ObservedObjectType *, 00091 unsigned long> ObservedObjectTagPair; 00092 typedef std::list< ObservedObjectTagPair > ObservedObjectPairContainer; 00093 typedef ::itk::MemberCommand< Self > DeleteEventCommandType; 00094 typedef ::itk::EventObject EventType; 00095 00096 mutable LoggerType::Pointer m_Logger; 00097 ObservedObjectPairContainer m_ObservedObjectPairContainer; 00098 DeleteEventCommandType::Pointer m_ObservedObjectDeleteReceptor; 00099 00105 void ObservedObjectDeleteProcessing(const itk::Object* caller, 00106 const EventType& event ); 00107 00108 // Put this here so we can share typedefs. 00109 class ObservedObjectTagPairObjectMatchPredicate 00110 { 00111 public: 00112 ObservedObjectTagPairObjectMatchPredicate( const itk::Object* obj ) 00113 : m_TargetObject( obj ) 00114 { 00115 } 00116 00117 bool operator()( const igstk::Object::ObservedObjectTagPair& objTagPair ) 00118 { 00119 if (objTagPair.first == m_TargetObject) 00120 { 00121 return true; 00122 } 00123 else 00124 { 00125 return false; 00126 } 00127 } 00128 00129 private: 00130 const itk::Object* m_TargetObject; 00131 }; 00132 00133 }; 00134 00135 } // end of namespace igstk 00136 00137 #endif //__igstk_Object_h_