8#ifndef META_OCEAN_BASE_OBJECT_REF_H
9#define META_OCEAN_BASE_OBJECT_REF_H
60 friend class ObjectHolder;
169 template <
typename T2>
inline T2&
force()
const;
248 explicit inline operator bool()
const;
290 if (newReferenceCount == 1u &&
callback_)
299 if (newReferenceCount == 0u)
332 object.objectHolder_ =
nullptr;
338 if (
object !=
nullptr)
347 if (
object !=
nullptr)
363template <
typename T2>
368 ocean_assert(
dynamic_cast<T2*
>(
objectHolder_->object_) !=
nullptr);
426 if (
this != &objectRef)
454 right.objectHolder_ =
nullptr;
479 return !(*
this == objectRef);
This class implements a container for callback functions.
Definition Callback.h:3454
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
~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:444
ObjectHolder * objectHolder_
Definition base/ObjectRef.h:262
Callback< void, const Event * > ReleaseCallback
Definition base/ObjectRef.h:68
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:489
bool operator==(const ObjectRef< T > &objectRef) const
Returns whether two object references are holds the same internal object.
Definition base/ObjectRef.h:461
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
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:495
bool operator!=(const ObjectRef< T > &objectRef) const
Returns whether two object references are not equal.
Definition base/ObjectRef.h:477
friend class SmartObjectRef
Definition base/ObjectRef.h:59
The namespace covering the entire Ocean framework.
Definition Accessor.h:15