Radium Engine  1.5.20
Loading...
Searching...
No Matches
VariableSet.cpp
1#include <Core/Containers/VariableSet.hpp>
2#include <Core/CoreMacros.hpp>
3
4// inspirations :
5// Radium dataflow dynamic type management
6// Radium attribArray
7// factory design pattern
8// visitor design pattern
9// https://en.cppreference.com/w/cpp/utility/any/type
10// https://gieseanw.wordpress.com/2017/05/03/a-true-heterogeneous-container-in-c/
11namespace Ra {
12namespace Core {
13
14auto VariableSet::VariableSetFunctions::getInstance() -> VariableSetFunctions* {
15 static VariableSet::VariableSetFunctions instance;
16 return &instance;
17}
18
20 m_variables = other.m_variables;
21 m_typeIndexToVtableIndex = other.m_typeIndexToVtableIndex;
22 m_storedType = other.m_storedType;
23 return *this;
24}
25
26auto VariableSet::operator=( VariableSet&& other ) noexcept -> VariableSet& {
27 m_variables = std::move( other.m_variables );
28 m_typeIndexToVtableIndex = std::move( other.m_typeIndexToVtableIndex );
29 m_storedType = std::move( other.m_storedType );
30 return *this;
31}
32
34 m_variables.clear();
35}
36
38 for ( const auto& type : from.getStoredTypes() ) {
39 const auto& index = from.m_typeIndexToVtableIndex.at( type );
40 from.m_vtable->m_mergeKeepFunctions[index]( from, *this );
41 }
42}
43
45 for ( const auto& type : from.getStoredTypes() ) {
46 const auto& index = from.m_typeIndexToVtableIndex.at( type );
47 from.m_vtable->m_mergeReplaceFunctions[index]( from, *this );
48 }
49}
50
51size_t VariableSet::size() const {
52 size_t sum { 0 };
53 for ( const auto& [type, index] : m_typeIndexToVtableIndex ) {
54 sum += m_vtable->m_sizeFunctions[index]( *this );
55 }
56 return sum;
57}
58
60 return m_visitorOperator.find( id ) != m_visitorOperator.cend();
61}
62
63void VariableSet::DynamicVisitor::operator()( std::any&& in, std::any&& userParam ) const {
64 m_visitorOperator.at( std::type_index( in.type() ) )( in, std::forward<std::any>( userParam ) );
65}
66
67} // namespace Core
68} // namespace Ra
T at(T... args)
bool accept(const std::type_index &id) const override
Acceptance function for the visitor.
void operator()(std::any &&in, std::any &&userParam) const override
Execute a visiting operator on accepted types.
Heterogeneous container storing "Variables", that maps a name (std::string) to a value (of any type T...
auto getStoredTypes() const -> const std::vector< std::type_index > &
Gets the stored data type.
void mergeKeepVariables(const VariableSet &from)
Merge the VariableSet from into this.
void clear()
remove all elements from the container
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 operator=(const VariableSet &other) -> VariableSet &
Copy assignment operator.
T clear(T... args)
T cend(T... args)
T find(T... args)
T forward(T... args)
T move(T... args)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:3