Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.5.27
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
VariableSet.cpp
1#include <Core/Containers/VariableSet.hpp>
2#include <functional>
3#include <stddef.h>
4#include <unordered_map>
5#include <utility>
6#include <vector>
7
8// inspirations :
9// Radium dataflow dynamic type management
10// Radium attribArray
11// factory design pattern
12// visitor design pattern
13// https://en.cppreference.com/w/cpp/utility/any/type
14// https://gieseanw.wordpress.com/2017/05/03/a-true-heterogeneous-container-in-c/
15namespace Ra {
16namespace Core {
17
18auto VariableSet::VariableSetFunctions::getInstance() -> VariableSetFunctions* {
19 static VariableSet::VariableSetFunctions instance;
20 return &instance;
21}
22
24 m_variables = other.m_variables;
25 m_typeIndexToVtableIndex = other.m_typeIndexToVtableIndex;
26 m_storedType = other.m_storedType;
27 return *this;
28}
29
30auto VariableSet::operator=( VariableSet&& other ) noexcept -> VariableSet& {
31 m_variables = std::move( other.m_variables );
32 m_typeIndexToVtableIndex = std::move( other.m_typeIndexToVtableIndex );
33 m_storedType = std::move( other.m_storedType );
34 return *this;
35}
36
38 m_variables.clear();
39}
40
42 for ( const auto& type : from.getStoredTypes() ) {
43 const auto& index = from.m_typeIndexToVtableIndex.at( type );
44 from.m_vtable->m_mergeKeepFunctions[index]( from, *this );
45 }
46}
47
49 for ( const auto& type : from.getStoredTypes() ) {
50 const auto& index = from.m_typeIndexToVtableIndex.at( type );
51 from.m_vtable->m_mergeReplaceFunctions[index]( from, *this );
52 }
53}
54
55size_t VariableSet::size() const {
56 size_t sum { 0 };
57 for ( const auto& [type, index] : m_typeIndexToVtableIndex ) {
58 sum += m_vtable->m_sizeFunctions[index]( *this );
59 }
60 return sum;
61}
62
63} // namespace Core
64} // namespace Ra
T at(T... args)
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 move(T... args)
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4