39 lines
1.1 KiB
Plaintext
39 lines
1.1 KiB
Plaintext
#ifndef OSG_REFERENCED
|
|
#define OSG_REFERENCED 1
|
|
|
|
#include <osg/Export>
|
|
#include <set>
|
|
|
|
namespace osg {
|
|
|
|
/** Base class from providing referencing counted objects.*/
|
|
class SG_EXPORT Referenced
|
|
{
|
|
|
|
public:
|
|
Referenced() { _refCount=0; }
|
|
Referenced(const Referenced&) { _refCount=0; }
|
|
|
|
inline Referenced& operator = (Referenced&) { return *this; }
|
|
|
|
/** increment the reference count by one, indicating that
|
|
this object has another pointer which is referencing it.*/
|
|
inline void ref() const { ++_refCount; }
|
|
/** decrement the reference count by one, indicating that
|
|
a pointer to this object is referencing it. If the
|
|
refence count goes to zero, it is assumed that this object
|
|
is nolonger referenced and is automatically deleted.*/
|
|
inline void unref() const { --_refCount; if (_refCount<=0) delete this; }
|
|
/** return the number pointers currently referencing this object. */
|
|
inline const int referenceCount() const { return _refCount; }
|
|
|
|
protected:
|
|
virtual ~Referenced() {}
|
|
mutable int _refCount;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
#endif
|