openPMD-api
Public Types | Public Member Functions | Public Attributes | List of all members
openPMD::auxiliary::Variant< T_DTYPES, T > Class Template Reference

Generic object to store a set of datatypes in without losing type safety. More...

#include <Variant.hpp>

Public Types

using resource = variantSrc::variant< T ... >
 

Public Member Functions

 Variant (resource r)
 Construct a lightweight wrapper around a generic object that indicates the concrete datatype of the specific object stored. More...
 
template<typename U >
get () const
 Retrieve a stored specific object of known datatype with ensured type-safety. More...
 
resource getResource () const
 Retrieve the stored generic object. More...
 
constexpr size_t index () const noexcept
 Retrieve the index of the alternative that is currently been held. More...
 

Public Attributes

T_DTYPES dtype
 

Detailed Description

template<class T_DTYPES, typename ... T>
class openPMD::auxiliary::Variant< T_DTYPES, T >

Generic object to store a set of datatypes in without losing type safety.

Template Parameters
T_DTYPESEnumeration of datatypes to be stored and identified.
TVaraidic template argument list of datatypes to be stored.

Constructor & Destructor Documentation

◆ Variant()

template<class T_DTYPES , typename ... T>
openPMD::auxiliary::Variant< T_DTYPES, T >::Variant ( resource  r)
inline

Construct a lightweight wrapper around a generic object that indicates the concrete datatype of the specific object stored.

Note
Gerneric objects can only generated implicitly if their datatype is contained in T_DTYPES.
Parameters
rGeneric object to be stored.

Member Function Documentation

◆ get()

template<class T_DTYPES , typename ... T>
template<typename U >
U openPMD::auxiliary::Variant< T_DTYPES, T >::get ( ) const
inline

Retrieve a stored specific object of known datatype with ensured type-safety.

Exceptions
std::bad_variant_accessif stored object is not of type U.
Template Parameters
UType of the object to be retrieved.
Returns
Copy of the retrieved object of type U.

◆ getResource()

template<class T_DTYPES , typename ... T>
resource openPMD::auxiliary::Variant< T_DTYPES, T >::getResource ( ) const
inline

Retrieve the stored generic object.

Returns
Copy of the stored generic object.

◆ index()

template<class T_DTYPES , typename ... T>
constexpr size_t openPMD::auxiliary::Variant< T_DTYPES, T >::index ( ) const
inlineconstexprnoexcept

Retrieve the index of the alternative that is currently been held.

Returns
zero-based index

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