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>
61 aspect->getComposite()->setAspectProperties(
properties);
65 template <
class AspectT,
typename PropertiesT>
68 return aspect->getComposite()->getAspectProperties();
72 template <
class BaseT,
class DerivedT,
typename StateDataT,
74 void (*setEmbeddedState)(DerivedT*,
const StateT&) =
75 &DefaultSetEmbeddedState<DerivedT, StateT>,
76 const StateT& (*getEmbeddedState)(
const DerivedT*) =
77 &DefaultGetEmbeddedState<DerivedT, StateT> >
86 constexpr
static void (*SetEmbeddedState)(
Derived*,
const State&) = setEmbeddedState;
87 constexpr
static const State& (*GetEmbeddedState)(
const Derived*) = getEmbeddedState;
99 using type =
typename std::conditional<
100 std::is_base_of<StateData, T>::value,
126 template <
typename T,
typename... RemainingArgs>
129 RemainingArgs&&... remainingArgs)
133 std::forward<RemainingArgs>(remainingArgs)...)
141 setState(
static_cast<const State&
>(state));
147 if(this->hasComposite())
149 SetEmbeddedState(
static_cast<Derived*
>(
this), state);
155 mTemporaryState = make_unique<State>(state);
167 if(this->hasComposite())
169 return GetEmbeddedState(
static_cast<const Derived*
>(
this));
174 dterr <<
"[detail::EmbeddedStateAspect::getState] This Aspect is not in "
175 <<
"a Composite, but it also does not have a temporary State "
176 <<
"available. This should not happen! Please report this as a "
181 return *mTemporaryState;
187 return make_unique<Derived>(this->getState());
194 template <
typename... RemainingArgs>
197 RemainingArgs&&... remainingArgs)
198 :
Base(
std::forward<RemainingArgs>(remainingArgs)...),
206 template <
typename... BaseArgs>
209 :
Base(
std::forward<BaseArgs>(args)...)
217 assert(
nullptr == this->getComposite());
219 Base::setComposite(newComposite);
221 SetEmbeddedState(
static_cast<Derived*
>(
this), *mTemporaryState);
223 mTemporaryState =
nullptr;
229 mTemporaryState = make_unique<State>(
230 GetEmbeddedState(
static_cast<const Derived*
>(
this)));
231 Base::loseComposite(oldComposite);
243 template <
class BaseT,
class DerivedT,
typename PropertiesDataT,
245 void (*setEmbeddedProperties)(DerivedT*,
const PropertiesT&) =
246 &DefaultSetEmbeddedProperties<DerivedT, PropertiesT>,
247 const PropertiesT& (*getEmbeddedProperties)(
const DerivedT*) =
248 &DefaultGetEmbeddedProperties<DerivedT, PropertiesT> >
261 constexpr
static void (*SetEmbeddedProperties)(
Derived*,
const Properties&) = setEmbeddedProperties;
262 constexpr
static const Properties& (*GetEmbeddedProperties)(
const Derived*) = getEmbeddedProperties;
269 template <
typename T>
272 using type =
typename std::conditional<
273 std::is_base_of<PropertiesData, T>::value,
299 template <
typename T,
typename... RemainingArgs>
302 RemainingArgs&&... remainingArgs)
306 std::forward<RemainingArgs>(remainingArgs)...)
320 if(this->hasComposite())
328 mTemporaryProperties = make_unique<Properties>(
properties);
334 return &getProperties();
340 if(this->hasComposite())
342 return GetEmbeddedProperties(
static_cast<const Derived*
>(
this));
345 if(!mTemporaryProperties)
347 dterr <<
"[detail::EmbeddedPropertiesAspect::getProperties] This Aspect "
348 <<
"is not in a Composite, but it also does not have temporary "
349 <<
"Properties available. This should not happen! Please report "
350 <<
"this as a bug!\n";
354 return *mTemporaryProperties;
359 return make_unique<Derived>(this->getProperties());
366 template <
typename... RemainingArgs>
369 RemainingArgs&&... remainingArgs)
370 :
Base(
std::forward<RemainingArgs>(remainingArgs)...),
378 template <
typename... BaseArgs>
381 :
Base(
std::forward<BaseArgs>(args)...)
389 assert(
nullptr == this->getComposite());
391 Base::setComposite(newComposite);
392 if(mTemporaryProperties)
393 SetEmbeddedProperties(
static_cast<Derived*
>(
this), *mTemporaryProperties);
396 mTemporaryProperties =
nullptr;
402 mTemporaryProperties = make_unique<Properties>(
403 GetEmbeddedProperties(
static_cast<Derived*
>(
this)));
404 Base::loseComposite(oldComposite);
423 template <
class BaseT,
class DerivedT,
typename StateDataT,
425 void (*setEmbeddedState)(DerivedT*,
const StateT&),
426 const StateT& (*getEmbeddedState)(
const DerivedT*)>
428 BaseT, DerivedT, StateDataT, StateT, setEmbeddedState,
429 getEmbeddedState>::SetEmbeddedState)(DerivedT*,
const StateT&);
432 template <
class BaseT,
class DerivedT,
typename StateDataT,
434 void (*setEmbeddedState)(DerivedT*,
const StateT&),
435 const StateT& (*getEmbeddedState)(
const DerivedT*)>
437 BaseT, DerivedT, StateDataT, StateT, setEmbeddedState,
438 getEmbeddedState>::GetEmbeddedState)(
const DerivedT*);
441 template <
class BaseT,
class DerivedT,
typename PropertiesDataT,
442 typename PropertiesT,
443 void (*setEmbeddedProperties)(DerivedT*,
const PropertiesT&),
444 const PropertiesT& (*getEmbeddedProperties)(
const DerivedT*)>
446 BaseT, DerivedT, PropertiesDataT, PropertiesT, setEmbeddedProperties,
447 getEmbeddedProperties>::SetEmbeddedProperties)(DerivedT*,
const PropertiesT&);
450 template <
class BaseT,
class DerivedT,
typename PropertiesDataT,
451 typename PropertiesT,
452 void (*setEmbeddedProperties)(DerivedT*,
const PropertiesT&),
453 const PropertiesT& (*getEmbeddedProperties)(
const DerivedT*)>
455 BaseT, DerivedT, PropertiesDataT, PropertiesT, setEmbeddedProperties,
456 getEmbeddedProperties>::GetEmbeddedProperties)(
const DerivedT*);
#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:83
If your Aspect has a State, then that State class should inherit this Aspect::State class.
Definition: Aspect.hpp:64
Composite is a base class that should be virtually inherited by any class that wants to be able to ma...
Definition: Composite.hpp:52
The MakeCloneable class is used to easily create an Cloneable (such as Node::State) which simply take...
Definition: Cloneable.hpp:85
Definition: EmbeddedAspect.hpp:250
PropertiesDataT PropertiesData
Definition: EmbeddedAspect.hpp:260
const Aspect::Properties * getAspectProperties() const override final
Definition: EmbeddedAspect.hpp:332
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:367
std::unique_ptr< Properties > mTemporaryProperties
After this Aspect is constructed and during transitions between Composite objects,...
Definition: EmbeddedAspect.hpp:411
void setComposite(Composite *newComposite) override
Pass the temporary Properties of this Aspect into the new Composite.
Definition: EmbeddedAspect.hpp:387
virtual ~EmbeddedPropertiesAspect()=default
BaseT Base
Definition: EmbeddedAspect.hpp:257
std::unique_ptr< Aspect > cloneAspect() const override
Definition: EmbeddedAspect.hpp:357
PropertiesT Properties
Definition: EmbeddedAspect.hpp:259
DelegateTag
Definition: EmbeddedAspect.hpp:253
const Properties & getProperties() const
Definition: EmbeddedAspect.hpp:338
DerivedT Derived
Definition: EmbeddedAspect.hpp:258
EmbeddedPropertiesAspect(const T &arg1, RemainingArgs &&... remainingArgs)
Construct this Aspect.
Definition: EmbeddedAspect.hpp:300
void setAspectProperties(const Aspect::Properties &properties) override final
Definition: EmbeddedAspect.hpp:312
EmbeddedPropertiesAspect(DelegateTag, BaseArgs &&... args)
Construct this Aspect without affecting the Properties, and pass all the arguments into the construct...
Definition: EmbeddedAspect.hpp:379
void setProperties(const Properties &properties)
Definition: EmbeddedAspect.hpp:318
void loseComposite(Composite *oldComposite) override
Save the embedded Properties of this Composite before we remove the Aspect.
Definition: EmbeddedAspect.hpp:400
EmbeddedPropertiesAspect()
Construct this Aspect without affecting the Properties.
Definition: EmbeddedAspect.hpp:278
Definition: EmbeddedAspect.hpp:79
void setState(const State &state)
Set the State of this Aspect.
Definition: EmbeddedAspect.hpp:145
void loseComposite(Composite *oldComposite) override
Save the embedded State of this Composite before we remove the Aspect.
Definition: EmbeddedAspect.hpp:227
std::unique_ptr< Aspect > cloneAspect() const override
Definition: EmbeddedAspect.hpp:185
DelegateTag
Definition: EmbeddedAspect.hpp:89
DerivedT Derived
Definition: EmbeddedAspect.hpp:83
StateDataT StateData
Definition: EmbeddedAspect.hpp:85
StateT State
Definition: EmbeddedAspect.hpp:84
void setAspectState(const Aspect::State &state) override final
Definition: EmbeddedAspect.hpp:139
const Aspect::State * getAspectState() const override final
Definition: EmbeddedAspect.hpp:159
BaseT Base
Definition: EmbeddedAspect.hpp:82
const State & getState() const
Get the State of this Aspect.
Definition: EmbeddedAspect.hpp:165
virtual ~EmbeddedStateAspect()=default
void setComposite(Composite *newComposite) override
Pass the temporary State of this Aspect into the new Composite.
Definition: EmbeddedAspect.hpp:215
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:207
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:195
EmbeddedStateAspect(const T &arg1, RemainingArgs &&... remainingArgs)
Construct this Aspect.
Definition: EmbeddedAspect.hpp:127
EmbeddedStateAspect()
Construct this Aspect without affecting the State.
Definition: EmbeddedAspect.hpp:105
std::unique_ptr< State > mTemporaryState
After this Aspect is constructed and during transitions between Composite objects,...
Definition: EmbeddedAspect.hpp:238
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:66
std::unique_ptr< T > make_unique(Args &&... args)
Definition: Memory-impl.hpp:66
Definition: BulletCollisionDetector.cpp:63
Definition: SharedLibraryManager.hpp:43
Used to identify constructor arguments that can be used as Properties.
Definition: EmbeddedAspect.hpp:271
typename std::conditional< std::is_base_of< PropertiesData, T >::value, PropertiesData, T >::type type
Definition: EmbeddedAspect.hpp:274
Used to identify constructor arguments that can be used as a State.
Definition: EmbeddedAspect.hpp:98
typename std::conditional< std::is_base_of< StateData, T >::value, StateData, T >::type type
Definition: EmbeddedAspect.hpp:101