Ocean
Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction > Class Template Reference

This class wraps an unmanaged object (or reference) which needs to be released after usage. More...

Inheritance diagram for Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >:

Public Member Functions

 ScopedObjectT ()=default
 Default constructor creating an object with invalid object. More...
 
 ScopedObjectT (ScopedObjectT< T, TReleaseValue, TReleaseFunction > &&scopedObject) noexcept
 Move constructor. More...
 
 ScopedObjectT (T &&object, TReleaseFunction &&releaseFunction) noexcept
 Creates a new scoped object. More...
 
 ScopedObjectT (T &&object, TReleaseFunction &&releaseFunction, const bool useReleaseFunction) noexcept
 Creates a new scoped object. More...
 
 ScopedObjectT (const T &object, TReleaseFunction &&releaseFunction) noexcept
 Creates a new scoped object. More...
 
 ScopedObjectT (const T &object, TReleaseFunction &&releaseFunction, const bool useReleaseFunction) noexcept
 Creates a new scoped object. More...
 
 ~ScopedObjectT ()
 Destructs this scoped object and releases the internal wrapped object. More...
 
bool isValid () const
 Returns whether this scoped object holds a valid release function (which will be invoked once the object is released). More...
 
const T & object () const
 Returns the wrapped object. More...
 
const T & operator-> () const
 Arrow operator returning the wrapped object. More...
 
const T & operator* () const
 De-reference operator returning the wrapped object. More...
 
void release ()
 Explicitly releases the wrapped object. More...
 
ScopedObjectT< T, TReleaseValue, TReleaseFunction > & operator= (ScopedObjectT< T, TReleaseValue, TReleaseFunction > &&scopedObject) noexcept
 Move operator. More...
 
 operator const T & () const
 Returns the wrapped object. More...
 

Protected Member Functions

 ScopedObjectT (const ScopedObjectT< T, TReleaseValue, TReleaseFunction > &)=delete
 Disabled copy constructor. More...
 
ScopedObjectT< T, TReleaseValue, TReleaseFunction > & operator= (const ScopedObjectT< T, TReleaseValue, TReleaseFunction > &)=delete
 Disabled assign operator. More...
 

Protected Attributes

object_ = T()
 The wrapped reference. More...
 
TReleaseFunction releaseFunction_ = TReleaseFunction()
 The function used to release the wrapped object. More...
 

Detailed Description

template<typename T, typename TReleaseValue = T, typename TReleaseFunction = void(*)(TReleaseValue)>
class Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >

This class wraps an unmanaged object (or reference) which needs to be released after usage.

The release function can be defined at runtime.

Template Parameters
TThe data type of the wrapped object
TReleaseValueThe optional explicit data type of the object to be released
TReleaseFunctionThe data type of the release function
See also
ScopedObjectCompileTime.

Constructor & Destructor Documentation

◆ ScopedObjectT() [1/7]

template<typename T , typename TReleaseValue = T, typename TReleaseFunction = void(*)(TReleaseValue)>
Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::ScopedObjectT ( )
default

Default constructor creating an object with invalid object.

◆ ScopedObjectT() [2/7]

template<typename T , typename TReleaseValue , typename TReleaseFunction >
Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::ScopedObjectT ( ScopedObjectT< T, TReleaseValue, TReleaseFunction > &&  scopedObject)
noexcept

Move constructor.

Parameters
scopedObjectThe scoped object to be moved

◆ ScopedObjectT() [3/7]

template<typename T , typename TReleaseValue , typename TReleaseFunction >
Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::ScopedObjectT ( T &&  object,
TReleaseFunction &&  releaseFunction 
)
noexcept

Creates a new scoped object.

Parameters
objectThe object to be wrapped
releaseFunctionThe release function

◆ ScopedObjectT() [4/7]

template<typename T , typename TReleaseValue , typename TReleaseFunction >
Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::ScopedObjectT ( T &&  object,
TReleaseFunction &&  releaseFunction,
const bool  useReleaseFunction 
)
noexcept

Creates a new scoped object.

This constructor allows to decide at runtime whether the release function will be used or not.

Parameters
objectThe object to be wrapped
releaseFunctionThe release function
useReleaseFunctionTrue, to use the provided release function; False, to ignore the provided release function (so that the wrapped object will never be released)

◆ ScopedObjectT() [5/7]

template<typename T , typename TReleaseValue , typename TReleaseFunction >
Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::ScopedObjectT ( const T &  object,
TReleaseFunction &&  releaseFunction 
)
noexcept

Creates a new scoped object.

Parameters
objectThe object to be wrapped
releaseFunctionThe release function

◆ ScopedObjectT() [6/7]

template<typename T , typename TReleaseValue , typename TReleaseFunction >
Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::ScopedObjectT ( const T &  object,
TReleaseFunction &&  releaseFunction,
const bool  useReleaseFunction 
)
noexcept

Creates a new scoped object.

This constructor allows to decide at runtime whether the release function will be used or not.

Parameters
objectThe object to be wrapped
releaseFunctionThe release function
useReleaseFunctionTrue, to use the provided release function; False, to ignore the provided release function (so that the wrapped object will never be released)

◆ ~ScopedObjectT()

template<typename T , typename TReleaseValue , typename TReleaseFunction >
Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::~ScopedObjectT

Destructs this scoped object and releases the internal wrapped object.

◆ ScopedObjectT() [7/7]

template<typename T , typename TReleaseValue = T, typename TReleaseFunction = void(*)(TReleaseValue)>
Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::ScopedObjectT ( const ScopedObjectT< T, TReleaseValue, TReleaseFunction > &  )
protecteddelete

Disabled copy constructor.

Member Function Documentation

◆ isValid()

template<typename T , typename TReleaseValue , typename TReleaseFunction >
bool Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::isValid

Returns whether this scoped object holds a valid release function (which will be invoked once the object is released).

Returns
True, if so

◆ object()

template<typename T , typename TReleaseValue , typename TReleaseFunction >
const T & Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::object

Returns the wrapped object.

Returns
The wrapped object

◆ operator const T &()

template<typename T , typename TReleaseValue , typename TReleaseFunction >
Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::operator const T &

Returns the wrapped object.

Returns
The wrapped object

◆ operator*()

template<typename T , typename TReleaseValue , typename TReleaseFunction >
const T & Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::operator*

De-reference operator returning the wrapped object.

Ensure that the object is valid before calling this operator.

Returns
The wrapped object
See also
isValid().

◆ operator->()

template<typename T , typename TReleaseValue , typename TReleaseFunction >
const T & Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::operator->

Arrow operator returning the wrapped object.

Ensure that the object is valid before calling this operator.

Returns
The wrapped object
See also
isValid().

◆ operator=() [1/2]

template<typename T , typename TReleaseValue = T, typename TReleaseFunction = void(*)(TReleaseValue)>
ScopedObjectT<T, TReleaseValue, TReleaseFunction>& Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::operator= ( const ScopedObjectT< T, TReleaseValue, TReleaseFunction > &  )
protecteddelete

Disabled assign operator.

Returns
Reference to this object

◆ operator=() [2/2]

template<typename T , typename TReleaseValue , typename TReleaseFunction >
ScopedObjectT< T, TReleaseValue, TReleaseFunction > & Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::operator= ( ScopedObjectT< T, TReleaseValue, TReleaseFunction > &&  scopedObject)
noexcept

Move operator.

Parameters
scopedObjectThe scoped object to be moved
Returns
Reference to this object

◆ release()

template<typename T , typename TReleaseValue , typename TReleaseFunction >
void Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::release

Explicitly releases the wrapped object.

Field Documentation

◆ object_

template<typename T , typename TReleaseValue = T, typename TReleaseFunction = void(*)(TReleaseValue)>
T Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::object_ = T()
protected

The wrapped reference.

◆ releaseFunction_

template<typename T , typename TReleaseValue = T, typename TReleaseFunction = void(*)(TReleaseValue)>
TReleaseFunction Ocean::ScopedObjectT< T, TReleaseValue, TReleaseFunction >::releaseFunction_ = TReleaseFunction()
protected

The function used to release the wrapped object.


The documentation for this class was generated from the following file: