Ocean
|
This template class implements a object reference with an internal reference counter. More...
Data Structures | |
class | ObjectHolder |
This class implements a helper object for the actual object reference class. More... | |
Public Types | |
typedef Callback< void, const T * > | ReleaseCallback |
Definition of a release callback function. More... | |
Public Member Functions | |
ObjectRef ()=default | |
Creates an empty ObjectRef object. More... | |
ObjectRef (const ObjectRef< T > &objectRef) | |
Copy constructor. More... | |
ObjectRef (ObjectRef< T > &&object) noexcept | |
Move constructor. More... | |
ObjectRef (T *object) | |
Creates a new ObjectRef holding a given object. More... | |
ObjectRef (T *object, const ReleaseCallback &releaseCallback) | |
Creates a new ObjectRef holding and managing a given object. More... | |
~ObjectRef () | |
Destructs an object reference object and releases the internal object if possible. More... | |
template<typename T2 > | |
T2 & | force () const |
Returns a reference to the internal object forcing to a specified type. More... | |
T * | operator-> () const |
Returns a point to the internal object if existing. More... | |
T & | operator* () const |
Returns a reference to the internal object if existing. More... | |
bool | isUnique () const |
Returns whether there is no other object reference but this one. More... | |
bool | isNull () const |
Returns whether this object reference holds no internal object. More... | |
void | release () |
Releases the internal object, if any. More... | |
T * | pointer () const |
Returns a pointer to the objects that is encapsulated by this wrapper. More... | |
ObjectRef< T > & | operator= (const ObjectRef< T > &objectRef) |
Assign operator. More... | |
ObjectRef< T > & | operator= (ObjectRef< T > &&right) noexcept |
Move operator. More... | |
bool | operator== (const ObjectRef< T > &objectRef) const |
Returns whether two object references are holds the same internal object. More... | |
bool | operator!= (const ObjectRef< T > &objectRef) const |
Returns whether two object references are not equal. More... | |
bool | operator< (const ObjectRef< T > &objectRef) const |
Returns whether the left object is less than the right one. More... | |
operator bool () const | |
Returns whether this object reference holds an internal object. More... | |
Static Protected Member Functions | |
static void | destroyObject (T *object) |
Destroys the object located in the ObjectHolder object. More... | |
Protected Attributes | |
ObjectHolder * | objectHolder_ = nullptr |
Pointer to the object holder. More... | |
Friends | |
template<typename T2 , typename TBase > | |
class | SmartObjectRef |
class | ObjectHolder |
This template class implements a object reference with an internal reference counter.
The reference counter is thread-safe.
Further, this implementation allows to define a callback function for release events.
By application of the callback function, a manager can be implemented that allows to store several ObjectRef objects in a managed list.
The manager can used this list to provide instances of specific ObjectRef objects on demand.
Due to the callback function, the manager will be informed whenever an ObjectRef object can be removed from the managed list so that the real object (which is encapsulated by the ObjectRef) can be released automatically.
The following code snippet demonstrates the application:
T | Type of the object to be encapsulated by this object reference |
typedef Callback<void, const T*> Ocean::ObjectRef< T >::ReleaseCallback |
Definition of a release callback function.
The first parameter determines the object for that the release event is invoked.
|
default |
Creates an empty ObjectRef object.
|
inline |
|
inlinenoexcept |
Move constructor.
object | The object to be moved |
|
inlineexplicit |
Creates a new ObjectRef holding a given object.
Beware: The given object will be released by this object reference!
object | The object to store |
|
inline |
Creates a new ObjectRef holding and managing a given object.
This constructor also requests a release callback event.
This callback event will be invoked after the internal reference counter of this object has been decremented and is equal to 1 afterwards.
Thus, the release callback provides an information that in the moment of the callback only one instance of the ObjectRef exists.
Therefore, this callback can be used to release an ObjectRef object which is stored in e.g. a managed list so that finally the reference counter will be zero and the stored object will be released.
Beware: The given object will be released by this object reference!
|
inline |
Destructs an object reference object and releases the internal object if possible.
|
inlinestaticprotected |
Destroys the object located in the ObjectHolder object.
This function is used to get access to the protected delete operator of the internal encapsulated object.
object | the object to destroy |
Returns a reference to the internal object forcing to a specified type.
Beware: Check whether this reference holds a valid internal object before calling this function!
Beware: Make sure the forced type is matching the internal object!
|
inline |
Returns whether this object reference holds no internal object.
|
inline |
Returns whether there is no other object reference but this one.
|
inlineexplicit |
Returns whether this object reference holds an internal object.
|
inline |
Returns whether two object references are not equal.
objectRef | Right object reference |
|
inline |
Returns a reference to the internal object if existing.
Beware: Check whether this reference holds an internal object before calling this function!
|
inline |
Returns a point to the internal object if existing.
Beware: Check whether this reference holds an internal object before calling this function!
|
inline |
Returns whether the left object is less than the right one.
objectRef | Right operand |
|
inline |
Assign operator.
objectRef | Right object reference to assign |
|
inlinenoexcept |
Move operator.
right | The right object to assign |
|
inline |
Returns whether two object references are holds the same internal object.
objectRef | Right object reference |
|
inline |
Returns a pointer to the objects that is encapsulated by this wrapper.
|
inline |
Releases the internal object, if any.
Beware: After the release the object can not be accessed anymore!
|
friend |
|
protected |
Pointer to the object holder.