SPH
Classes | Public Member Functions | Friends | List of all members
Dynamic Class Reference

Convenient object for storing a single value of different types. More...

#include <Dynamic.h>

Public Member Functions

 Dynamic ()
 Construct an uninitialized value. More...
 
 ~Dynamic ()
 Needs to be in .cpp to compile with clang, for some reason. More...
 
template<typename T , typename = std::enable_if_t<!std::is_same<std::decay_t<T>, Dynamic>::value>>
 Dynamic (T &&value)
 Contruct value from one of possible value types. More...
 
 Dynamic (const Dynamic &other)
 
 Dynamic (Dynamic &&other)
 
template<typename T , typename = std::enable_if_t<DynamicVariant::canHold<T>()>>
Dynamicoperator= (T &&rhs)
 Assign one of possible value types into the value. More...
 
Dynamicoperator= (const Dynamic &other)
 
Dynamicoperator= (Dynamic &&other)
 
template<typename T , typename = std::enable_if_t<DynamicVariant::canHold<T>()>>
INLINE T & get ()
 Returns the reference to the stored value given its type. More...
 
template<typename T , typename = std::enable_if_t<DynamicVariant::canHold<T>()>>
const T & get () const
 Returns the const reference to the stored value given its type. More...
 
template<typename T , typename = std::enable_if_t<DynamicVariant::canHold<T>()>>
 operator T& ()
 Conversion operator to one of stored types. More...
 
template<typename T , typename = std::enable_if_t<DynamicVariant::canHold<T>()>>
 operator const T & () const
 Coversion operator to one of stored types, const version. More...
 
Float getScalar () const
 Converts the stored value into a single number, using one of possible conversions. More...
 
DynamicId getType () const
 
bool empty () const
 Checks if the value has been initialized. More...
 
 operator bool () const
 
bool operator! () const
 
template<typename T , typename = std::enable_if_t<DynamicVariant::canHold<T>()>>
bool operator== (const T &value) const
 Equality operator with one of stored types. More...
 

Friends

std::ostream & operator<< (std::ostream &stream, const Dynamic &value)
 Prints the currently stored value into the stream, using << operator of its type. More...
 

Detailed Description

Convenient object for storing a single value of different types.

Object can currently store scalar, vector, tensor, unsigned integer and MinMaxMean. This is intended mainly for logging and output routines, as the object provides generic way to store different types and print stored values. There is no need to pass types as template arguments, so the object Value is a suitable return value or parameter of virtual functions (that cannot be templated).

Definition at line 35 of file Dynamic.h.

Constructor & Destructor Documentation

◆ Dynamic() [1/4]

NAMESPACE_SPH_BEGIN Dynamic::Dynamic ( )
default

Construct an uninitialized value.

◆ ~Dynamic()

Dynamic::~Dynamic ( )
default

Needs to be in .cpp to compile with clang, for some reason.

◆ Dynamic() [2/4]

template<typename T , typename = std::enable_if_t<!std::is_same<std::decay_t<T>, Dynamic>::value>>
Dynamic::Dynamic ( T &&  value)
inline

Contruct value from one of possible value types.

Definition at line 58 of file Dynamic.h.

◆ Dynamic() [3/4]

Dynamic::Dynamic ( const Dynamic other)
inline

Definition at line 61 of file Dynamic.h.

◆ Dynamic() [4/4]

Dynamic::Dynamic ( Dynamic &&  other)
inline

Definition at line 64 of file Dynamic.h.

Member Function Documentation

◆ empty()

bool Dynamic::empty ( ) const
inline

Checks if the value has been initialized.

Definition at line 120 of file Dynamic.h.

◆ get() [1/2]

template<typename T , typename = std::enable_if_t<DynamicVariant::canHold<T>()>>
INLINE T& Dynamic::get ( )
inline

Returns the reference to the stored value given its type.

The stored value must indeed have a type T, checked by assert.

Definition at line 88 of file Dynamic.h.

◆ get() [2/2]

template<typename T , typename = std::enable_if_t<DynamicVariant::canHold<T>()>>
const T& Dynamic::get ( ) const
inline

Returns the const reference to the stored value given its type.

Definition at line 94 of file Dynamic.h.

◆ getScalar()

Float Dynamic::getScalar ( ) const
inline

Converts the stored value into a single number, using one of possible conversions.

Definition at line 111 of file Dynamic.h.

◆ getType()

DynamicId Dynamic::getType ( ) const
inline

Definition at line 115 of file Dynamic.h.

◆ operator bool()

Dynamic::operator bool ( ) const
inlineexplicit

Definition at line 124 of file Dynamic.h.

◆ operator const T &()

template<typename T , typename = std::enable_if_t<DynamicVariant::canHold<T>()>>
Dynamic::operator const T & ( ) const
inline

Coversion operator to one of stored types, const version.

Definition at line 106 of file Dynamic.h.

◆ operator T&()

template<typename T , typename = std::enable_if_t<DynamicVariant::canHold<T>()>>
Dynamic::operator T& ( )
inline

Conversion operator to one of stored types.

Definition at line 100 of file Dynamic.h.

◆ operator!()

bool Dynamic::operator! ( ) const
inline

Definition at line 128 of file Dynamic.h.

◆ operator=() [1/3]

Dynamic& Dynamic::operator= ( const Dynamic other)
inline

Definition at line 74 of file Dynamic.h.

◆ operator=() [2/3]

Dynamic& Dynamic::operator= ( Dynamic &&  other)
inline

Definition at line 79 of file Dynamic.h.

◆ operator=() [3/3]

template<typename T , typename = std::enable_if_t<DynamicVariant::canHold<T>()>>
Dynamic& Dynamic::operator= ( T &&  rhs)
inline

Assign one of possible value types into the value.

Definition at line 69 of file Dynamic.h.

◆ operator==()

template<typename T , typename = std::enable_if_t<DynamicVariant::canHold<T>()>>
bool Dynamic::operator== ( const T &  value) const
inline

Equality operator with one of stored types.

Definition at line 134 of file Dynamic.h.

Friends And Related Function Documentation

◆ operator<<

std::ostream& operator<< ( std::ostream &  stream,
const Dynamic value 
)
friend

Prints the currently stored value into the stream, using << operator of its type.

Definition at line 139 of file Dynamic.h.


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