mod_servlet
C++Servlets
 All Classes Files Functions Variables Typedefs Macros Pages
servlet::optional_ptr< T > Class Template Reference

Class implements smart pointer with optional ownership. More...

#include <optional.h>

Public Types

typedef T value_type
 Type definition for value type.
 
typedef T * pointer
 Type definition for pointer type.
 
typedef const T * const_pointer
 Type definition for const pointer type.
 

Public Member Functions

constexpr optional_ptr ()
 Default constructor. More...
 
constexpr optional_ptr (T *ptr, bool owner=false)
 Constructor which creates the object with a given pointer and specified ownership. More...
 
constexpr optional_ptr (const optional_ptr &other)=delete
 Copy contructor. More...
 
constexpr optional_ptr (optional_ptr &&other)
 Move constructor. More...
 
 ~optional_ptr () noexcept
 Destructor. More...
 
constexpr void clear ()
 Clears the object. More...
 
constexpr optional_ptroperator= (const optional_ptr &other)=delete
 Copy is prohibited.
 
constexpr optional_ptroperator= (optional_ptr &&other) noexcept
 Move assignment. More...
 
constexpr optional_ptrassign (T *ptr, bool owner=false)
 Assigns new pointer to this object. More...
 
constexpr operator bool () const noexcept
 Checks whether this object contains valid pointer. More...
 
constexpr bool has_value () const noexcept
 Checks whether this object contains valid pointer. More...
 
constexpr bool is_owner () const noexcept
 Checks whether this object is the owner of the contained pointer. More...
 
constexpr T * operator-> ()
 Accesses the contained pointer. More...
 
constexpr const T * operator-> () const
 const version of pointer accessor More...
 
constexpr T & operator* ()&
 Accesses the contained pointer. More...
 
constexpr const T & operator* () const &
 Accesses the contained pointer. More...
 
constexpr void swap (optional_ptr &other) noexcept
 Swaps the contents with those of other. More...
 
constexpr void reset () noexcept
 If this object contains a valid pointer, delete that. More...
 

Detailed Description

template<typename T>
class servlet::optional_ptr< T >

Class implements smart pointer with optional ownership.

If the object owns the contained pointer it will delete the pointer on destruction, otherwise the contained pointer will not be deleted.

Template Parameters
thetype of the value to manage.

Constructor & Destructor Documentation

template<typename T>
constexpr servlet::optional_ptr< T >::optional_ptr ( )
inline

Default constructor.

Creates empty object with nullptr as the contained pointer.

template<typename T>
constexpr servlet::optional_ptr< T >::optional_ptr ( T *  ptr,
bool  owner = false 
)
inline

Constructor which creates the object with a given pointer and specified ownership.

Parameters
ptrPointer to contain in optional_ptr
ownerOwnership flag.
template<typename T>
constexpr servlet::optional_ptr< T >::optional_ptr ( const optional_ptr< T > &  other)
delete

Copy contructor.

Parameters
otherobject to copy.
template<typename T>
constexpr servlet::optional_ptr< T >::optional_ptr ( optional_ptr< T > &&  other)
inline

Move constructor.

Parameters
otherobject to move.
template<typename T>
servlet::optional_ptr< T >::~optional_ptr ( )
inlinenoexcept

Destructor.

If the object contains the valid pointer and is the owner of it, deletes this pointer. Otherwise, does nothing.

Member Function Documentation

template<typename T>
constexpr optional_ptr& servlet::optional_ptr< T >::assign ( T *  ptr,
bool  owner = false 
)
inline

Assigns new pointer to this object.

If this object already contains a valid pointer and is the owner it will delelete it before the assignment.

Parameters
ptrnew pointer to assign
ownerownership flag
Returns
self
template<typename T>
constexpr void servlet::optional_ptr< T >::clear ( )
inline

Clears the object.

This method will delete the contained pointer if it is an owner, drop the * pointer to nullptr and reset the ownership flag to false

template<typename T>
constexpr bool servlet::optional_ptr< T >::has_value ( ) const
inlinenoexcept

Checks whether this object contains valid pointer.

Returns
true if this object contains valid pointer, false otherwise.
template<typename T>
constexpr bool servlet::optional_ptr< T >::is_owner ( ) const
inlinenoexcept

Checks whether this object is the owner of the contained pointer.

Returns
true if this object is the owner of the contained pointer, false otherwise.
template<typename T>
constexpr servlet::optional_ptr< T >::operator bool ( ) const
inlineexplicitnoexcept

Checks whether this object contains valid pointer.

Returns
true if this object contains valid pointer, false otherwise.
See Also
has_value
template<typename T>
constexpr T& servlet::optional_ptr< T >::operator* ( )
inline

Accesses the contained pointer.

Returns
reference to contained value.
See Also
has_value
Exceptions
null_pointer_exceptionif the contained pointer is nullptr.
template<typename T>
constexpr const T& servlet::optional_ptr< T >::operator* ( ) const
inline

Accesses the contained pointer.

Returns
const reference to contained value.
See Also
has_value
Exceptions
null_pointer_exceptionif the contained pointer is nullptr.
template<typename T>
constexpr T* servlet::optional_ptr< T >::operator-> ( )
inline

Accesses the contained pointer.

Returns
contained pointer.
Exceptions
null_pointer_exceptionif the contained pointer is nullptr.
template<typename T>
constexpr const T* servlet::optional_ptr< T >::operator-> ( ) const
inline

const version of pointer accessor

Returns
contained const pointer.
Exceptions
null_pointer_exceptionif the contained pointer is nullptr.
template<typename T>
constexpr optional_ptr& servlet::optional_ptr< T >::operator= ( optional_ptr< T > &&  other)
inlinenoexcept

Move assignment.

If this object contains valid pointer and is the owner it will delete it before the assignment.

Parameters
otherthe object to move
Returns
self
template<typename T>
constexpr void servlet::optional_ptr< T >::reset ( )
inlinenoexcept

If this object contains a valid pointer, delete that.

Otherwise, there are no effects.

See Also
clear
template<typename T>
constexpr void servlet::optional_ptr< T >::swap ( optional_ptr< T > &  other)
inlinenoexcept

Swaps the contents with those of other.

Parameters
otherthe object to exchange the contents with

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