2001-10-04 23:12:57 +08:00
|
|
|
//C++ header - Open Scene Graph - Copyright (C) 1998-2001 Robert Osfield
|
|
|
|
//Distributed under the terms of the GNU Library General Public License (LGPL)
|
|
|
|
//as published by the Free Software Foundation.
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
#ifndef OSG_REFERENCED
|
|
|
|
#define OSG_REFERENCED 1
|
|
|
|
|
|
|
|
#include <osg/Export>
|
2001-09-20 05:08:56 +08:00
|
|
|
#include <set>
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
namespace osg {
|
|
|
|
|
|
|
|
/** Base class from providing referencing counted objects.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
class SG_EXPORT Referenced
|
2001-01-11 00:32:10 +08:00
|
|
|
{
|
|
|
|
|
|
|
|
public:
|
|
|
|
Referenced() { _refCount=0; }
|
2001-09-20 05:08:56 +08:00
|
|
|
Referenced(const Referenced&) { _refCount=0; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
2001-09-20 05:08:56 +08:00
|
|
|
inline Referenced& operator = (Referenced&) { return *this; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
/** increment the reference count by one, indicating that
|
|
|
|
this object has another pointer which is referencing it.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void ref() const { ++_refCount; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** decrement the reference count by one, indicating that
|
|
|
|
a pointer to this object is referencing it. If the
|
2001-10-01 19:15:55 +08:00
|
|
|
reference count goes to zero, it is assumed that this object
|
|
|
|
is no longer referenced and is automatically deleted.*/
|
2001-09-20 05:08:56 +08:00
|
|
|
inline void unref() const { --_refCount; if (_refCount<=0) delete this; }
|
2001-01-11 00:32:10 +08:00
|
|
|
/** return the number pointers currently referencing this object. */
|
2001-09-20 05:08:56 +08:00
|
|
|
inline const int referenceCount() const { return _refCount; }
|
2001-01-11 00:32:10 +08:00
|
|
|
|
|
|
|
protected:
|
2001-09-20 05:08:56 +08:00
|
|
|
virtual ~Referenced() {}
|
|
|
|
mutable int _refCount;
|
|
|
|
|
2001-01-11 00:32:10 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|