Loading...
Searching...
No Matches
Dune::Functions::PolymorphicSmallObject< Base, bufferSize > Class Template Reference
Utility | Utility » Utilities for type-erasure

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

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

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

## Public Member Functions

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

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

  Base | Base class type of wrapped objects
  bufferSize | Size 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, std::enable_if_t< std::is_base_of_v< Base, std::remove_cv_t< std::remove_reference_t< Derived > > >, int > = 0>

Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::PolymorphicSmallObject | ( | Derived && | derived | ) |

inline

Construct from object.

Template Parameters

  Derived | Type of object to be stored, must be derived from Base

Parameters

  derived | Object to be stored

## PolymorphicSmallObject() [3/4]

template<class Base, size_t bufferSize>

Dune::Functions::PolymorphicSmallObject< Base, bufferSize >::PolymorphicSmallObject | ( | PolymorphicSmallObject< Base, bufferSize > && | other | ) |

inline noexcept

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

inline explicit

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

inline noexcept

Move assignment from other PolymorphicSmallObject.

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

- polymorphicsmallobject.hh