|
OPeNDAP Hyrax Back End Server (BES)
Updated for version 3.8.3
|
A base class for a simple reference counted object. More...
#include <RCObject.h>


Public Member Functions | |
| void | addPreDeleteCB (UseCountHitZeroCB *pCB) |
| Add uniquely. More... | |
| virtual int | getRefCount () const |
| Get the current reference count. More... | |
| RCObject (RCObjectPool *pool=0) | |
| If the pool is given, the object will be released back to the pool when its count hits 0, otherwise it will be deleted. More... | |
| RCObject (const RCObject &proto) | |
| Copy ctor: Starts count at 0 and adds us to the proto's pool if it exists. More... | |
| virtual int | ref () const |
| Increase the reference count by one. More... | |
| virtual void | removeFromPool () const |
| If the object is in an auto-delete pool, remove it from the pool and force it to only delete when it's ref count goes to 0. More... | |
| void | removePreDeleteCB (UseCountHitZeroCB *pCB) |
| Remove it exists. More... | |
| virtual std::string | toString () const |
| Just prints the count and address. More... | |
| virtual int | unref () const throw () |
| Decrease the reference count by one. More... | |
| virtual | ~RCObject () |
Friends | |
| class | RCObjectPool |
A base class for a simple reference counted object.
Use as a base class for objects that need to delete themselves when their reference count goes to 0.
When a strong reference to the object is required, the caller uses ref(). When the reference needs to be released, unref() is called. p->unref() should be considered potentially identical to delete p; since it can cause the object to be deleted. The pointer should NOT be used after an unref() unless it was known to be preceded by a ref(), or unless the count is checked prior to unref() and found to be > 1.
A new RCObject has a count of 0, and will only be destroyed automatically if the count goes from 1 back to 0, so the caller is in charge of it unless the first ref() call. Be careful storing these in std::auto_ptr! Instead, use a RCPtr(new RCObject()) in place of auto_ptr for hanging onto an RCOBject* in a local variable before possible early exit.
Consider adding a pointer to an abstract MemoryPool or what have you so that a Factory can implement the interface and these objects can be stored in a list as well as returned from factory. That way the factory can forcibly clear all dangling references from the pool in its dtor in the face of exception unwind or programmer ref counting error.
Definition at line 162 of file RCObject.h.
| agg_util::RCObject::RCObject | ( | RCObjectPool * | pool = 0 | ) |
If the pool is given, the object will be released back to the pool when its count hits 0, otherwise it will be deleted.
Definition at line 39 of file RCObject.cc.
References agg_util::RCObjectPool::add().

| agg_util::RCObject::RCObject | ( | const RCObject & | proto | ) |
Copy ctor: Starts count at 0 and adds us to the proto's pool if it exists.
Definition at line 51 of file RCObject.cc.
References agg_util::RCObjectPool::add().

|
virtual |
Definition at line 63 of file RCObject.cc.
References NCML_ASSERT_MSG.
| void agg_util::RCObject::addPreDeleteCB | ( | UseCountHitZeroCB * | pCB | ) |
Add uniquely.
If it is added agan, the second time is ignored.
Definition at line 145 of file RCObject.cc.
References BESDEBUG.
|
virtual |
Get the current reference count.
Implements agg_util::RCObjectInterface.
Definition at line 110 of file RCObject.cc.
|
virtual |
Increase the reference count by one.
const since we do not consider the ref count part of the semantic constness of the rep
Implements agg_util::RCObjectInterface.
Definition at line 74 of file RCObject.cc.
References BESDEBUG.
Referenced by ncml_module::AggregationElement::addChildDataset(), ncml_module::NetcdfElement::addDimension(), ncml_module::AggregationElement::addScanElement(), ncml_module::NetcdfElement::VariableValueValidator::addVariableToValidate(), and agg_util::RCPtr< ncml_module::AggregationElement >::refAndGet().
|
virtual |
If the object is in an auto-delete pool, remove it from the pool and force it to only delete when it's ref count goes to 0.
Useful when we desire a particular object stay around outside of the pool's lifetime.
Implements agg_util::RCObjectInterface.
Definition at line 116 of file RCObject.cc.
References NCML_ASSERT, and agg_util::RCObjectPool::remove().

| void agg_util::RCObject::removePreDeleteCB | ( | UseCountHitZeroCB * | pCB | ) |
Remove it exists.
If not, this unchanged.
Definition at line 164 of file RCObject.cc.
References BESDEBUG.
|
virtual |
Just prints the count and address.
Implements agg_util::RCObjectInterface.
Reimplemented in ncml_module::NCMLElement, ncml_module::AggregationElement, ncml_module::NetcdfElement, ncml_module::VariableElement, ncml_module::DimensionElement, ncml_module::ScanElement, ncml_module::AttributeElement, ncml_module::ValuesElement, ncml_module::VariableAggElement, ncml_module::ExplicitElement, ncml_module::ReadMetadataElement, and ncml_module::RemoveElement.
Definition at line 128 of file RCObject.cc.
Referenced by unref().
|
virtual | |||||||||||||
Decrease the reference count by one.
If it goes from 1 to 0, delete this and this is no longer valid.
It is illegal to unref() an object with a count of 0. We don't throw to allow use in dtors, so the caller is assumed not to do it!
const since the reference count is not part of the semantic constness of the rep
Implements agg_util::RCObjectInterface.
Definition at line 82 of file RCObject.cc.
References BESDEBUG, agg_util::RCObjectPool::release(), and toString().
Referenced by ncml_module::NetcdfElement::clearDimensions(), agg_util::RCPtr< ncml_module::AggregationElement >::operator=(), ncml_module::AggregationElement::~AggregationElement(), and ncml_module::NetcdfElement::VariableValueValidator::~VariableValueValidator().

|
friend |
Definition at line 165 of file RCObject.h.