Commit 25ea8d78 authored by Andy Cedilnik's avatar Andy Cedilnik
Browse files

Add superclass of vtkObject called vtkObjectBase, put reference counting to...

Add superclass of vtkObject called vtkObjectBase, put reference counting to vtkObjectBase, make all Register and UnRegister methods to be virtual and take vtkObjectBase as an argument, fix wrapping for Tcl and try to fix it for Python and Java. This was tested on Linux and Windows. Also, containers are now subclass of vtkObjectBase. Eventually commands should also be.
parent 9b1201a5
......@@ -79,6 +79,7 @@ vtkMultiThreader.cxx
vtkMutexLock.cxx
vtkNonLinearCell.cxx
vtkObject.cxx
vtkObjectBase.cxx
vtkObjectFactory.cxx
vtkObjectFactoryCollection.cxx
vtkOldStyleCallbackCommand.cxx
......@@ -152,6 +153,8 @@ vtkWindowLevelLookupTable.cxx
vtkXMLFileOutputWindow.cxx
)
# vtkObjectBase is marked ABSTRACT so that instantiators are happy.
ABSTRACT_FILES(
vtkAbstractMapper
vtkAbstractTransform
......@@ -170,6 +173,7 @@ vtkInitialValueProblemSolver
vtkLinearTransform
vtkLocator
vtkNonLinearCell
vtkObjectBase
vtkObjectFactory
vtkOldStyleCallbackCommand
vtkOverrideInformation
......
......@@ -26,13 +26,15 @@
// VTK Iterators are not reliable when adding or deleting elements
// from the container. Use iterators for traversing only.
#include "vtkContainer.h"
#ifndef __vtkAbstractIterator_h
#define __vtkAbstractIterator_h
#include "vtkObjectBase.h"
class vtkContainer;
template<class KeyType, class DataType>
class vtkAbstractIterator
class vtkAbstractIterator : public vtkObjectBase
{
friend class vtkContainer;
......@@ -41,23 +43,6 @@ public:
// Return the class name as a string.
virtual const char* GetClassName() const { return "vtkAbstractIterator"; }
// Description:
// The counterpart to New(), Delete simply calls UnRegister to lower the
// reference count by one. It is no different than calling UnRegister.
void Delete() { this->UnRegister(); }
// Description:
// Increase the reference count of this container.
void Register();
void Register(vtkObject *) { this->Register(); }
// Description:
// Decrease the reference count (release by another object). This has
// the same effect as invoking Delete() (i.e., it reduces the reference
// count by 1).
void UnRegister();
void UnRegister(vtkObject *) { this->UnRegister(); }
// Description:
// Retrieve the key from the iterator. For lists, the key is the
// index of the element.
......
......@@ -44,22 +44,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#define __vtkAbstractIterator_txx
#include "vtkAbstractIterator.h"
#include "vtkDebugLeaks.h"
template<class KeyType, class DataType>
void vtkAbstractIterator<KeyType,DataType>::Register()
{
this->ReferenceCount++;
}
template<class KeyType, class DataType>
void vtkAbstractIterator<KeyType,DataType>::UnRegister()
{
if (--this->ReferenceCount <= 0)
{
delete this;
}
}
#include "vtkDebugLeaks.h"
#include "vtkContainer.h"
template<class KeyType, class DataType>
vtkAbstractIterator<KeyType,DataType>::vtkAbstractIterator()
......
......@@ -68,7 +68,8 @@ class vtkAbstractList : public vtkContainer
{
public:
typedef vtkContainer Superclass;
const char* GetClassName() const { return "vtkAbstractList"; }
static vtkAbstractList<DType>* New();
virtual const char* GetClassName() const { return "vtkAbstractList"; }
// Just to avoid typing over and over, let us define some typedefs.
// They will not work in subclasses, but this header file will
......
......@@ -21,6 +21,16 @@
#define __vtkAbstractList_txx
#include "vtkAbstractList.h"
#include "vtkDebugLeaks.h"
template<class DType>
vtkAbstractList<DType>* vtkAbstractList<DType>::New()
{
#ifdef VTK_DEBUG_LEAKS
vtkDebugLeaks::ConstructClass("vtkAbstractList");
#endif
return new vtkAbstractList<DType>;
}
template<class DataType>
vtkAbstractList<DataType>::vtkAbstractList() {}
......
......@@ -22,7 +22,7 @@
#include "vtkDebugLeaks.h"
#include "vtkCriticalSection.h"
vtkCxxRevisionMacro(vtkAbstractTransform, "1.21");
vtkCxxRevisionMacro(vtkAbstractTransform, "1.22");
//----------------------------------------------------------------------------
vtkAbstractTransform::vtkAbstractTransform()
......@@ -331,7 +331,7 @@ unsigned long vtkAbstractTransform::GetMTime()
//----------------------------------------------------------------------------
// We need to handle the circular reference between a transform and its
// inverse.
void vtkAbstractTransform::UnRegister(vtkObject *o)
void vtkAbstractTransform::UnRegister(vtkObjectBase *o)
{
if (this->InUnRegister)
{ // we don't want to go into infinite recursion...
......@@ -380,7 +380,7 @@ protected:
void operator=(const vtkSimpleTransform&);
};
vtkCxxRevisionMacro(vtkSimpleTransform, "1.21");
vtkCxxRevisionMacro(vtkSimpleTransform, "1.22");
//----------------------------------------------------------------------------
vtkTransformConcatenation::vtkTransformConcatenation()
......
......@@ -242,7 +242,7 @@ public:
// Description:
// Needs a special UnRegister() implementation to avoid
// circular references.
void UnRegister(vtkObject *O);
virtual void UnRegister(vtkObjectBase *O);
// Description:
// This method is deprecated in the base class. It is still valid
......
......@@ -47,6 +47,7 @@
#include "vtkWin32Header.h"
class vtkObjectBase;
class vtkObject;
// The superclass that all commands should be subclasses of
......@@ -63,7 +64,7 @@ public:
// Description:
// Increase the reference count (mark as used by another object).
void Register();
void Register(vtkObject *)
void Register(vtkObjectBase *)
{ this->Register(); }
// Description:
......@@ -71,7 +72,7 @@ public:
// the same effect as invoking Delete() (i.e., it reduces the reference
// count by 1).
void UnRegister();
void UnRegister(vtkObject *)
void UnRegister(vtkObjectBase *)
{ this->UnRegister(); }
// Description:
......
......@@ -43,22 +43,8 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "vtkContainer.h"
#include "vtkDebugLeaks.h"
void vtkContainer::Register()
{
this->ReferenceCount++;
}
void vtkContainer::UnRegister()
{
if (--this->ReferenceCount <= 0)
{
delete this;
}
}
vtkContainer::vtkContainer()
{
this->ReferenceCount = 1;
}
vtkContainer::~vtkContainer()
......
......@@ -32,13 +32,13 @@
// .SECTION See Also
// vtkAbstractIterator, vtkAbstractList, vtkAbstractMap
#include "vtkObject.h"
#include "vtkObjectBase.h"
#include "vtkString.h"
#ifndef __vtkContainer_h
#define __vtkContainer_h
class VTK_COMMON_EXPORT vtkContainer
class VTK_COMMON_EXPORT vtkContainer : public vtkObjectBase
{
public:
// Description:
......@@ -58,22 +58,22 @@ public:
// Description:
// The counterpart to New(), Delete simply calls UnRegister to lower the
// reference count by one. It is no different than calling UnRegister.
void Delete() { this->UnRegister(); }
//void Delete() { this->UnRegister(); }
// Description:
// Increase the reference count of this container.
void Register();
void Register(vtkObject *) { this->Register(); }
//void Register();
//void Register(vtkObject *) { this->Register(); }
// Description:
// Decrease the reference count (release by another object). This has
// the same effect as invoking Delete() (i.e., it reduces the reference
// count by 1).
void UnRegister();
void UnRegister(vtkObject *) { this->UnRegister(); }
//void UnRegister();
//void UnRegister(vtkObject *) { this->UnRegister(); }
protected:
vtkIdType ReferenceCount;
//vtkIdType ReferenceCount;
vtkContainer();
virtual ~vtkContainer();
......@@ -88,7 +88,7 @@ int vtkContainerDefaultCompare(DType& k1, DType& k2)
return ( k1 < k2 ) ? ( -1 ) : ( ( k1 == k2 ) ? ( 0 ) : ( 1 ) );
}
static inline int vtkContainerCompareMethod(vtkObject* d1, vtkObject* d2)
static inline int vtkContainerCompareMethod(vtkObjectBase* d1, vtkObjectBase* d2)
{ return vtkContainerDefaultCompare(d1,d2); }
static inline int vtkContainerCompareMethod(char d1, char d2)
{ return vtkContainerDefaultCompare(d1,d2); }
......@@ -120,7 +120,7 @@ static inline int vtkContainerCompareMethod(void* d1, void* d2)
template<class DType>
DType vtkContainerDefaultCreate(DType k2) { return k2; }
static inline vtkObject* vtkContainerCreateMethod(vtkObject* d1)
static inline vtkObjectBase* vtkContainerCreateMethod(vtkObjectBase* d1)
{ if ( d1) { d1->Register(0); } return d1; }
static inline char vtkContainerCreateMethod(char d1)
{ return vtkContainerDefaultCreate(d1); }
......@@ -149,7 +149,7 @@ static inline char* vtkContainerCreateMethod(char* d1)
static inline void* vtkContainerCreateMethod(void* d1)
{ return vtkContainerDefaultCreate(d1); }
static inline void vtkContainerDeleteMethod(vtkObject* d1)
static inline void vtkContainerDeleteMethod(vtkObjectBase* d1)
{ if ( d1 ) { d1->UnRegister(0); } /* cout << "UR(d1)" << endl; */ }
static inline void vtkContainerDeleteMethod(char) {}
static inline void vtkContainerDeleteMethod(short) {}
......
......@@ -22,7 +22,7 @@
#include "vtkObjectFactory.h"
#include "vtkSource.h"
vtkCxxRevisionMacro(vtkDataObject, "1.85");
vtkCxxRevisionMacro(vtkDataObject, "1.86");
vtkStandardNewMacro(vtkDataObject);
vtkCxxSetObjectMacro(vtkDataObject,FieldData,vtkFieldData);
......@@ -458,7 +458,7 @@ void vtkDataObject::SetSource(vtkSource *arg)
//----------------------------------------------------------------------------
void vtkDataObject::UnRegister(vtkObject *o)
void vtkDataObject::UnRegister(vtkObjectBase *o)
{
// detect the circular loop source <-> data
// If we have two references and one of them is my data
......
......@@ -108,7 +108,7 @@ public:
vtkGetObjectMacro(FieldData,vtkFieldData);
// Handle the source/data loop.
void UnRegister(vtkObject *o);
virtual void UnRegister(vtkObjectBase *o);
// Description:
// Get the net reference count. That is the count minus
......
......@@ -105,12 +105,20 @@ ostream& operator<<(ostream& os, vtkObject& o)
return os;
}
vtkObject *vtkObject::New()
{
#ifdef VTK_DEBUG_LEAKS
vtkDebugLeaks::ConstructClass("vtkObject");
#endif
return new vtkObject;
}
// Create an object with Debug turned off and modified time initialized
// to zero.
vtkObject::vtkObject()
{
this->Debug = 0;
this->ReferenceCount = 1;
this->SubjectHelper = NULL;
this->Modified(); // Insures modified time > than any other time
// initial reference count = 1 and reference counting on.
......@@ -133,10 +141,10 @@ vtkObject::~vtkObject()
// Delete a vtk object. This method should always be used to delete an object
// when the new operator was used to create it. Using the C++ delete method
// will not work with reference counting.
void vtkObject::Delete()
{
this->UnRegister((vtkObject *)NULL);
}
//void vtkObject::Delete()
//{
// this->UnRegister((vtkObject *)NULL);
//}
// Return the modification for this object.
unsigned long int vtkObject::GetMTime()
......@@ -221,39 +229,39 @@ void vtkObject::SetReferenceCount(int ref)
// Description:
// Increase the reference count (mark as used by another object).
void vtkObject::Register(vtkObject* o)
{
this->ReferenceCount++;
if ( o )
{
vtkDebugMacro(<< "Registered by " << o->GetClassName() << " (" << o
<< "), ReferenceCount = " << this->ReferenceCount);
}
else
{
vtkDebugMacro(<< "Registered by NULL, ReferenceCount = "
<< this->ReferenceCount);
}
if (this->ReferenceCount <= 0)
{
delete this;
}
}
// void vtkObject::Register(vtkObjectBase* o)
// {
// this->ReferenceCount++;
// if ( o )
// {
// vtkDebugMacro(<< "Registered by " << o->GetClassName() << " (" << o
// << "), ReferenceCount = " << this->ReferenceCount);
// }
// else
// {
// vtkDebugMacro(<< "Registered by NULL, ReferenceCount = "
// << this->ReferenceCount);
// }
// if (this->ReferenceCount <= 0)
// {
// delete this;
// }
// }
// Description:
// Decrease the reference count (release by another object).
void vtkObject::UnRegister(vtkObject* o)
void vtkObject::UnRegister(vtkObjectBase* o)
{
if (o)
{
vtkDebugMacro(<< "UnRegistered by "
<< o->GetClassName() << " (" << o << "), ReferenceCount = "
<< (this->ReferenceCount-1));
<< o->GetClassName() << " (" << o << "), ReferenceCount = "
<< (this->ReferenceCount-1));
}
else
{
vtkDebugMacro(<< "UnRegistered by NULL, ReferenceCount = "
<< (this->ReferenceCount-1));
<< (this->ReferenceCount-1));
}
if (--this->ReferenceCount <= 0)
......@@ -288,7 +296,7 @@ vtkObject *vtkObject::SafeDownCast(vtkObject *o)
void vtkObject::CollectRevisions(ostream& os)
{
os << "vtkObject 1.75\n";
os << "vtkObject 1.76\n";
}
//----------------------------------Command/Observer stuff-------------------
......@@ -296,7 +304,7 @@ void vtkObject::CollectRevisions(ostream& os)
vtkObserver::~vtkObserver()
{
this->Command->UnRegister();
this->Command->UnRegister(0);
}
vtkSubjectHelper::~vtkSubjectHelper()
......@@ -324,7 +332,7 @@ AddObserver(unsigned long event, vtkCommand *cmd, float p)
elem->Next = NULL;
elem->Event = event;
elem->Command = cmd;
cmd->Register();
cmd->Register(0);
elem->Tag = this->Count;
this->Count++;
......
......@@ -43,18 +43,19 @@
#include "vtkIndent.h"
#include "vtkTimeStamp.h"
#include "vtkSetGet.h"
#include "vtkObjectBase.h"
class vtkSubjectHelper;
class vtkCommand;
class VTK_COMMON_EXPORT vtkObject
class VTK_COMMON_EXPORT vtkObject : public vtkObjectBase
{
public:
// Description:
// Return the class name as a string. This method is defined
// in all subclasses of vtkObject with the vtkTypeRevisionMacro found
// in vtkSetGet.h.
virtual const char *GetClassName() {return "vtkObject";};
virtual const char *GetClassName() const {return "vtkObject";};
// Description:
// Return 1 if this class type is the same type of (or a subclass of)
......@@ -71,21 +72,20 @@ public:
// Description:
// Will cast the supplied object to vtkObject* is this is a safe operation
// (i.e., a safe downcast); otherwise NULL is returned. This method is
// defined in all subclasses of vtkObject with the vtkTypeRevisionMacro found in
// vtkSetGet.h.
// defined in all subclasses of vtkObject with the vtkTypeRevisionMacro
// found in vtkSetGet.h.
static vtkObject *SafeDownCast(vtkObject *o);
// Description:
// Delete a VTK object. This method should always be used to delete
// an object when the New() method was used to create it. Using the
// C++ delete method will not work with reference counting.
virtual void Delete();
//virtual void Delete();
// Description:
// Create an object with Debug turned off, modified time initialized
// to zero, and reference counting on.
static vtkObject *New()
{return new vtkObject;}
static vtkObject *New();
#ifdef _WIN32
// avoid dll boundary problems
......@@ -150,13 +150,13 @@ public:
// Description:
// Increase the reference count (mark as used by another object).
void Register(vtkObject* o);
//virtual void Register(vtkObjectBase* o);
// Description:
// Decrease the reference count (release by another object). This has
// the same effect as invoking Delete() (i.e., it reduces the reference
// count by 1).
virtual void UnRegister(vtkObject* o);
virtual void UnRegister(vtkObjectBase* o);
// Description:
// Return the current reference count of this object.
......@@ -202,7 +202,6 @@ protected:
unsigned char Debug; // Enable debug messages
vtkTimeStamp MTime; // Keep track of modification time
int ReferenceCount; // Number of uses of this object by other objects
vtkSubjectHelper *SubjectHelper;
private:
......
......@@ -113,7 +113,8 @@ void vtkObjectBase::Register(vtkObjectBase* o)
this->ReferenceCount++;
if ( o )
{
vtkBaseDebugMacro(<< "Registered by " << o->GetClassName() << " (" << o
vtkBaseDebugMacro(<< "Registered by " << this->GetClassName()
<< " " << o->GetClassName() << " (" << o
<< "), ReferenceCount = " << this->ReferenceCount);
}
else
......@@ -141,7 +142,8 @@ void vtkObjectBase::UnRegister(vtkObjectBase* o)
else
{
vtkBaseDebugMacro(
<< "UnRegistered by NULL, ReferenceCount = "
<< "UnRegistered " << this->GetClassName()
<< " by NULL, ReferenceCount = "
<< (this->ReferenceCount-1));
}
......@@ -158,5 +160,5 @@ void vtkObjectBase::UnRegister(vtkObjectBase* o)
void vtkObjectBase::CollectRevisions(ostream& os)
{
os << "vtkObjectBase 1.1\n";
os << "vtkObjectBase 1.2\n";
}
......@@ -20,7 +20,7 @@
#include "vtkSource.h"
#include "vtkPointLocator.h"
vtkCxxRevisionMacro(vtkPointSet, "1.74");
vtkCxxRevisionMacro(vtkPointSet, "1.75");
vtkCxxSetObjectMacro(vtkPointSet,Points,vtkPoints);
......@@ -306,7 +306,7 @@ void vtkPointSet::Squeeze()
}
//----------------------------------------------------------------------------
void vtkPointSet::UnRegister(vtkObject *o)
void vtkPointSet::UnRegister(vtkObjectBase *o)
{
// detect the circular loop source <-> data
// If we have two references and one of them is my data
......
......@@ -79,7 +79,7 @@ public:
// Description:
// Detect reference loop PointSet <-> locator.
void UnRegister(vtkObject *o);
virtual void UnRegister(vtkObjectBase *o);
// Description:
// Get the net reference count. That is the count minus
......
......@@ -128,7 +128,6 @@
(((type) == VTK_UNSIGNED_CHAR) ? "unsigned char" : \
"Undefined"))))))
//
// Set built-in type. Creates member Set"name"() (e.g., SetVisibility());
//
......@@ -621,7 +620,7 @@ virtual float *Get##name() \
//
#define vtkTypeMacro(thisClass,superclass) \
typedef superclass Superclass; \
virtual const char *GetClassName() {return #thisClass;} \
virtual const char *GetClassName() const {return #thisClass;} \
static int IsTypeOf(const char *type) \
{ \
if ( !strcmp(#thisClass,type) ) \
......@@ -653,7 +652,6 @@ virtual float *Get##name() \
return thisClass::SafeDownCast(this->NewInstanceInternal()); \
}
// Version of vtkTypeMacro that adds the CollectRevisions method.
#define vtkTypeRevisionMacro(thisClass,superclass) \
protected: \
......
......@@ -23,7 +23,7 @@
#include "vtkFieldData.h"
#include "vtkObjectFactory.h"
vtkCxxRevisionMacro(vtkSource, "1.96");
vtkCxxRevisionMacro(vtkSource, "1.97");
#ifndef NULL
#define NULL 0
......@@ -714,7 +714,7 @@ int vtkSource::InRegisterLoop(vtkObject *o)
return 0;
}
void vtkSource::UnRegister(vtkObject *o)
void vtkSource::UnRegister(vtkObjectBase *o)
{
int idx;
int done = 0;
......
......@@ -95,7 +95,7 @@ public:
// Description:
// Handle the source/data loop.
void UnRegister(vtkObject *o);
virtual void UnRegister(vtkObjectBase *o);
// Description:
// Test to see if this object is in a reference counting loop.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment