Utopia 2
Framework for studying models of complex & adaptive systems.
Loading...
Searching...
No Matches
state.hh
Go to the documentation of this file.
1#ifndef UTOPIA_CORE_STATE_HH
2#define UTOPIA_CORE_STATE_HH
3
4namespace Utopia {
5
12
20enum class Update {
21 manual,
22 sync,
23 async
24};
25
27
36template<typename StateType, Update mode>
38
40template<typename StateType>
42{
43public:
46
48
52 state(state_initial)
53 { }
54};
55
57
62template<typename StateType>
64{
65public:
68
70 static constexpr bool is_sync () { return false; }
71
73 StateContainer (const State state):
74 _state(state)
75 { }
76
78 State& state () { return _state; }
80 const State& state () const { return _state; }
81
82private:
84};
85
87
92template<typename StateType>
94{
95public:
98
100 static constexpr bool is_sync () { return true; }
101
103 StateContainer (const State state):
104 _state(state),
105 _state_new(state)
106 { }
107
109 State& state_new () { return _state_new; }
111 const State& state () const { return _state; }
113 void update () noexcept { _state = _state_new; }
114
115private:
118};
119
124} // namespace Utopia
125
126#endif // UTOPIA_CORE_STATE_HH
const State & state() const
Return const reference to state.
Definition state.hh:80
static constexpr bool is_sync()
Export implementation type.
Definition state.hh:70
State & state()
Return reference to state.
Definition state.hh:78
StateType State
Type of state.
Definition state.hh:67
StateContainer(const State state)
Construct state container with specific state.
Definition state.hh:73
StateContainer(const State state_initial)
Construct state container with specific state.
Definition state.hh:51
static constexpr bool is_sync()
Export implementation type.
Definition state.hh:100
void update() noexcept
Overwrite state with state cache.
Definition state.hh:113
StateContainer(const State state)
Construct state container with specific state.
Definition state.hh:103
const State & state() const
Return const reference to state.
Definition state.hh:111
StateType State
Type of state.
Definition state.hh:97
State & state_new()
Return reference to state cache.
Definition state.hh:109
Container for states.
Definition state.hh:37
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
@ manual
Fully manual: write_data method is always called.
Update
Update modes when applying rules.
Definition state.hh:20
@ async
Asynchronous update.
@ sync
Synchronous update.
Definition agent.hh:11