KWStyle - itkObject.h
 
Matrix View
Description

1 /*=========================================================================
2
3   Program:   Insight Segmentation & Registration Toolkit
4   Module:    $RCSfile: itkObject.h.html,v $
5   Language:  C++
6   Date:      $Date: 2006/01/17 19:15:43 $
7   Version:   $Revision: 1.4 $
8
9   Copyright (c) Insight Software Consortium. All rights reserved.
10   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11
12   Portions of this code are covered under the VTK copyright.
13   See VTKCopyright.txt or http://www.kitware.com/VTKCopyright.htm for details.
14
15      This software is distributed WITHOUT ANY WARRANTY; without even 
16      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
17 IND *****PURPOSE.  See the above copyright notices for more information.
18
19 =========================================================================*/
20 #ifndef __itkObject_h
21 #define __itkObject_h
22
23 #include "itkLightObject.h"
24 #include "itkEventObject.h"
25
26 #include "itkMetaDataDictionary.h"
27 namespace itk
28 {
29 class SubjectImplementation;
30 class Command;
31
32 /** \class Object
33  * \brief Base class for most itk classes.
34  *
35  * Object is the second-highest level base class for most itk objects.
36  * It extends the base object functionality of LightObject by
37  * implementing callbacks (via object/observer), debug flags/methods,
38  * and modification time tracking. Most ITK classes should be a subclas
39  * of Object due to the need to keep track of modified time.
40  *
41  * \ingroup ITKSystemObjects
42  * \ingroup DataRepresentation
43  */
44 class ITKCommon_EXPORT Object: public LightObject
45 {
46 public:
47   /** Smart pointer typedef support. */
48   typedef Object              Self;
49 TDA   typedef LightObject  Superclass;
50   typedef SmartPointer<Self>  Pointer;
51 TDA   typedef SmartPointer<const Self>  ConstPointer;
52   
53   /** Method for creation through the object factory. */
54   static Pointer New();
55
56   /** Create an object from an instance, potentially deferring to a
57    * factory.  This method allows you to create an instance of an
58    * object that is exactly the same type as the referring object.
59    * This is useful in cases where an object has been cast back to a
60    * base class. */
61   virtual LightObject::Pointer CreateAnother() const;
62
63   /** Standard part of all itk objects. */
64   itkTypeMacro(Object, LightObject);
65
66   /** Turn debugging output on.  */
67   virtual void DebugOn() const;
68
69   /** Turn debugging output off.  */
70   virtual void DebugOff() const;
71   
72   /** Get the value of the debug flag.  */
73   bool GetDebug() const;
74   
75   /** Set the value of the debug flag. A non-zero value turns debugging on. */
76   void SetDebug(bool debugFlag) const;
77   
78   /** Return this objects modified time.  */
79   virtual unsigned long GetMTime() const;
80
81   /** Update the modification time for this object. Many filters rely on the
82    * modification time to determine if they need to recompute their data.  */
83   virtual void Modified() const;
84   
85   /** Increase the reference count (mark as used by another object).  */
86   virtual void Register() const;
87
88   /** Decrease the reference count (release by another object).  */
89   virtual void UnRegister() const;
90
91   /** Sets the reference count (use with care)  */
92   virtual void SetReferenceCount(int);
93
94   /** This is a global flag that controls whether any debug, warning
95    *  or error messages are displayed.  */
96   static void SetGlobalWarningDisplay(bool flag);
97   static bool GetGlobalWarningDisplay();
98   static void GlobalWarningDisplayOn()
99     { Object::SetGlobalWarningDisplay(true); }
100   static void GlobalWarningDisplayOff()
101     { Object::SetGlobalWarningDisplay(false); }
102     
103   /** Allow people to add/remove/invoke observers (callbacks) to any ITK
104    * object. This is an implementation of the subject/observer design
105    * pattern. An observer is added by specifying an event to respond to
106    * and an itk::Command to execute. It returns an unsigned long tag
107    * which can be used later to remove the event or retrieve the
108    * command.  The memory for the Command becomes the responsibility of
109    * this object, so don't pass the same instance of a command to two
110    * different objects  */
111   unsigned long AddObserver(const EventObject & event, Command *);
112   unsigned long AddObserver(const EventObject & event, Command *) const;
113  
114   /** Get the command associated with the given tag.  NOTE: This returns
115    * a pointer to a Command, but it is safe to asign this to a
116    * Command::Pointer.  Since Command inherits from LightObject, at this
117    * point in the code, only a pointer or a reference to the Command can
118    * be used.   */
119   Command* GetCommand(unsigned long tag);
120
121   /** Call Execute on all the Commands observing this event id. */
122   void InvokeEvent( const EventObject & );
123
124   /** Call Execute on all the Commands observing this event id.
125    * The actions triggered by this call doesn't modify this object. */
126   void InvokeEvent( const EventObject & ) const;
127
128   /** Remove the observer with this tag value. */
129   void RemoveObserver(unsigned long tag);
130
131   /** Remove all observers . */
132   void RemoveAllObservers();
133
134   /** Return true if an observer is registered for this event. */
135   bool HasObserver( const EventObject & event ) const;
136
137   /**
138    * \return A reference to this objects MetaDataDictionary.
139    * \warning This reference may be changed.
140    */
141   MetaDataDictionary & GetMetaDataDictionary(void);
142
143   /**
144    * \return A constant reference to this objects MetaDataDictionary.
145    */
146   const MetaDataDictionary & GetMetaDataDictionary(void) const;
147
148   /**
149    * \return Set the MetaDataDictionary
150    */
151   void SetMetaDataDictionary(const MetaDataDictionary & rhs);
152
153
154 protected:
155   Object(); 
156   virtual ~Object(); 
157
158   /** Methods invoked by Print() to print information about the object
159    * including superclasses. Typically not called by the user (use Print()
160    * instead) but used in the hierarchical print process to combine the
161    * output of several classes.  */
162   virtual void PrintSelf(std::ostream& os, Indent indent) const;
163
164   bool PrintObservers(std::ostream& os, Indent indent) const;
165
166 private:
167   Object(const Self&); //purposely not implemented
168   void operator=(const Self&); //purposely not implemented
169
170   /** Enable/Disable debug messages. */
171   mutable bool m_Debug;
172   
173   /** Keep track of modification time. */
174   mutable TimeStamp m_MTime;
175   
176   /** Global object debug flag. */
177   static bool m_GlobalWarningDisplay;
178
179   /** Implementation class for Subject/Observer Pattern.
180    * This is only allocated if used. */
181   SubjectImplementation* m_SubjectImplementation;
182 IND */**
183 IND *** Implementation for holding Object MetaData
184 IND *** @see itk::MetaDataDictionary
185 IND *** @see itk::MetaDataObjectBase
186 IND *** @see itk::MetaDataObject
187 IND *** This is only allocated if used.
188 IND ***/
189   mutable MetaDataDictionary * m_MetaDataDictionary;
190 };
191
192 // end namespace itk
193
194 #endif
195
196 EOF

Generated by KWStyle 1.0b on Tuesday January,17 at 02:14:37PM
© Kitware Inc.