Radium Engine
1.5.20
|
Heterogeneous container storing "Variables", that maps a name (std::string) to a value (of any type T). More...
#include <Core/Containers/VariableSet.hpp>
Classes | |
class | DynamicVisitor |
Base class for visitors with configurable per-type callbacks. Visiting will be prepared at running time by dynamically adding visitor operators for each type one want to visit in the container. The visitor accept type based on either the added operators or an external acceptance functor which can be associated/changed at runtime. This functor is only allowed to reduce the number of visited type as only type for which a visitor operator is registered can be visited. The visitor operators should be any callable that accept to be called using f(const std::string&, T&[, std::any&&]) More... | |
class | DynamicVisitorBase |
Base class for dynamically configurable visitors Users can implement this interface to build custom visitors without any restriction. To ease visitor configuration, see class DynamicVisitor. More... | |
struct | StaticVisitor |
Base class for visitors with static supported types. Visiting will be prepared at compile time by unfolding type list and generating all the required function calls for the visit. Any class that defines the same alias for a public member "types" can be used as a visitor. More... | |
Public Types | |
template<typename T > | |
using | VariableContainer = std::map<std::string, T> |
Container type for the mapping name->value of variables with type T. | |
template<typename T > | |
using | Variable = typename VariableContainer<T>::value_type |
Variable type as stored in the VariableSet. | |
template<typename T > | |
using | VariableType = typename Variable<T>::second_type |
Type of the variable value. | |
template<typename T > | |
using | VariableHandle = typename VariableContainer<T>::iterator |
Handle of a variable A handle on a variable with type T is an iterator into the BaseContainer. De-referencing the handle give access to a non const pair <const std::string, T> (BaseContainer<T>::value_type). VariableHandle validity follows the rules of BaseContainer<T>::iterator validity. | |
template<typename H > | |
using | VariableTypeFromHandle = typename std::iterator_traits<H>::value_type::second_type |
Type of the variable referenced by a VariableHandle. | |
Public Member Functions | |
template<typename F , typename U > | |
void | visitStatic (F &&visitor, U &userParams) const |
template<typename F , typename U > | |
void | visitStatic (F &&visitor, U &&userParams) const |
VariableSet () | |
VariableSet (const VariableSet &other) noexcept | |
A VariableSet is copyable. | |
VariableSet (VariableSet &&other) noexcept | |
A VariableSet is movable. | |
auto | operator= (const VariableSet &other) -> VariableSet & |
Copy assignment operator. | |
auto | operator= (VariableSet &&other) noexcept -> VariableSet & |
Move assignment operator. | |
void | clear () |
remove all elements from the container | |
void | mergeKeepVariables (const VariableSet &from) |
Merge the VariableSet from into this. | |
void | mergeReplaceVariables (const VariableSet &from) |
Merge the VariableSet from into this. | |
size_t | size () const |
Gets the total number of variables (of any type) | |
auto | getStoredTypes () const -> const std::vector< std::type_index > & |
Gets the stored data type. | |
template<typename T > | |
auto | insertVariable (const std::string &name, const T &value) -> std::pair< VariableHandle< T >, bool > |
Add a variable, i.e. an association name->value, into the container. | |
template<typename T > | |
auto | getVariable (const std::string &name) const -> const T & |
get the value of the given variable | |
template<typename T > | |
auto | getVariable (const std::string &name) -> T & |
template<typename T > | |
auto | getVariableHandle (const std::string &name) const -> const VariableHandle< T > |
get the handle on the variable with the given name | |
template<typename H > | |
bool | isHandleValid (const H &handle) const |
Test the validity of a handle. | |
template<typename T > | |
auto | setVariable (const std::string &name, const T &value) -> std::pair< VariableHandle< T >, bool > |
reset (or set if the variable does not exist yet) the value of the variable. | |
template<typename T > | |
bool | deleteVariable (const std::string &name) |
Remove a variable, i.e. a name->value association. | |
template<typename H > | |
bool | deleteVariable (H &handle) |
delete a variable from its handle | |
template<typename T > | |
auto | existsVariable (const std::string &name) const -> Utils::optional< VariableHandle< T > > |
test the existence of the given variable | |
template<typename T > | |
auto | existsVariableType () const -> Utils::optional< VariableContainer< T > * > |
Test if the storage supports a given variable type. | |
template<typename T > | |
bool | deleteAllVariables () |
Removes all variables of the given type. | |
template<typename T > | |
auto | getAllVariables () const -> VariableContainer< T > & |
Get the whole container for variables of a given type. | |
template<typename H > | |
auto | getAllVariablesFromHandle (const H &handle) -> VariableContainer< VariableTypeFromHandle< H > > & |
Get the whole container for variables of the same type than the given handled variable. | |
template<typename T > | |
size_t | numberOf () const |
Get the number of variables of the given type. | |
template<typename F > | |
void | visit (F &&visitor) const |
Visit the container using a user defined visitor. | |
template<typename F , typename T > | |
void | visit (F &&visitor, T &userParams) const |
overload of the static visit method to allow a parameter pass by reference | |
template<typename F , typename T > | |
void | visit (F &&visitor, T &&userParams) const |
overload of the static visit method to allow a parameter pass by rvalue reference | |
Heterogeneous container storing "Variables", that maps a name (std::string) to a value (of any type T).
The container is compatible with any type, from simple arithmetic type to wrapped references to any other type.
"Variables" can be added, accessed and removed from the container given their type, name and value.
Given a type, the container gives access to the mapping name->value for all variables with the given type.
Stored variables can be referenced using a VariableHandle returned when a variable is inserted in the container or fetch giving the type and the name of the variable. Validity of the variable handle follows the same rules than the std::iterator attached to the underlying mapping storage (std::map<std::string, T>::iterator for the actual implementation).
From a variable handle (possibly invalid), the mapping name->value for all variables with the same type can be fetched. This allows generic, type agnostic, usage of the container as soon as a variable handle (even invalid) is available.
The container could be visited to apply processing, transformation, ... on all or part of the variables. The accept functions of the visitor are defined by the availability of a callable object whose profile is compatible with the visited types.
Visiting the container can be made
The visitor of the collection can accept one user parameter to be forwarded to each visit function. This parameter could be of any type, knowing the same parameter will be forwarded to all processing method when visiting a variable. Some constraints on user provided parameter depends on the visiting strategy
Definition at line 71 of file VariableSet.hpp.
using Ra::Core::VariableSet::Variable = typename VariableContainer<T>::value_type |
Variable type as stored in the VariableSet.
Definition at line 80 of file VariableSet.hpp.
using Ra::Core::VariableSet::VariableContainer = std::map<std::string, T> |
Container type for the mapping name->value of variables with type T.
Definition at line 76 of file VariableSet.hpp.
using Ra::Core::VariableSet::VariableHandle = typename VariableContainer<T>::iterator |
Handle of a variable A handle on a variable with type T is an iterator into the BaseContainer. De-referencing the handle give access to a non const pair <const std::string, T> (BaseContainer<T>::value_type). VariableHandle validity follows the rules of BaseContainer<T>::iterator validity.
Definition at line 92 of file VariableSet.hpp.
using Ra::Core::VariableSet::VariableType = typename Variable<T>::second_type |
Type of the variable value.
Definition at line 84 of file VariableSet.hpp.
using Ra::Core::VariableSet::VariableTypeFromHandle = typename std::iterator_traits<H>::value_type::second_type |
Type of the variable referenced by a VariableHandle.
Definition at line 98 of file VariableSet.hpp.
|
inline |
Constructors, destructors
Definition at line 103 of file VariableSet.hpp.
|
inlinenoexcept |
A VariableSet is copyable.
Definition at line 106 of file VariableSet.hpp.
|
inlinenoexcept |
A VariableSet is movable.
Definition at line 111 of file VariableSet.hpp.
void Ra::Core::VariableSet::clear | ( | ) |
remove all elements from the container
Definition at line 33 of file VariableSet.cpp.
bool Ra::Core::VariableSet::deleteAllVariables | ( | ) |
Removes all variables of the given type.
T | The type of variable to remove |
Definition at line 756 of file VariableSet.hpp.
bool Ra::Core::VariableSet::deleteVariable | ( | const std::string & | name | ) |
Remove a variable, i.e. a name->value association.
Definition at line 651 of file VariableSet.hpp.
bool Ra::Core::VariableSet::deleteVariable | ( | H & | handle | ) |
delete a variable from its handle
H | Type of the handle. Expected to be VariableHandle<T> for some variable type T |
handle | the variable handle |
Definition at line 662 of file VariableSet.hpp.
auto Ra::Core::VariableSet::existsVariable | ( | const std::string & | name | ) | const -> Utils::optional<VariableHandle<T>> |
test the existence of the given variable
Definition at line 670 of file VariableSet.hpp.
auto Ra::Core::VariableSet::existsVariableType | ( | ) | const -> Utils::optional<VariableContainer<T>*> |
Test if the storage supports a given variable type.
Operators acting on a per type basis
T | The type of variable to test |
Definition at line 749 of file VariableSet.hpp.
auto Ra::Core::VariableSet::getAllVariables | ( | ) | const -> VariableContainer<T>& |
Get the whole container for variables of a given type.
T | The variable type to get |
Definition at line 765 of file VariableSet.hpp.
auto Ra::Core::VariableSet::getAllVariablesFromHandle | ( | const H & | handle | ) | -> VariableContainer<VariableTypeFromHandle<H>>& |
Get the whole container for variables of the same type than the given handled variable.
H | Type of the variable handle, should be VariableHandle<T> for some type T |
handle | the handle to an existing variable |
Definition at line 774 of file VariableSet.hpp.
|
inline |
Gets the stored data type.
Definition at line 147 of file VariableSet.hpp.
auto Ra::Core::VariableSet::getVariable | ( | const std::string & | name | ) | -> T& |
Definition at line 618 of file VariableSet.hpp.
auto Ra::Core::VariableSet::getVariable | ( | const std::string & | name | ) | const -> const T& |
get the value of the given variable
Definition at line 623 of file VariableSet.hpp.
auto Ra::Core::VariableSet::getVariableHandle | ( | const std::string & | name | ) | const -> const VariableHandle<T> |
get the handle on the variable with the given name
T | the type of the variable |
name | the name of a variable |
Definition at line 628 of file VariableSet.hpp.
auto Ra::Core::VariableSet::insertVariable | ( | const std::string & | name, |
const T & | value ) -> std::pair<VariableHandle<T>, bool> |
Add a variable, i.e. an association name->value, into the container.
Operators acting on a per variable basis
Definition at line 608 of file VariableSet.hpp.
bool Ra::Core::VariableSet::isHandleValid | ( | const H & | handle | ) | const |
Test the validity of a handle.
H | Type of the handle. Expected to be VariableHandle<T> for some variable type T |
handle | the variable handle |
Definition at line 634 of file VariableSet.hpp.
void Ra::Core::VariableSet::mergeKeepVariables | ( | const VariableSet & | from | ) |
Merge the VariableSet from into this.
from | the VariableSet to merge with the current. Existing variable into this, with same name as in from, are kept unchanged |
Definition at line 37 of file VariableSet.cpp.
void Ra::Core::VariableSet::mergeReplaceVariables | ( | const VariableSet & | from | ) |
Merge the VariableSet from into this.
from | the VariableSet to merge with the current. Existing variable into this, with same name as in from, are replaced by from's one. |
Definition at line 44 of file VariableSet.cpp.
size_t Ra::Core::VariableSet::numberOf | ( | ) | const |
Get the number of variables of the given type.
T | The type to test |
Definition at line 781 of file VariableSet.hpp.
auto Ra::Core::VariableSet::operator= | ( | const VariableSet & | other | ) | -> VariableSet& |
Copy assignment operator.
Operators acting on a the whole VariableSet
Definition at line 19 of file VariableSet.cpp.
|
noexcept |
Move assignment operator.
Definition at line 26 of file VariableSet.cpp.
auto Ra::Core::VariableSet::setVariable | ( | const std::string & | name, |
const T & | value ) -> std::pair<VariableHandle<T>, bool> |
reset (or set if the variable does not exist yet) the value of the variable.
Definition at line 640 of file VariableSet.hpp.
size_t Ra::Core::VariableSet::size | ( | ) | const |
Gets the total number of variables (of any type)
Definition at line 51 of file VariableSet.cpp.
|
inline |
Visit the container using a user defined visitor.
F | The type of the visitor to use (could be dynamic or static - see above ) |
visitor | The visitor object to use The type of the visiting functor F should be
|
Definition at line 907 of file VariableSet.hpp.
|
inline |
overload of the static visit method to allow a parameter pass by rvalue reference
Definition at line 923 of file VariableSet.hpp.
|
inline |
overload of the static visit method to allow a parameter pass by reference
Definition at line 915 of file VariableSet.hpp.
void Ra::Core::VariableSet::visitStatic | ( | F && | visitor, |
U && | userParams ) const |
Definition at line 826 of file VariableSet.hpp.
void Ra::Core::VariableSet::visitStatic | ( | F && | visitor, |
U & | userParams ) const |
Definition at line 820 of file VariableSet.hpp.