1 /*=========================================================================
3 Program: Visualization Toolkit
4 Module: $RCSfile: vtkObjectBase.h,v $
6 Date: $Date: 2002/12/03 23:41:30 $
7 Version: $Revision: 1.7 $
9 Copyright (c) 1993-2002 Ken Martin, Will Schroeder, Bill Lorensen
11 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
13 This software is distributed WITHOUT ANY WARRANTY; without even
14 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 PURPOSE. See the above copyright notice for more information.
17 =========================================================================*/
18 // .NAME vtkObjectBase - abstract base class for most VTK objects
19 // .SECTION Description
20 // vtkObjectBase is the base class for all reference counted classes
21 // in the VTK. These classes include vtkCommand classes, vtkContainer
22 // classes, and vtkObject classes.
24 // vtkObjectBase performs reference counting: objects that are
25 // reference counted exist as long as another object uses them. Once
26 // the last reference to a reference counted object is removed, the
27 // object will spontaneously destruct.
29 // Constructor and destructor of the subclasses of vtkObjectBase
30 // should be protected, so that only New() and UnRegister() actually
31 // call them. Debug leaks can be used to see if there are any objects
32 // left with nonzero reference count.
35 // Note: Objects of subclasses of vtkObjectBase should always be
36 // created with the New() method and deleted with the Delete()
37 // method. They cannot be allocated off the stack (i.e., automatic
38 // objects) because the constructor is a protected method.
41 // vtkObject vtkCommand vtkContainer
43 #ifndef __vtkObjectBase_h
44 #define __vtkObjectBase_h
46 #include "vtkIndent.h"
47 #include "vtkSystemIncludes.h"
49 class VTK_COMMON_EXPORT vtkObjectBase
53 // Return the class name as a string. This method is defined
54 // in all subclasses of vtkObjectBase with the vtkTypeRevisionMacro found
56 virtual const char *GetClassName() const {return "vtkObjectBase";};
59 // Return 1 if this class type is the same type of (or a subclass of)
60 // the named class. Returns 0 otherwise. This method works in
61 // combination with vtkTypeRevisionMacro found in vtkSetGet.h.
62 static int IsTypeOf(const char *name);
65 // Return 1 if this class is the same type of (or a subclass of)
66 // the named class. Returns 0 otherwise. This method works in
67 // combination with vtkTypeRevisionMacro found in vtkSetGet.h.
68 virtual int IsA(const char *name);
71 // Delete a VTK object. This method should always be used to delete
72 // an object when the New() method was used to create it. Using the
73 // C++ delete method will not work with reference counting.
74 virtual void Delete();
77 // Create an object with Debug turned off, modified time initialized
78 // to zero, and reference counting on.
79 static vtkObjectBase *New()
80 {return new vtkObjectBase;}
83 // avoid dll boundary problems
84 void* operator new( size_t tSize );
85 void operator delete( void* p );
89 // Print an object to an ostream. This is the method to call
90 // when you wish to see print the internal state of an object.
91 void Print(ostream& os);
94 // Methods invoked by print to print information about the object
95 // including superclasses. Typically not called by the user (use
96 // Print() instead) but used in the hierarchical print process to
97 // combine the output of several classes.
98 virtual void PrintSelf(ostream& os, vtkIndent indent);
99 virtual void PrintHeader(ostream& os, vtkIndent indent);
100 virtual void PrintTrailer(ostream& os, vtkIndent indent);
103 // Increase the reference count (mark as used by another object).
104 void Register(vtkObjectBase* o);
107 // Decrease the reference count (release by another object). This
108 // has the same effect as invoking Delete() (i.e., it reduces the
109 // reference count by 1).
110 virtual void UnRegister(vtkObjectBase* o);
113 // Return the current reference count of this object.
114 int GetReferenceCount()
115 {return this->ReferenceCount;}
118 // Sets the reference count. (This is very dangerous, use with care.)
119 void SetReferenceCount(int);
122 // Prints a list of the class .cxx file CVS revisions for all
123 // classes in the object's inheritance chain. The format of the
124 // list is "vtkObjectBase 1.4\n" with one class per line. The list
125 // always starts with the least-derived class (vtkObjectBase), and
126 // ends with the most-derived class. This is useful for programs
127 // wishing to do serialization of VTK objects.
128 void PrintRevisions(ostream& os);
132 virtual ~vtkObjectBase();
134 virtual void CollectRevisions(ostream& os);
136 int ReferenceCount; // Number of uses of this object by other objects
140 friend VTK_COMMON_EXPORT ostream& operator<<(ostream& os, vtkObjectBase& o);
145 vtkObjectBase(const vtkObjectBase&) {}
146 void operator=(const vtkObjectBase&) {}