33 #ifndef STATE_NESTED_SET_H 34 #define STATE_NESTED_SET_H 48 template <
typename... NestedStates>
50 template <
typename... NestedStates>
52 template <
typename... NestedStates>
54 template <
typename... NestedStates>
56 template <
typename... NestedStates>
58 template <
typename... NestedStates>
65 states_ = std::make_tuple(std::shared_ptr<NestedStates>(
new NestedStates(
this))...);
66 statesBase_ = std::initializer_list<StateSPtr>{ std::shared_ptr<NestedStates>(
new NestedStates(
this))... };
74 states_ = std::make_tuple(std::shared_ptr<NestedStates>(
new NestedStates(
this))...);
75 statesBase_ = std::initializer_list<StateSPtr>{ std::shared_ptr<NestedStates>(
new NestedStates(
this))... };
114 double&
value(
const std::size_t& _i)
override 120 const double&
value(
const std::size_t& _i)
const override 144 stateI->updateSize();
148 size_t valSizeSum = 0;
149 auto funcBindVals = [
this, &valSizeSum](
StateSPtr stateI)
151 size_t valSizeI = stateI->valueSize();
152 for (
size_t i = 0; i < valSizeI; ++i)
154 values_[valSizeSum + i] = &stateI->value(i);
156 valSizeSum += valSizeI;
165 static constexpr
const size_t statesSize_ =
sizeof...(NestedStates);
168 std::tuple<std::shared_ptr<NestedStates>...>
states_;
186 template <
typename EnumStateVals,
typename... NestedStates>
224 template <EnumStateVals _i>
225 typename std::tuple_element<asInt(_i), std::tuple<std::shared_ptr<NestedStates>...> >::type&
state()
227 return std::get<asInt(_i)>(this->
states_);
232 #endif // STATE_NESTED_SET_H std::shared_ptr< State > StateSPtr
StateNestedSet(State *_parent)
std::vector< double * > values_
StateSPtr & state(const std::size_t &_i) override
Access sub-state based on index _i.
std::unique_ptr< StateNestedSet< NestedStates... > const > StateNestedSetConstUPtr
virtual StateSPtr cloneState() const override
Clone-to-base-class-ptr function.
std::shared_ptr< StateNestedSet< NestedStates... > const > StateNestedSetConstSPtr
StateNestedSetScoped(State *_parent)
static constexpr const size_t statesSize_
virtual ~StateNestedSet()=default
constexpr std::enable_if< II==sizeof...(Tp), void >::type for_each_tuple(std::tuple< Tp... > &, FuncT)
const double & value(const std::size_t &_i) const override
Const access state variable based on index _i.
std::shared_ptr< StateNestedSet< NestedStates... > > StateNestedSetSPtr
Extension of StateNestedSet providing sub-state access based on a scoped enumeration (compile-time)...
Implementation of State being formed by tuple of substates.
Generic tree-like recursive structure that allows sub-structure access as well as ordered (array-like...
size_t stateSize() const override
Size of the sub-states.
double & value(const std::size_t &_i) override
Access state variable based on index _i.
std::vector< StateSPtr > statesBase_
size_t valueSize() const override
Size of the state variables.
std::tuple_element< asInt(_i), std::tuple< std::shared_ptr< NestedStates >... > >::type & state()
Scoped access (compile-time) to the sub-states of the state object.
std::tuple< std::shared_ptr< NestedStates >... > states_
std::unique_ptr< StateNestedSet< NestedStates... > > StateNestedSetUPtr
void callRootUpdateSize()
Calls (if present) the parent updateSize procedure. Otherwise performs root updateSize.
void updateSize() override
Performs internal manipulation when any of the underlying arrays are being resized.
StateNestedSet & operator=(const StateNestedSet &)=default