32 #ifndef Object_INCLUDE_ONCE 33 #define Object_INCLUDE_ONCE 40 #if VL_DEBUG_LIVING_OBJECTS 67 mObject =
const_cast<T*
>(object);
89 other->incReference();
100 other->incReference();
103 mObject =
const_cast<T*
>(other);
111 other->incReference();
166 VL_DEBUG_SET_OBJECT_NAME()
167 mRefCountMutex =
NULL;
169 mAutomaticDelete =
true;
171 #ifdef VL_USER_DATA_OBJECT 174 #if VL_DEBUG_LIVING_OBJECTS 175 debug_living_objects()->insert(
this);
186 #ifdef VL_USER_DATA_OBJECT 187 mUserData = other.mUserData;
192 mAutomaticDelete =
true;
195 #if VL_DEBUG_LIVING_OBJECTS 196 debug_living_objects()->insert(
this);
206 #ifdef VL_USER_DATA_OBJECT 207 mUserData = other.mUserData;
217 const std::string&
objectName()
const {
return mObjectName; }
237 return mReferenceCount;
245 const_cast<IMutex*
>(refCountMutex())->lock();
251 const_cast<IMutex*>(refCountMutex())->unlock();
258 IMutex* mutex = mRefCountMutex;
266 if (mReferenceCount == 0 && automaticDelete())
282 T*
as() {
return cast<T>(
this); }
286 const T*
as()
const {
return cast<const T>(
this); }
288 #ifdef VL_USER_DATA_OBJECT 290 const Object* userData()
const {
return mUserData.get(); }
291 Object* userData() {
return mUserData.get(); }
292 void setUserData(
Object* user_data) { mUserData = user_data; }
309 #if VL_DEBUG_LIVING_OBJECTS 310 static std::set< Object* >* mDebug_LivingObjects;
311 static std::set< Object* >* debug_living_objects()
313 if (!mDebug_LivingObjects)
314 mDebug_LivingObjects =
new std::set< Object* >;
315 return mDebug_LivingObjects;
ref(const T *object=NULL)
const T * operator->() const
const T & operator*() const
ref & operator=(const ref &other)
void setAutomaticDelete(bool autodel_on)
If set to true the Object is deleted when its reference count reaches 0.
void setObjectName(const char *name)
The name of the object, by default set to the object's class name in debug builds.
const IMutex * refCountMutex() const
The mutex used to protect the reference counting of an Object across multiple threads.
Set of macros and templates implementing a simple and portable RTTI system.
Object(const Object &other)
Copy constructor: copies the name, ref count mutex and user data.
IMutex * refCountMutex()
The mutex used to protect the reference counting of an Object across multiple threads.
#define VL_INSTRUMENT_BASE_CLASS(ClassName)
ref & operator=(const T *other)
Visualization Library main namespace.
void setRefCountMutex(IMutex *mutex)
The mutex used to protect the reference counting of an Object across multiple threads.
void setObjectName(const std::string &name)
The name of the object, by default set to the object's class name in debug builds.
bool operator!=(const ref< T1 > &o1, const ref< T2 > &o2)
The base class for all the reference counted objects.
An interface to implement simple platform-independent mutexes used to protect critical sections...
ref & operator=(const ref< T2 > &other)
T * as()
Casts an Object to the specified class.
int referenceCount() const
Returns the number of references of an object.
T * get_writable() const
This is mainly useful when using ref<> with std::map, std::set, etc.
const std::string & objectName() const
The name of the object, by default set to the object's class name.
virtual void lock()=0
Locks the mutex.
bool operator<(const ref &other) const
const T * as() const
Casts an Object to the specified class.
bool automaticDelete() const
If set to true the Object is deleted when its reference count reaches 0.
bool operator==(const ref< T1 > &o1, const ref< T2 > &o2)
ref(const ref< T2 > &other)
The ref<> class is used to reference-count an Object.
virtual void unlock()=0
Unlocks the mutex.
void decReference()
Decrements the reference count of an object and deletes it if both automaticDelete() is true the coun...
Object & operator=(const Object &other)
Copy operator: copies the object's name, ref count mutex and user data.
void incReference() const
Increments the reference count of an object.