33 #ifndef DART_COMMON_DETAIL_EMBEDDEDASPECT_HPP_
34 #define DART_COMMON_DETAIL_EMBEDDEDASPECT_HPP_
44 template <
class AspectT,
typename StateT>
47 aspect->getComposite()->setAspectState(state);
51 template <
class AspectT,
typename StateT>
54 return aspect->getComposite()->getAspectState();
58 template <
class AspectT,
typename PropertiesT>
60 AspectT* aspect,
const PropertiesT&
properties)
62 aspect->getComposite()->setAspectProperties(
properties);
66 template <
class AspectT,
typename PropertiesT>
69 return aspect->getComposite()->getAspectProperties();
78 void (*setEmbeddedState)(DerivedT*,
const StateT&)
79 = &DefaultSetEmbeddedState<DerivedT, StateT>,
80 const StateT& (*getEmbeddedState)(
const DerivedT*)
81 = &DefaultGetEmbeddedState<DerivedT, StateT> >
104 template <
typename T>
132 template <
typename T,
typename... RemainingArgs>
137 std::forward<RemainingArgs>(remainingArgs)...)
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;
191 return std::make_unique<Derived>(this->getState());
197 template <
typename... RemainingArgs>
200 :
Base(
std::forward<RemainingArgs>(remainingArgs)...),
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> >
266 = setEmbeddedProperties;
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>
310 std::forward<RemainingArgs>(remainingArgs)...)
324 if (this->hasComposite())
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;
363 return std::make_unique<Derived>(this->getProperties());
369 template <
typename... RemainingArgs>
373 RemainingArgs&&... remainingArgs)
374 :
Base(
std::forward<RemainingArgs>(remainingArgs)...),
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)(
#define dterr
Output an error message.
Definition: Console.hpp:49
BodyPropPtr properties
Definition: SdfParser.cpp:80
std::string type
Definition: SdfParser.cpp:82
If your Aspect has Properties, then that Properties class should inherit this Aspect::Properties clas...
Definition: Aspect.hpp:86
If your Aspect has a State, then that State class should inherit this Aspect::State class.
Definition: Aspect.hpp:65
Composite is a base class that should be virtually inherited by any class that wants to be able to ma...
Definition: Composite.hpp:53
The MakeCloneable class is used to easily create an Cloneable (such as Node::State) which simply take...
Definition: Cloneable.hpp:84
Definition: EmbeddedAspect.hpp:253
PropertiesDataT PropertiesData
Definition: EmbeddedAspect.hpp:264
const Aspect::Properties * getAspectProperties() const override final
Definition: EmbeddedAspect.hpp:336
EmbeddedPropertiesAspect(const EmbeddedPropertiesAspect &)=delete
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
std::unique_ptr< Properties > mTemporaryProperties
After this Aspect is constructed and during transitions between Composite objects,...
Definition: EmbeddedAspect.hpp:414
void setComposite(Composite *newComposite) override
Pass the temporary Properties of this Aspect into the new Composite.
Definition: EmbeddedAspect.hpp:390
virtual ~EmbeddedPropertiesAspect()=default
BaseT Base
Definition: EmbeddedAspect.hpp:261
std::unique_ptr< Aspect > cloneAspect() const override
Definition: EmbeddedAspect.hpp:361
PropertiesT Properties
Definition: EmbeddedAspect.hpp:263
DelegateTag
Definition: EmbeddedAspect.hpp:256
const Properties & getProperties() const
Definition: EmbeddedAspect.hpp:342
DerivedT Derived
Definition: EmbeddedAspect.hpp:262
EmbeddedPropertiesAspect(const T &arg1, RemainingArgs &&... remainingArgs)
Construct this Aspect.
Definition: EmbeddedAspect.hpp:306
void setAspectProperties(const Aspect::Properties &properties) override final
Definition: EmbeddedAspect.hpp:316
EmbeddedPropertiesAspect(DelegateTag, BaseArgs &&... args)
Construct this Aspect without affecting the Properties, and pass all the arguments into the construct...
Definition: EmbeddedAspect.hpp:383
void setProperties(const Properties &properties)
Definition: EmbeddedAspect.hpp:322
void loseComposite(Composite *oldComposite) override
Save the embedded Properties of this Composite before we remove the Aspect.
Definition: EmbeddedAspect.hpp:403
EmbeddedPropertiesAspect()
Construct this Aspect without affecting the Properties.
Definition: EmbeddedAspect.hpp:285
Definition: EmbeddedAspect.hpp:83
void setState(const State &state)
Set the State of this Aspect.
Definition: EmbeddedAspect.hpp:149
void loseComposite(Composite *oldComposite) override
Save the embedded State of this Composite before we remove the Aspect.
Definition: EmbeddedAspect.hpp:228
std::unique_ptr< Aspect > cloneAspect() const override
Definition: EmbeddedAspect.hpp:189
DelegateTag
Definition: EmbeddedAspect.hpp:95
DerivedT Derived
Definition: EmbeddedAspect.hpp:86
StateDataT StateData
Definition: EmbeddedAspect.hpp:88
StateT State
Definition: EmbeddedAspect.hpp:87
void setAspectState(const Aspect::State &state) override final
Definition: EmbeddedAspect.hpp:143
const Aspect::State * getAspectState() const override final
Definition: EmbeddedAspect.hpp:163
BaseT Base
Definition: EmbeddedAspect.hpp:85
const State & getState() const
Get the State of this Aspect.
Definition: EmbeddedAspect.hpp:169
virtual ~EmbeddedStateAspect()=default
void setComposite(Composite *newComposite) override
Pass the temporary State of this Aspect into the new Composite.
Definition: EmbeddedAspect.hpp:216
EmbeddedStateAspect(const EmbeddedStateAspect &)=delete
EmbeddedStateAspect(DelegateTag, BaseArgs &&... args)
Construct this Aspect without affecting the State, and pass all the arguments into the constructor of...
Definition: EmbeddedAspect.hpp:209
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
EmbeddedStateAspect()
Construct this Aspect without affecting the State.
Definition: EmbeddedAspect.hpp:112
std::unique_ptr< State > mTemporaryState
After this Aspect is constructed and during transitions between Composite objects,...
Definition: EmbeddedAspect.hpp:239
void DefaultSetEmbeddedProperties(AspectT *aspect, const PropertiesT &properties)
Definition: EmbeddedAspect.hpp:59
void DefaultSetEmbeddedState(AspectT *aspect, const StateT &state)
Definition: EmbeddedAspect.hpp:45
const StateT & DefaultGetEmbeddedState(const AspectT *aspect)
Definition: EmbeddedAspect.hpp:52
const PropertiesT & DefaultGetEmbeddedProperties(const AspectT *aspect)
Definition: EmbeddedAspect.hpp:67
std::unique_ptr< T > make_unique(Args &&... args)
Definition: Memory-impl.hpp:67
Definition: BulletCollisionDetector.cpp:65
Definition: SharedLibraryManager.hpp:46
Used to identify constructor arguments that can be used as Properties.
Definition: EmbeddedAspect.hpp:277
typename std::conditional< std::is_base_of< PropertiesData, T >::value, PropertiesData, T >::type type
Definition: EmbeddedAspect.hpp:281
Used to identify constructor arguments that can be used as a State.
Definition: EmbeddedAspect.hpp:106
typename std::conditional< std::is_base_of< StateData, T >::value, StateData, T >::type type
Definition: EmbeddedAspect.hpp:108