Commit be68f183 authored by Will Schroeder's avatar Will Schroeder
Browse files

Initial revision

parent 5ff1d205
/*=========================================================================
Program: Visualization Library
Module: RefCount.hh
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file or its
contents may be copied, reproduced or altered in any way without the express
written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
// .NAME vlRefCount - subclasses of this object are reference counted
// .SECTION Description
// vlRefCount is the base class for objects that are reference counted.
// Objects that are reference counted exist as long as another object
// uses them. Once the last reference to a reference counted object is
// removed, the object will spontaneously destruct. Typically only data
// objects that are passed between objects are reference counted.
#ifndef __vlRefCount_hh
#define __vlRefCount_hh
#include "Object.hh"
class vlRefCount : public vlObject
{
public:
vlRefCount();
~vlRefCount();
void PrintSelf(ostream& os, vlIndent indent);
char *GetClassName() {return "vlRefCount";};
void Register(vlObject* o);
void UnRegister(vlObject* o);
int GetRefCount() {return this->RefCount;};
private:
int RefCount; // Number of uses of this object by other objects
};
#endif
/*=========================================================================
Program: Visualization Library
Module: RefCount.cc
Language: C++
Date: $Date$
Version: $Revision$
This file is part of the Visualization Library. No part of this file
or its contents may be copied, reproduced or altered in any way
without the express written consent of the authors.
Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen 1993, 1994
=========================================================================*/
#include "RefCount.hh"
// Description:
// Construct with initial reference count = 0.
vlRefCount::vlRefCount()
{
this->RefCount = 0;
}
vlRefCount::~vlRefCount()
{
if (this->RefCount > 0)
{
vlErrorMacro(<< "Trying to delete object with non-zero reference count");
}
}
// Description:
// Increase the reference count (mark as used by another object).
void vlRefCount::Register(vlObject* o)
{
this->RefCount++;
vlDebugMacro(<< "Registered by " << o->GetClassName() << " (" << o << ")");
}
// Description:
// Decrease the reference count (release by another object).
void vlRefCount::UnRegister(vlObject* o)
{
vlDebugMacro(<< "UnRegistered by " << o->GetClassName() << " (" << 0 << ")");
if (--this->RefCount <= 0) delete this;
}
void vlRefCount::PrintSelf(ostream& os, vlIndent indent)
{
if (this->ShouldIPrint(vlRefCount::GetClassName()))
{
vlObject::PrintSelf(os,indent);
os << indent << "Reference Count: " << this->RefCount << "\n";
}
}
Markdown is supported
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