33 #ifndef DART_COMMON_DETAIL_EMBEDDEDASPECT_HPP_ 34 #define DART_COMMON_DETAIL_EMBEDDEDASPECT_HPP_ 36 #include "dart/common/Aspect.hpp" 37 #include "dart/common/StlHelpers.hpp" 44 template <
class AspectT,
typename StateT>
45 void DefaultSetEmbeddedState(AspectT* aspect,
const StateT& state)
47 aspect->getComposite()->setAspectState(state);
51 template <
class AspectT,
typename StateT>
52 const StateT& DefaultGetEmbeddedState(
const AspectT* aspect)
54 return aspect->getComposite()->getAspectState();
58 template <
class AspectT,
typename PropertiesT>
59 void DefaultSetEmbeddedProperties(
60 AspectT* aspect,
const PropertiesT& properties)
62 aspect->getComposite()->setAspectProperties(properties);
66 template <
class AspectT,
typename PropertiesT>
67 const PropertiesT& DefaultGetEmbeddedProperties(
const AspectT* aspect)
69 return aspect->getComposite()->getAspectProperties();
77 typename StateT = common::Aspect::MakeState<StateDataT>,
78 void (*setEmbeddedState)(DerivedT*,
const StateT&)
79 = &DefaultSetEmbeddedState<DerivedT, StateT>,
80 const StateT& (*getEmbeddedState)(
const DerivedT*)
81 = &DefaultGetEmbeddedState<DerivedT, StateT> >
86 using Derived = DerivedT;
88 using StateData = StateDataT;
89 constexpr
static void (*SetEmbeddedState)(Derived*,
const State&)
91 constexpr
static const State& (*GetEmbeddedState)(
const Derived*)
104 template <
typename T>
107 using type =
typename std::
108 conditional<std::is_base_of<StateData, T>::value, StateData, T>::type;
132 template <
typename T,
typename... RemainingArgs>
136 static_cast<const typename ConvertIfState<T>::type&>(arg1),
137 std::forward<RemainingArgs>(remainingArgs)...)
143 void setAspectState(
const Aspect::State& state)
override final 145 setState(static_cast<const State&>(state));
151 if (this->hasComposite())
153 SetEmbeddedState(static_cast<Derived*>(
this), state);
159 mTemporaryState = std::make_unique<State>(state);
171 if (this->hasComposite())
173 return GetEmbeddedState(static_cast<const Derived*>(
this));
176 if (!mTemporaryState)
178 dterr <<
"[detail::EmbeddedStateAspect::getState] This Aspect is not in " 179 <<
"a Composite, but it also does not have a temporary State " 180 <<
"available. This should not happen! Please report this as a " 185 return *mTemporaryState;
189 std::unique_ptr<Aspect> cloneAspect()
const override 191 return std::make_unique<Derived>(this->getState());
197 template <
typename... RemainingArgs>
199 DelegateTag,
const StateData& state, RemainingArgs&&... remainingArgs)
200 :
Base(
std::forward<RemainingArgs>(remainingArgs)...),
201 mTemporaryState(
std::make_unique<
State>(state))
208 template <
typename... BaseArgs>
210 :
Base(
std::forward<BaseArgs>(args)...)
218 assert(
nullptr == this->getComposite());
220 Base::setComposite(newComposite);
222 SetEmbeddedState(static_cast<Derived*>(
this), *mTemporaryState);
224 mTemporaryState =
nullptr;
230 mTemporaryState = std::make_unique<State>(
231 GetEmbeddedState(static_cast<const Derived*>(
this)));
232 Base::loseComposite(oldComposite);
246 typename PropertiesDataT,
248 void (*setEmbeddedProperties)(DerivedT*,
const PropertiesT&)
249 = &DefaultSetEmbeddedProperties<DerivedT, PropertiesT>,
250 const PropertiesT& (*getEmbeddedProperties)(
const DerivedT*)
251 = &DefaultGetEmbeddedProperties<DerivedT, PropertiesT> >
262 using Derived = DerivedT;
263 using Properties = PropertiesT;
264 using PropertiesData = PropertiesDataT;
265 constexpr
static void (*SetEmbeddedProperties)(Derived*,
const Properties&)
266 = setEmbeddedProperties;
267 constexpr
static const Properties& (*GetEmbeddedProperties)(
const Derived*)
268 = getEmbeddedProperties;
275 template <
typename T>
278 using type =
typename std::conditional<
279 std::is_base_of<PropertiesData, T>::value,
305 template <
typename T,
typename... RemainingArgs>
309 static_cast<const typename ConvertIfProperties<T>::type&>(arg1),
310 std::forward<RemainingArgs>(remainingArgs)...)
318 setProperties(static_cast<const Properties&>(properties));
322 void setProperties(
const Properties& properties)
324 if (this->hasComposite())
326 SetEmbeddedProperties(static_cast<Derived*>(
this), properties);
332 mTemporaryProperties = std::make_unique<Properties>(properties);
338 return &getProperties();
344 if (this->hasComposite())
346 return GetEmbeddedProperties(static_cast<const Derived*>(
this));
349 if (!mTemporaryProperties)
351 dterr <<
"[detail::EmbeddedPropertiesAspect::getProperties] This Aspect " 352 <<
"is not in a Composite, but it also does not have temporary " 353 <<
"Properties available. This should not happen! Please report " 354 <<
"this as a bug!\n";
358 return *mTemporaryProperties;
361 std::unique_ptr<Aspect> cloneAspect()
const override 363 return std::make_unique<Derived>(this->getProperties());
369 template <
typename... RemainingArgs>
372 const PropertiesData& properties,
373 RemainingArgs&&... remainingArgs)
374 :
Base(
std::forward<RemainingArgs>(remainingArgs)...),
375 mTemporaryProperties(
std::make_unique<
Properties>(properties))
382 template <
typename... BaseArgs>
384 :
Base(
std::forward<BaseArgs>(args)...)
392 assert(
nullptr == this->getComposite());
394 Base::setComposite(newComposite);
395 if (mTemporaryProperties)
396 SetEmbeddedProperties(static_cast<Derived*>(
this), *mTemporaryProperties);
399 mTemporaryProperties =
nullptr;
405 mTemporaryProperties = std::make_unique<Properties>(
406 GetEmbeddedProperties(static_cast<Derived*>(
this)));
407 Base::loseComposite(oldComposite);
429 void (*setEmbeddedState)(DerivedT*,
const StateT&),
430 const StateT& (*getEmbeddedState)(
const DerivedT*)>
437 getEmbeddedState>::SetEmbeddedState)(DerivedT*,
const StateT&);
445 void (*setEmbeddedState)(DerivedT*,
const StateT&),
446 const StateT& (*getEmbeddedState)(
const DerivedT*)>
453 getEmbeddedState>::GetEmbeddedState)(
const DerivedT*);
459 typename PropertiesDataT,
460 typename PropertiesT,
461 void (*setEmbeddedProperties)(DerivedT*,
const PropertiesT&),
462 const PropertiesT& (*getEmbeddedProperties)(
const DerivedT*)>
468 setEmbeddedProperties,
469 getEmbeddedProperties>::SetEmbeddedProperties)(
470 DerivedT*,
const PropertiesT&);
476 typename PropertiesDataT,
477 typename PropertiesT,
478 void (*setEmbeddedProperties)(DerivedT*,
const PropertiesT&),
479 const PropertiesT& (*getEmbeddedProperties)(
const DerivedT*)>
485 setEmbeddedProperties,
486 getEmbeddedProperties>::GetEmbeddedProperties)(
493 #endif // DART_COMMON_DETAIL_EMBEDDEDASPECT_HPP_ void setComposite(Composite *newComposite) override
Pass the temporary State of this Aspect into the new Composite.
Definition: EmbeddedAspect.hpp:216
void loseComposite(Composite *oldComposite) override
Save the embedded State of this Composite before we remove the Aspect.
Definition: EmbeddedAspect.hpp:228
EmbeddedStateAspect(DelegateTag, const StateData &state, RemainingArgs &&... remainingArgs)
Construct this Aspect using the StateData, and pass the remaining arguments into the constructor of t...
Definition: EmbeddedAspect.hpp:198
EmbeddedStateAspect(const T &arg1, RemainingArgs &&... remainingArgs)
Construct this Aspect.
Definition: EmbeddedAspect.hpp:133
std::unique_ptr< State > mTemporaryState
After this Aspect is constructed and during transitions between Composite objects, this will hold the State of the Aspect.
Definition: EmbeddedAspect.hpp:239
EmbeddedPropertiesAspect(DelegateTag, BaseArgs &&... args)
Construct this Aspect without affecting the Properties, and pass all the arguments into the construct...
Definition: EmbeddedAspect.hpp:383
The MakeCloneable class is used to easily create an Cloneable (such as Node::State) which simply take...
Definition: Cloneable.hpp:83
Definition: SharedLibraryManager.hpp:46
std::unique_ptr< Properties > mTemporaryProperties
After this Aspect is constructed and during transitions between Composite objects, this will hold the Properties of the Aspect.
Definition: EmbeddedAspect.hpp:414
If your Aspect has Properties, then that Properties class should inherit this Aspect::Properties clas...
Definition: Aspect.hpp:85
void loseComposite(Composite *oldComposite) override
Save the embedded Properties of this Composite before we remove the Aspect.
Definition: EmbeddedAspect.hpp:403
EmbeddedPropertiesAspect(const T &arg1, RemainingArgs &&... remainingArgs)
Construct this Aspect.
Definition: EmbeddedAspect.hpp:306
const State & getState() const
Get the State of this Aspect.
Definition: EmbeddedAspect.hpp:169
Used to identify constructor arguments that can be used as Properties.
Definition: EmbeddedAspect.hpp:276
Definition: Aspect.cpp:40
If your Aspect has a State, then that State class should inherit this Aspect::State class...
Definition: Aspect.hpp:64
Used to identify constructor arguments that can be used as a State.
Definition: EmbeddedAspect.hpp:105
Definition: EmbeddedAspect.hpp:252
class State
Definition: State.hpp:65
void setComposite(Composite *newComposite) override
Pass the temporary Properties of this Aspect into the new Composite.
Definition: EmbeddedAspect.hpp:390
Composite is a base class that should be virtually inherited by any class that wants to be able to ma...
Definition: Composite.hpp:52
void setState(const State &state)
Set the State of this Aspect.
Definition: EmbeddedAspect.hpp:149
EmbeddedStateAspect()
Construct this Aspect without affecting the State.
Definition: EmbeddedAspect.hpp:112
EmbeddedStateAspect(DelegateTag, BaseArgs &&... args)
Construct this Aspect without affecting the State, and pass all the arguments into the constructor of...
Definition: EmbeddedAspect.hpp:209
Definition: EmbeddedAspect.hpp:82
EmbeddedPropertiesAspect(DelegateTag, const PropertiesData &properties, RemainingArgs &&... remainingArgs)
Construct this Aspect using the PropertiesData, and pass the remaining arguments into the constructor...
Definition: EmbeddedAspect.hpp:370
EmbeddedPropertiesAspect()
Construct this Aspect without affecting the Properties.
Definition: EmbeddedAspect.hpp:285