8 #ifndef META_OCEAN_BASE_OBJECT_REF_H
9 #define META_OCEAN_BASE_OBJECT_REF_H
169 template <
typename T2>
inline T2&
force()
const;
248 explicit inline operator bool()
const;
265 template <
typename T>
268 atomicReferenceCounter_(1u),
269 callback_(releaseCallback)
274 template <
typename T>
277 ocean_assert(atomicReferenceCounter_ != 0u);
278 ++atomicReferenceCounter_;
283 template <
typename T>
286 ocean_assert(atomicReferenceCounter_ != 0u);
288 const unsigned int newReferenceCount = atomicReferenceCounter_.fetch_sub(1u) - 1u;
290 if (newReferenceCount == 1u && callback_)
294 ocean_assert(object_);
299 if (newReferenceCount == 0u)
313 template <
typename T>
316 return atomicReferenceCounter_;
319 template <
typename T>
328 template <
typename T>
332 object.objectHolder_ =
nullptr;
335 template <
typename T>
338 if (
object !=
nullptr)
344 template <
typename T>
347 if (
object !=
nullptr)
353 template <
typename T>
362 template <
typename T>
363 template <
typename T2>
373 template <
typename T>
381 template <
typename T>
389 template <
typename T>
395 template <
typename T>
406 template <
typename T>
416 template <
typename T>
423 template <
typename T>
440 template <
typename T>
451 right.objectHolder_ =
nullptr;
457 template <
typename T>
473 template <
typename T>
476 return !(*
this == objectRef);
479 template <
typename T>
485 template <
typename T>
491 template <
typename T>
This class implements a helper object for the actual object reference class.
Definition: base/ObjectRef.h:78
ObjectHolder * ref()
Increases the reference counter.
Definition: base/ObjectRef.h:275
T * object_
Pointer to the internal object.
Definition: base/ObjectRef.h:110
ReleaseCallback callback_
Release callback.
Definition: base/ObjectRef.h:116
unsigned int references() const
Returns the number of references.
Definition: base/ObjectRef.h:314
void unref()
Decreases the reference counter and disposes the encapsulated object and the holder itself if the ref...
Definition: base/ObjectRef.h:284
std::atomic< unsigned int > atomicReferenceCounter_
Reference counter of the internal object.
Definition: base/ObjectRef.h:113
ObjectHolder(T *object, const ReleaseCallback &releaseCallback=ReleaseCallback())
Creates a new ObjectHolder object.
Definition: base/ObjectRef.h:266
This template class implements a object reference with an internal reference counter.
Definition: base/ObjectRef.h:58
~ObjectRef()
Destructs an object reference object and releases the internal object if possible.
Definition: base/ObjectRef.h:354
T * pointer() const
Returns a pointer to the objects that is encapsulated by this wrapper.
Definition: base/ObjectRef.h:417
T * operator->() const
Returns a point to the internal object if existing.
Definition: base/ObjectRef.h:374
ObjectRef(ObjectRef< T > &&object) noexcept
Move constructor.
Definition: base/ObjectRef.h:329
ObjectRef< T > & operator=(ObjectRef< T > &&right) noexcept
Move operator.
Definition: base/ObjectRef.h:441
ObjectHolder * objectHolder_
Pointer to the object holder.
Definition: base/ObjectRef.h:262
bool isUnique() const
Returns whether there is no other object reference but this one.
Definition: base/ObjectRef.h:396
ObjectRef()=default
Creates an empty ObjectRef object.
friend class ObjectHolder
Definition: base/ObjectRef.h:60
bool isNull() const
Returns whether this object reference holds no internal object.
Definition: base/ObjectRef.h:390
ObjectRef(T *object, const ReleaseCallback &releaseCallback)
Creates a new ObjectRef holding and managing a given object.
Definition: base/ObjectRef.h:345
static void destroyObject(T *object)
Destroys the object located in the ObjectHolder object.
Definition: base/ObjectRef.h:486
bool operator==(const ObjectRef< T > &objectRef) const
Returns whether two object references are holds the same internal object.
Definition: base/ObjectRef.h:458
ObjectRef< T > & operator=(const ObjectRef< T > &objectRef)
Assign operator.
Definition: base/ObjectRef.h:424
ObjectRef(const ObjectRef< T > &objectRef)
Copy constructor.
Definition: base/ObjectRef.h:320
T2 & force() const
Returns a reference to the internal object forcing to a specified type.
Definition: base/ObjectRef.h:364
Callback< void, const T * > ReleaseCallback
Definition of a release callback function.
Definition: base/ObjectRef.h:68
ObjectRef(T *object)
Creates a new ObjectRef holding a given object.
Definition: base/ObjectRef.h:336
T & operator*() const
Returns a reference to the internal object if existing.
Definition: base/ObjectRef.h:382
void release()
Releases the internal object, if any.
Definition: base/ObjectRef.h:407
bool operator<(const ObjectRef< T > &objectRef) const
Returns whether the left object is less than the right one.
Definition: base/ObjectRef.h:492
bool operator!=(const ObjectRef< T > &objectRef) const
Returns whether two object references are not equal.
Definition: base/ObjectRef.h:474
This template class implements a smart object reference which is a specialization of an ObjectRef obj...
Definition: SmartObjectRef.h:90
The namespace covering the entire Ocean framework.
Definition: Accessor.h:15