GEOSX
Public Member Functions | List of all members
geos::ReferenceWrapper< T > Class Template Reference

#include <ReferenceWrapper.hpp>

Public Member Functions

 ReferenceWrapper ()
 Default constructor sets m_ref to nullptr.
 
 ReferenceWrapper (T &source) noexcept
 Constructor that sets m_ref to address of input. More...
 
 ~ReferenceWrapper ()=default
 Default destructor.
 
 ReferenceWrapper (ReferenceWrapper const &source)
 Copy constructor copies the source m_ref to the new m_ref. More...
 
 ReferenceWrapper (ReferenceWrapper &&source)
 Move constructor copies the source m_ref to the new m_ref. More...
 
ReferenceWrapperoperator= (ReferenceWrapper const &source)
 Copy assignment operator. More...
 
template<typename T_RHS , typename U = T>
std::enable_if< !std::is_const< U >::value, ReferenceWrapper & >::type operator= (T_RHS const &rhs)
 Assignment operator. More...
 
ReferenceWrapperoperator= (T &&source)
 Move assignment operator. More...
 
 operator T& ()
 User defined conversion to T &.
 
 operator T const & () const
 User defined conversion to T const &
 
void set (T &source)
 Set the address that m_ref points to. More...
 
void set (T *source)
 Set the address that m_ref points to. More...
 
T & get ()
 Accessor for m_ref. More...
 
const T & get () const
 Const accessor for m_ref. More...
 
bool isValid () const
 Check if reference is initialized. More...
 
const T * getPtr () const
 Const accessor for m_ref. More...
 
template<typename ... ARGS>
std::result_of< T &(ARGS &&...) >::type operator() (ARGS &&... args)
 A pass thru parenthesis operator which calls underlying T::operator(). More...
 
template<typename ... ARGS>
std::result_of< T const &(ARGS &&...) >::type operator() (ARGS &&... args) const
 A pass thru parenthesis operator which calls underlying T::operator(). More...
 

Detailed Description

template<typename T>
class geos::ReferenceWrapper< T >

Template Parameters
Typethat is wrapped

This class manages a pointer to the templated type, but provides a reference-like interface, thus negating the requirement to dereference the object. The primary use for this is for nested arrays that hold pointers at the last level, but allows for reference-like usage. For instance, consider a collection of object that you would like to refer to thought an array of pointers.

array1d< ReferenceWrapper< array1d< double > > > arr;

where the array::operator[] exists. The ReferenceWrapper allows

arr[index1][index2]

note: this is really only useful for heavy array that hold their own data. For light arrays that hold pointers to their data, then this is unnecessary as a copy of the array does not trigger a deep copy.

Definition at line 48 of file ReferenceWrapper.hpp.

Constructor & Destructor Documentation

◆ ReferenceWrapper() [1/3]

template<typename T >
geos::ReferenceWrapper< T >::ReferenceWrapper ( T &  source)
inlinenoexcept

Constructor that sets m_ref to address of input.

Parameters
[in]sourceobject to wrap

Definition at line 64 of file ReferenceWrapper.hpp.

◆ ReferenceWrapper() [2/3]

template<typename T >
geos::ReferenceWrapper< T >::ReferenceWrapper ( ReferenceWrapper< T > const &  source)
inline

Copy constructor copies the source m_ref to the new m_ref.

Parameters
[in]sourceobject to copy

Definition at line 78 of file ReferenceWrapper.hpp.

◆ ReferenceWrapper() [3/3]

template<typename T >
geos::ReferenceWrapper< T >::ReferenceWrapper ( ReferenceWrapper< T > &&  source)
inline

Move constructor copies the source m_ref to the new m_ref.

Parameters
[in,out]sourceobject to move from

Definition at line 87 of file ReferenceWrapper.hpp.

Member Function Documentation

◆ get() [1/2]

template<typename T >
T& geos::ReferenceWrapper< T >::get ( )
inline

Accessor for m_ref.

Returns
reference to wrapped value

Definition at line 175 of file ReferenceWrapper.hpp.

◆ get() [2/2]

template<typename T >
const T& geos::ReferenceWrapper< T >::get ( ) const
inline

Const accessor for m_ref.

Returns
const reference to wrapped value

Definition at line 184 of file ReferenceWrapper.hpp.

◆ getPtr()

template<typename T >
const T* geos::ReferenceWrapper< T >::getPtr ( ) const
inline

Const accessor for m_ref.

Returns
const reference to wrapped value

Definition at line 202 of file ReferenceWrapper.hpp.

◆ isValid()

template<typename T >
bool geos::ReferenceWrapper< T >::isValid ( ) const
inline

Check if reference is initialized.

Returns
true if the object has been initialized with a value, false otherwise

Definition at line 193 of file ReferenceWrapper.hpp.

◆ operator()() [1/2]

template<typename T >
template<typename ... ARGS>
std::result_of< T & (ARGS&&...) >::type geos::ReferenceWrapper< T >::operator() ( ARGS &&...  args)
inline

A pass thru parenthesis operator which calls underlying T::operator().

Template Parameters
variadictypes to pass through to T::operator()
Parameters
argsvariadic params to pass through to T::operator()
Returns
the return type of T::operator()

Definition at line 250 of file ReferenceWrapper.hpp.

◆ operator()() [2/2]

template<typename T >
template<typename ... ARGS>
std::result_of< T const&(ARGS&&...) >::type geos::ReferenceWrapper< T >::operator() ( ARGS &&...  args) const
inline

A pass thru parenthesis operator which calls underlying T::operator().

Template Parameters
variadictypes to pass through to T::operator()
Parameters
argsvariadic params to pass through to T::operator()
Returns
the return type of T::operator() const

Definition at line 263 of file ReferenceWrapper.hpp.

◆ operator=() [1/3]

template<typename T >
ReferenceWrapper& geos::ReferenceWrapper< T >::operator= ( ReferenceWrapper< T > const &  source)
inline

Copy assignment operator.

Parameters
[in]sourceobject to copy
Returns

Definition at line 98 of file ReferenceWrapper.hpp.

◆ operator=() [2/3]

template<typename T >
ReferenceWrapper& geos::ReferenceWrapper< T >::operator= ( T &&  source)
inline

Move assignment operator.

Parameters
[in,out]sourcethe rhs value to be moved
Returns
reference to this object

Sets the value that m_ref refers to to the value of the rhs.

Definition at line 131 of file ReferenceWrapper.hpp.

◆ operator=() [3/3]

template<typename T >
template<typename T_RHS , typename U = T>
std::enable_if< !std::is_const< U >::value, ReferenceWrapper & >::type geos::ReferenceWrapper< T >::operator= ( T_RHS const &  rhs)
inline

Assignment operator.

Template Parameters
T_RHStype of the rhs
Udummy template parameter to enable SFINAE stuff
Parameters
[in]rhsvalue to be copied
Returns
*this

Calls m_ref->operator=() to allow for any type on the rhs if m_ref->operator=() has a valid overload for T_RHS.

Definition at line 118 of file ReferenceWrapper.hpp.

◆ set() [1/2]

template<typename T >
void geos::ReferenceWrapper< T >::set ( T &  source)
inline

Set the address that m_ref points to.

Parameters
[in]sourcereference to object that wrapper will refer to

Definition at line 157 of file ReferenceWrapper.hpp.

◆ set() [2/2]

template<typename T >
void geos::ReferenceWrapper< T >::set ( T *  source)
inline

Set the address that m_ref points to.

Parameters
[in]sourcepointer to object that wrapper will refer to

Definition at line 166 of file ReferenceWrapper.hpp.


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