LArSoft  v09_90_00
Liquid Argon Software toolkit - https://larsoft.org/
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

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 (pointer_t &&from)
 Constructor and assignment from a unique pointer: steal the content. More...
 
MovableClassWrapperoperator= (pointer_t &&from)
 Constructor and assignment from a unique pointer: steal the content. More...
 
bool valid () const
 Returns whether there is a valid pointer. More...
 
 operator bool () const
 Returns whether there is a valid pointer. More...
 

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...
 

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 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 57 of file ProviderList.h.

Member Typedef Documentation

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

contained type

Definition at line 58 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 60 of file ProviderList.h.

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

this type

Definition at line 59 of file ProviderList.h.

Constructor & Destructor Documentation

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

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

Definition at line 71 of file ProviderList.h.

71 : 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 74 of file ProviderList.h.

74  : ptr(std::move(from))
75  {}
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 79 of file ProviderList.h.

79 : ptr(std::move(from)) {}
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 89 of file ProviderList.h.

89  : ptr(from.ptr)
90  {}

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 99 of file ProviderList.h.

99 { 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 102 of file ProviderList.h.

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

Returns whether there is a valid pointer.

Definition at line 108 of file ProviderList.h.

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

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

Definition at line 80 of file ProviderList.h.

81  {
82  ptr = std::move(from);
83  return *this;
84  }
template<typename T>
datum_t& testing::details::MovableClassWrapper< T >::ref ( )
inline

Returns a reference to the datum with the correct type.

Definition at line 93 of file ProviderList.h.

93 { 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 96 of file ProviderList.h.

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

Returns whether there is a valid pointer.

Definition at line 106 of file ProviderList.h.

106 { return bool(ptr); }

Friends And Related Function Documentation

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

Definition at line 63 of file ProviderList.h.

Member Data Documentation

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

Definition at line 112 of file ProviderList.h.

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

type to specify a share constructor

Definition at line 68 of file ProviderList.h.


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