libebml_ng
Public Member Functions | List of all members
ebml::flexible_ptr< T > Class Template Reference

A flexible pointer that can store either a strong (shared) or weak pointer. More...

#include <flexptr.h>

Public Member Functions

 flexible_ptr ()
 Default constructor. Initializes with an empty strong pointer. More...
 
 flexible_ptr (const std::nullptr_t &)
 Constructs a flexible_ptr that is null. More...
 
 flexible_ptr (const flexible_ptr< T > &other)
 Copy constructor. More...
 
 flexible_ptr (flexible_ptr< T > &&other)
 Move constructor. More...
 
 flexible_ptr (const ptr< T > &p)
 Constructs a flexible_ptr from a strong pointer to T. More...
 
 flexible_ptr (ptr< T > &&p)
 Constructs a flexible_ptr from a movable strong pointer to T. More...
 
 flexible_ptr (const ptr< const T > &p)
 Constructs a flexible_ptr from a strong pointer to a const T. More...
 
 flexible_ptr (ptr< const T > &&p)
 Constructs a flexible_ptr from a movable strong pointer to a const T. More...
 
 flexible_ptr (const wptr< T > &p)
 Constructs a flexible_ptr from a weak pointer to T. More...
 
 flexible_ptr (wptr< T > &&p)
 Constructs a flexible_ptr from a movable weak pointer to T. More...
 
 flexible_ptr (const wptr< const T > &p)
 Constructs a flexible_ptr from a weak pointer to a const T. More...
 
 flexible_ptr (wptr< const T > &&p)
 Constructs a flexible_ptr from a movable weak pointer to a const T. More...
 
 ~flexible_ptr ()
 Destructor. More...
 
flexible_ptr< T > & operator= (const flexible_ptr< T > &other)
 Copy assignment operator. More...
 
flexible_ptr< T > & operator= (flexible_ptr< T > &&other)
 Move assignment operator. More...
 
flexible_ptr< T > & operator= (const ptr< T > &other)
 Assignment operator from a strong pointer of type ptr<T>. More...
 
flexible_ptr< T > & operator= (ptr< T > &&other)
 Assignment operator from a movable strong pointer of type ptr<T>. More...
 
flexible_ptr< T > & operator= (const wptr< T > &other)
 Assignment operator from a weak pointer of type wptr<T>. More...
 
flexible_ptr< T > & operator= (wptr< T > &&other)
 Assignment operator from a movable weak pointer of type wptr<T>. More...
 
flexible_ptr< T > & operator= (const ptr< const T > &other)
 Assignment operator from a strong pointer of type ptr<const T>. More...
 
flexible_ptr< T > & operator= (ptr< const T > &&other)
 Assignment operator from a movable strong pointer of type ptr<const T>. More...
 
flexible_ptr< T > & operator= (const wptr< const T > &other)
 Assignment operator from a weak pointer of type wptr<const T>. More...
 
flexible_ptr< T > & operator= (wptr< const T > &&other)
 Assignment operator from a movable weak pointer of type wptr<const T>. More...
 
flexible_ptr< T > & operator= (const std::nullptr_t &)
 Assignment operator from nullptr. More...
 
bool is_const () const
 Checks whether the stored pointer is pointing to a const object. More...
 
bool is_weak () const
 Checks whether the stored pointer is a weak pointer. More...
 
ptr< T > get () const
 Retrieves the stored strong pointer. More...
 
ptr< const T > cget () const
 Retrieves the stored strong pointer to a const T. More...
 
bool notnull () const
 Checks whether the stored pointer is not null. More...
 

Detailed Description

template<typename T>
class ebml::flexible_ptr< T >

A flexible pointer that can store either a strong (shared) or weak pointer.

The flexible_ptr class provides the ability to select at runtime whether the underlying stored pointer is a strong pointer (ebml_shared_ptr) or a weak pointer (ebml_weak_ptr). It also supports both mutable and const types.

Template Parameters
TType of the managed object.

Constructor & Destructor Documentation

◆ flexible_ptr() [1/12]

template<typename T>
ebml::flexible_ptr< T >::flexible_ptr ( )
inline

Default constructor. Initializes with an empty strong pointer.

◆ flexible_ptr() [2/12]

template<typename T>
ebml::flexible_ptr< T >::flexible_ptr ( const std::nullptr_t &  )
inline

Constructs a flexible_ptr that is null.

◆ flexible_ptr() [3/12]

template<typename T>
ebml::flexible_ptr< T >::flexible_ptr ( const flexible_ptr< T > &  other)
inline

Copy constructor.

Creates a flexible_ptr by copying from another.

Parameters
otherThe source flexible_ptr.

◆ flexible_ptr() [4/12]

template<typename T>
ebml::flexible_ptr< T >::flexible_ptr ( flexible_ptr< T > &&  other)
inline

Move constructor.

Transfers ownership from another flexible_ptr.

Parameters
otherThe source flexible_ptr to move.

◆ flexible_ptr() [5/12]

template<typename T>
ebml::flexible_ptr< T >::flexible_ptr ( const ptr< T > &  p)
inline

Constructs a flexible_ptr from a strong pointer to T.

Parameters
pThe strong pointer (ptr<T>) to be stored.

◆ flexible_ptr() [6/12]

template<typename T>
ebml::flexible_ptr< T >::flexible_ptr ( ptr< T > &&  p)
inline

Constructs a flexible_ptr from a movable strong pointer to T.

Parameters
pThe strong pointer (ptr<T>) to be moved in.

◆ flexible_ptr() [7/12]

template<typename T>
ebml::flexible_ptr< T >::flexible_ptr ( const ptr< const T > &  p)
inline

Constructs a flexible_ptr from a strong pointer to a const T.

Parameters
pThe strong pointer (ptr<const T>) to be stored.

◆ flexible_ptr() [8/12]

template<typename T>
ebml::flexible_ptr< T >::flexible_ptr ( ptr< const T > &&  p)
inline

Constructs a flexible_ptr from a movable strong pointer to a const T.

Parameters
pThe strong pointer (ptr<const T>) to be moved in.

◆ flexible_ptr() [9/12]

template<typename T>
ebml::flexible_ptr< T >::flexible_ptr ( const wptr< T > &  p)
inline

Constructs a flexible_ptr from a weak pointer to T.

Parameters
pThe weak pointer (wptr<T>) to be stored.

◆ flexible_ptr() [10/12]

template<typename T>
ebml::flexible_ptr< T >::flexible_ptr ( wptr< T > &&  p)
inline

Constructs a flexible_ptr from a movable weak pointer to T.

Parameters
pThe weak pointer (wptr<T>) to be moved in.

◆ flexible_ptr() [11/12]

template<typename T>
ebml::flexible_ptr< T >::flexible_ptr ( const wptr< const T > &  p)
inline

Constructs a flexible_ptr from a weak pointer to a const T.

Parameters
pThe weak pointer (wptr<const T>) to be stored.

◆ flexible_ptr() [12/12]

template<typename T>
ebml::flexible_ptr< T >::flexible_ptr ( wptr< const T > &&  p)
inline

Constructs a flexible_ptr from a movable weak pointer to a const T.

Parameters
pThe weak pointer (wptr<const T>) to be moved in.

◆ ~flexible_ptr()

template<typename T>
ebml::flexible_ptr< T >::~flexible_ptr ( )
inline

Destructor.

Calls the appropriate destructor for the underlying pointer.

Member Function Documentation

◆ cget()

template<typename T>
ptr<const T> ebml::flexible_ptr< T >::cget ( ) const
inline

Retrieves the stored strong pointer to a const T.

Always returns a strong pointer that treats the managed object as const.

Returns
ptr<const T> The strong const pointer.
Exceptions
std::runtime_errorif an unexpected flag value is encountered.

◆ get()

template<typename T>
ptr<T> ebml::flexible_ptr< T >::get ( ) const
inline

Retrieves the stored strong pointer.

Returns a strong pointer to T. Throws if the underlying pointer is const.

Returns
ptr<T> The strong pointer to T.
Exceptions
std::runtime_errorif non-const access is requested on a const object.

◆ is_const()

template<typename T>
bool ebml::flexible_ptr< T >::is_const ( ) const
inline

Checks whether the stored pointer is pointing to a const object.

Returns
true if the stored pointer is const, false otherwise.

◆ is_weak()

template<typename T>
bool ebml::flexible_ptr< T >::is_weak ( ) const
inline

Checks whether the stored pointer is a weak pointer.

Returns
true if the stored pointer is weak, false otherwise.

◆ notnull()

template<typename T>
bool ebml::flexible_ptr< T >::notnull ( ) const
inline

Checks whether the stored pointer is not null.

The check is performed based on the type of pointed object (strong or weak).

Returns
true if the underlying pointer is non-null (and not expired for weak pointers), false otherwise.
Exceptions
std::runtime_errorif an unexpected flag value is encountered.

◆ operator=() [1/11]

template<typename T>
flexible_ptr<T>& ebml::flexible_ptr< T >::operator= ( const flexible_ptr< T > &  other)
inline

Copy assignment operator.

Assigns from another flexible_ptr.

Parameters
otherThe source flexible_ptr.
Returns
Reference to this flexible_ptr.

◆ operator=() [2/11]

template<typename T>
flexible_ptr<T>& ebml::flexible_ptr< T >::operator= ( flexible_ptr< T > &&  other)
inline

Move assignment operator.

Transfers the pointer held by another flexible_ptr.

Parameters
otherThe source flexible_ptr.
Returns
Reference to this flexible_ptr.

◆ operator=() [3/11]

template<typename T>
flexible_ptr<T>& ebml::flexible_ptr< T >::operator= ( const ptr< T > &  other)
inline

Assignment operator from a strong pointer of type ptr<T>.

Parameters
otherThe strong pointer to assign from.
Returns
Reference to this flexible_ptr.

◆ operator=() [4/11]

template<typename T>
flexible_ptr<T>& ebml::flexible_ptr< T >::operator= ( ptr< T > &&  other)
inline

Assignment operator from a movable strong pointer of type ptr<T>.

Parameters
otherThe strong pointer to move in.
Returns
Reference to this flexible_ptr.

◆ operator=() [5/11]

template<typename T>
flexible_ptr<T>& ebml::flexible_ptr< T >::operator= ( const wptr< T > &  other)
inline

Assignment operator from a weak pointer of type wptr<T>.

Parameters
otherThe weak pointer to assign from.
Returns
Reference to this flexible_ptr.

◆ operator=() [6/11]

template<typename T>
flexible_ptr<T>& ebml::flexible_ptr< T >::operator= ( wptr< T > &&  other)
inline

Assignment operator from a movable weak pointer of type wptr<T>.

Parameters
otherThe weak pointer to move in.
Returns
Reference to this flexible_ptr.

◆ operator=() [7/11]

template<typename T>
flexible_ptr<T>& ebml::flexible_ptr< T >::operator= ( const ptr< const T > &  other)
inline

Assignment operator from a strong pointer of type ptr<const T>.

Parameters
otherThe strong pointer to const T to assign from.
Returns
Reference to this flexible_ptr.

◆ operator=() [8/11]

template<typename T>
flexible_ptr<T>& ebml::flexible_ptr< T >::operator= ( ptr< const T > &&  other)
inline

Assignment operator from a movable strong pointer of type ptr<const T>.

Parameters
otherThe strong pointer to const T to move in.
Returns
Reference to this flexible_ptr.

◆ operator=() [9/11]

template<typename T>
flexible_ptr<T>& ebml::flexible_ptr< T >::operator= ( const wptr< const T > &  other)
inline

Assignment operator from a weak pointer of type wptr<const T>.

Parameters
otherThe weak pointer to assign from.
Returns
Reference to this flexible_ptr.

◆ operator=() [10/11]

template<typename T>
flexible_ptr<T>& ebml::flexible_ptr< T >::operator= ( wptr< const T > &&  other)
inline

Assignment operator from a movable weak pointer of type wptr<const T>.

Parameters
otherThe weak pointer to move in.
Returns
Reference to this flexible_ptr.

◆ operator=() [11/11]

template<typename T>
flexible_ptr<T>& ebml::flexible_ptr< T >::operator= ( const std::nullptr_t &  )
inline

Assignment operator from nullptr.

Resets the flexible_ptr to an empty strong pointer.

Returns
Reference to this flexible_ptr.

Member Data Documentation

◆ const_sp

template<typename T>
ptr<const T> ebml::flexible_ptr< T >::const_sp

Stored strong pointer for const T.

◆ const_wp

template<typename T>
wptr<const T> ebml::flexible_ptr< T >::const_wp

Stored weak pointer for const T.

◆ sp

template<typename T>
ptr<T> ebml::flexible_ptr< T >::sp

Stored strong pointer for mutable T.

◆ wp

template<typename T>
wptr<T> ebml::flexible_ptr< T >::wp

Stored weak pointer for mutable T.


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