Classes | Public Member Functions | Static Public Attributes | Private Types | Private Attributes | Friends | List of all members
testing::details::MovableClassWrapper< T > Class Template Reference

A class containing an owned object. More...

#include <ProviderList.h>

Inheritance diagram for testing::details::MovableClassWrapper< T >:
testing::details::MovableClassWrapperBase testing::details::MovableClassWrapperBase

Classes

struct  share_t
 

Public Member Functions

 MovableClassWrapper ()
 Default constructor: no datum present (move one in later on) More...
 
template<typename U >
 MovableClassWrapper (std::unique_ptr< U > &&from)
 
template<typename U >
 MovableClassWrapper (MovableClassWrapper< U > const &from, share_t)
 Share constructor (kind of copy) More...
 
datum_tref ()
 Returns a reference to the datum with the correct type. More...
 
datum_t const & ref () const
 Returns a constant reference to the datum with the correct type. More...
 
datum_tget ()
 Returns a pointer to the datum with the correct type. More...
 
datum_t const * get () const
 Returns a constant pointer to the datum with the correct type. More...
 
 MovableClassWrapper ()
 Default constructor: no datum present (move one in later on) More...
 
template<typename U >
 MovableClassWrapper (std::unique_ptr< U > &&from)
 
template<typename U >
 MovableClassWrapper (MovableClassWrapper< U > const &from, share_t)
 Share constructor (kind of copy) More...
 
datum_tref ()
 Returns a reference to the datum with the correct type. More...
 
datum_t const & ref () const
 Returns a constant reference to the datum with the correct type. More...
 
datum_tget ()
 Returns a pointer to the datum with the correct type. More...
 
datum_t const * get () const
 Returns a constant pointer to the datum with the correct type. More...
 
 MovableClassWrapper (pointer_t &&from)
 Constructor and assignment from a unique pointer: steal the content. More...
 
MovableClassWrapperoperator= (pointer_t &&from)
 
bool valid () const
 Returns whether there is a valid pointer. More...
 
 operator bool () const
 
 MovableClassWrapper (pointer_t &&from)
 Constructor and assignment from a unique pointer: steal the content. More...
 
MovableClassWrapperoperator= (pointer_t &&from)
 
bool valid () const
 Returns whether there is a valid pointer. More...
 
 operator bool () const
 
- Public Member Functions inherited from testing::details::MovableClassWrapperBase
virtual ~MovableClassWrapperBase ()=default
 
virtual ~MovableClassWrapperBase ()=default
 

Static Public Attributes

static constexpr share_t share = {}
 type to specify a share constructor More...
 

Private Types

using datum_t = T
 contained type More...
 
using this_t = MovableClassWrapper< T >
 this type More...
 
using pointer_t = std::shared_ptr< datum_t >
 pointer storing datum More...
 
using datum_t = T
 contained type More...
 
using this_t = MovableClassWrapper< T >
 this type More...
 
using pointer_t = std::shared_ptr< datum_t >
 pointer storing datum More...
 

Private Attributes

pointer_t ptr
 

Friends

template<typename U >
class MovableClassWrapper
 

Detailed Description

template<typename T>
class testing::details::MovableClassWrapper< T >

A class containing an owned object.

Template Parameters
Ttype of the contained object

Differently from boost::any, T does not have to be copiable nor movable. The price is that the object is dynamically allocated.

Given that we don't require T to be movable and we don't require it to be polymorphic, we need some way to move T and have T recognized as such when put in a mixed container. Hence this wrapper. The price is quite high: two chained dynamic allocations per object (one in the wrapper to provide mobility, the other in the container not to lose polymorphism).

Template Parameters
Ttype of the contained object

Differently from std::any, T does not have to be copiable nor movable. The price is that the object is dynamically allocated.

Given that we don't require T to be movable and we don't require it to be polymorphic, we need some way to move T and have T recognized as such when put in a mixed container. Hence this wrapper. The price is quite high: two chained dynamic allocations per object (one in the wrapper to provide mobility, the other in the container not to lose polymorphism).

Definition at line 58 of file ProviderList.h.

Member Typedef Documentation

template<typename T>
using testing::details::MovableClassWrapper< T >::datum_t = T
private

contained type

Definition at line 59 of file ProviderList.h.

template<typename T>
using testing::details::MovableClassWrapper< T >::datum_t = T
private

contained type

Definition at line 59 of file ProviderList.h.

template<typename T>
using testing::details::MovableClassWrapper< T >::pointer_t = std::shared_ptr<datum_t>
private

pointer storing datum

Definition at line 61 of file ProviderList.h.

template<typename T>
using testing::details::MovableClassWrapper< T >::pointer_t = std::shared_ptr<datum_t>
private

pointer storing datum

Definition at line 61 of file ProviderList.h.

template<typename T>
using testing::details::MovableClassWrapper< T >::this_t = MovableClassWrapper<T>
private

this type

Definition at line 60 of file ProviderList.h.

template<typename T>
using testing::details::MovableClassWrapper< T >::this_t = MovableClassWrapper<T>
private

this type

Definition at line 60 of file ProviderList.h.

Constructor & Destructor Documentation

template<typename U >
MovableClassWrapper ( )
inline

Default constructor: no datum present (move one in later on)

Definition at line 73 of file ProviderList.h.

73 : ptr(std::make_unique<datum_t>()) {}
template<typename T>
template<typename U >
testing::details::MovableClassWrapper< T >::MovableClassWrapper ( std::unique_ptr< U > &&  from)
inline

Definition at line 76 of file ProviderList.h.

76 : ptr(std::move(from)) {}
def move(depos, offset)
Definition: depos.py:107
template<typename T>
testing::details::MovableClassWrapper< T >::MovableClassWrapper ( pointer_t &&  from)
inline

Constructor and assignment from a unique pointer: steal the content.

Definition at line 80 of file ProviderList.h.

80 : ptr(std::move(from)) {}
def move(depos, offset)
Definition: depos.py:107
template<typename T>
template<typename U >
testing::details::MovableClassWrapper< T >::MovableClassWrapper ( MovableClassWrapper< U > const &  from,
share_t   
)
inline

Share constructor (kind of copy)

Definition at line 87 of file ProviderList.h.

87  :
88  ptr(from.ptr) {}
template<typename T>
testing::details::MovableClassWrapper< T >::MovableClassWrapper ( )
inline

Default constructor: no datum present (move one in later on)

Definition at line 73 of file ProviderList.h.

73 : ptr(std::make_unique<datum_t>()) {}
template<typename T>
template<typename U >
testing::details::MovableClassWrapper< T >::MovableClassWrapper ( std::unique_ptr< U > &&  from)
inline

Definition at line 76 of file ProviderList.h.

76 : ptr(std::move(from)) {}
def move(depos, offset)
Definition: depos.py:107
template<typename T>
testing::details::MovableClassWrapper< T >::MovableClassWrapper ( pointer_t &&  from)
inline

Constructor and assignment from a unique pointer: steal the content.

Definition at line 80 of file ProviderList.h.

80 : ptr(std::move(from)) {}
def move(depos, offset)
Definition: depos.py:107
template<typename T>
template<typename U >
testing::details::MovableClassWrapper< T >::MovableClassWrapper ( MovableClassWrapper< U > const &  from,
share_t   
)
inline

Share constructor (kind of copy)

Definition at line 87 of file ProviderList.h.

87  :
88  ptr(from.ptr) {}

Member Function Documentation

template<typename T>
datum_t* testing::details::MovableClassWrapper< T >::get ( )
inline

Returns a pointer to the datum with the correct type.

Definition at line 98 of file ProviderList.h.

98 { return ptr.get(); }
template<typename T>
datum_t* testing::details::MovableClassWrapper< T >::get ( )
inline

Returns a pointer to the datum with the correct type.

Definition at line 98 of file ProviderList.h.

98 { return ptr.get(); }
template<typename T>
datum_t const* testing::details::MovableClassWrapper< T >::get ( ) const
inline

Returns a constant pointer to the datum with the correct type.

Definition at line 101 of file ProviderList.h.

101 { return ptr.get(); }
template<typename T>
datum_t const* testing::details::MovableClassWrapper< T >::get ( ) const
inline

Returns a constant pointer to the datum with the correct type.

Definition at line 101 of file ProviderList.h.

101 { return ptr.get(); }
template<typename T>
testing::details::MovableClassWrapper< T >::operator bool ( ) const
inline

Definition at line 107 of file ProviderList.h.

107 { return valid(); }
bool valid() const
Returns whether there is a valid pointer.
Definition: ProviderList.h:105
template<typename T>
testing::details::MovableClassWrapper< T >::operator bool ( ) const
inline

Definition at line 107 of file ProviderList.h.

107 { return valid(); }
bool valid() const
Returns whether there is a valid pointer.
Definition: ProviderList.h:105
template<typename T>
MovableClassWrapper& testing::details::MovableClassWrapper< T >::operator= ( pointer_t &&  from)
inline

Definition at line 81 of file ProviderList.h.

82  { ptr = std::move(from); return *this; }
def move(depos, offset)
Definition: depos.py:107
template<typename T>
MovableClassWrapper& testing::details::MovableClassWrapper< T >::operator= ( pointer_t &&  from)
inline

Definition at line 81 of file ProviderList.h.

82  { ptr = std::move(from); return *this; }
def move(depos, offset)
Definition: depos.py:107
template<typename T>
datum_t& testing::details::MovableClassWrapper< T >::ref ( )
inline

Returns a reference to the datum with the correct type.

Definition at line 92 of file ProviderList.h.

92 { return *ptr; }
template<typename T>
datum_t& testing::details::MovableClassWrapper< T >::ref ( )
inline

Returns a reference to the datum with the correct type.

Definition at line 92 of file ProviderList.h.

92 { return *ptr; }
template<typename T>
datum_t const& testing::details::MovableClassWrapper< T >::ref ( ) const
inline

Returns a constant reference to the datum with the correct type.

Definition at line 95 of file ProviderList.h.

95 { return *ptr; }
template<typename T>
datum_t const& testing::details::MovableClassWrapper< T >::ref ( ) const
inline

Returns a constant reference to the datum with the correct type.

Definition at line 95 of file ProviderList.h.

95 { return *ptr; }
template<typename T>
bool testing::details::MovableClassWrapper< T >::valid ( ) const
inline

Returns whether there is a valid pointer.

Definition at line 105 of file ProviderList.h.

105 { return bool(ptr); }
int bool
Definition: qglobal.h:345
template<typename T>
bool testing::details::MovableClassWrapper< T >::valid ( ) const
inline

Returns whether there is a valid pointer.

Definition at line 105 of file ProviderList.h.

105 { return bool(ptr); }
int bool
Definition: qglobal.h:345

Friends And Related Function Documentation

template<typename T>
template<typename U >
friend class MovableClassWrapper
friend

Definition at line 65 of file ProviderList.h.

Member Data Documentation

template<typename T>
pointer_t testing::details::MovableClassWrapper< T >::ptr
private

Definition at line 111 of file ProviderList.h.

template<typename T>
static constexpr share_t testing::details::MovableClassWrapper< T >::share = {}
static

type to specify a share constructor

Definition at line 70 of file ProviderList.h.


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