dune-functions 2.9.0
Public Member Functions | List of all members
Dune::Functions::PolymorphicSmallObject< Base, bufferSize > Class Template Reference

A wrapper providing small object optimization with polymorphic types. More...

#include <dune/functions/common/polymorphicsmallobject.hh>

Inheritance diagram for Dune::Functions::PolymorphicSmallObject< Base, bufferSize >:
Inheritance graph

Public Member Functions

 PolymorphicSmallObject ()
 Default constructor. More...
 
template<class Derived , typename std::enable_if< std::is_base_of< Base, std::remove_cv_t< std::remove_reference_t< Derived > > >::value, int >::type = 0>
 PolymorphicSmallObject (Derived &&derived)
 Construct from object. More...
 
 PolymorphicSmallObject (PolymorphicSmallObject &&other) noexcept
 Move constructor from other PolymorphicSmallObject. More...
 
 PolymorphicSmallObject (const PolymorphicSmallObject &other)
 Copy constructor from other PolymorphicSmallObject. More...
 
 ~PolymorphicSmallObject ()
 Destructor. More...
 
PolymorphicSmallObjectoperator= (const PolymorphicSmallObject &other)
 Copy assignment from other PolymorphicSmallObject. More...
 
PolymorphicSmallObjectoperator= (PolymorphicSmallObject &&other) noexcept
 Move assignment from other PolymorphicSmallObject. More...
 
 operator bool () const
 Check if *this is not empty. More...
 
bool bufferUsed () const
 Check if object is stored in internal stack buffer. More...
 
const Base & get () const
 Obtain reference to stored object. More...
 
Base & get ()
 Obtain mutable reference to stored object. More...
 

Detailed Description

template<class Base, size_t bufferSize>
class Dune::Functions::PolymorphicSmallObject< Base, bufferSize >

A wrapper providing small object optimization with polymorphic types.

Template Parameters
BaseBase class type of wrapped objects
bufferSizeSize of small object buffer

This class encapsulates small object optimization for polymorphic types. The type of objects passed to the constructor must be derived from the base class type Base.

If the size of the derived type fits into the static buffer, then the wrapped object is stored there, otherwise it is allocated dynamically.

Notice that this class does implement use type erasure for destructors, copy/move constructors and copy/move assignment. Hence it requires that Base has a virtual destructor.

In order to make the copy constructor work for polymorphic types, Base must provide virtual methods Base* clone() and Base* clone(void*). The former should return a pointer to a dynamically allocated clone, while the latter should call the appropriate placement-new with the passed pointer.

Similarly the polymorphic type has to implement a virtual Base* move(void*) method. This should call placement-new and can std::move all the data but leave the object in a valid and probably unusable state.

Constructor & Destructor Documentation

◆ PolymorphicSmallObject() [1/4]

template<class Base , size_t bufferSize>
Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::PolymorphicSmallObject ( )
inline

Default constructor.

◆ PolymorphicSmallObject() [2/4]

template<class Base , size_t bufferSize>
template<class Derived , typename std::enable_if< std::is_base_of< Base, std::remove_cv_t< std::remove_reference_t< Derived > > >::value, int >::type = 0>
Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::PolymorphicSmallObject ( Derived &&  derived)
inline

Construct from object.

Template Parameters
DerivedType of object to be stored, must be derived from Base
Parameters
derivedObject to be stored

◆ PolymorphicSmallObject() [3/4]

template<class Base , size_t bufferSize>
Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::PolymorphicSmallObject ( PolymorphicSmallObject< Base, bufferSize > &&  other)
inlinenoexcept

Move constructor from other PolymorphicSmallObject.

◆ PolymorphicSmallObject() [4/4]

template<class Base , size_t bufferSize>
Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::PolymorphicSmallObject ( const PolymorphicSmallObject< Base, bufferSize > &  other)
inline

Copy constructor from other PolymorphicSmallObject.

◆ ~PolymorphicSmallObject()

template<class Base , size_t bufferSize>
Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::~PolymorphicSmallObject ( )
inline

Destructor.

Member Function Documentation

◆ bufferUsed()

template<class Base , size_t bufferSize>
bool Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::bufferUsed ( ) const
inline

Check if object is stored in internal stack buffer.

◆ get() [1/2]

template<class Base , size_t bufferSize>
Base & Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::get ( )
inline

Obtain mutable reference to stored object.

◆ get() [2/2]

template<class Base , size_t bufferSize>
const Base & Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::get ( ) const
inline

Obtain reference to stored object.

◆ operator bool()

template<class Base , size_t bufferSize>
Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::operator bool ( ) const
inlineexplicit

Check if *this is not empty.

◆ operator=() [1/2]

template<class Base , size_t bufferSize>
PolymorphicSmallObject & Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::operator= ( const PolymorphicSmallObject< Base, bufferSize > &  other)
inline

Copy assignment from other PolymorphicSmallObject.

◆ operator=() [2/2]

template<class Base , size_t bufferSize>
PolymorphicSmallObject & Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::operator= ( PolymorphicSmallObject< Base, bufferSize > &&  other)
inlinenoexcept

Move assignment from other PolymorphicSmallObject.


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