33 #ifndef DART_COMMON_DETAIL_COMPOSITE_HPP_
34 #define DART_COMMON_DETAIL_COMPOSITE_HPP_
38 #define DART_COMMON_CHECK_ILLEGAL_ASPECT_ERASE(Func, T, ReturnType) \
39 if (requiresAspect<T>()) \
41 dterr << "[Composite::" #Func << "] Illegal request to remove required " \
42 << "Aspect [" << typeid(T).name() << "]!\n"; \
54 return (get<T>() !=
nullptr);
65 return static_cast<T*
>(it->second.get());
72 return const_cast<Composite*
>(
this)->get<T>();
79 _set(
typeid(T), aspect);
86 _set(
typeid(T), std::move(aspect));
90 template <
class T,
typename... Args>
93 T* aspect =
new T(std::forward<Args>(args)...);
94 mAspectMap[
typeid(T)] = std::unique_ptr<T>(aspect);
109 it->second =
nullptr;
117 std::unique_ptr<T> extraction =
nullptr;
123 extraction = std::unique_ptr<T>(
static_cast<T*
>(it->second.release()));
151 template <
class T,
class NextAspect,
class... Aspects>
154 comp->template createAspect<NextAspect>();
164 #define DART_BAKE_SPECIALIZED_ASPECT_IRREGULAR(TypeName, AspectName) \
166 inline bool has##AspectName() const \
168 return this->template has<TypeName>(); \
172 inline TypeName* get##AspectName() \
174 return this->template get<TypeName>(); \
178 inline const TypeName* get##AspectName() const \
180 return this->template get<TypeName>(); \
187 inline TypeName* get##AspectName(const bool createIfNull) \
189 TypeName* aspect = get##AspectName(); \
191 if (createIfNull && nullptr == aspect) \
192 return create##AspectName(); \
202 inline void set##AspectName(const TypeName* aspect) \
204 this->template set<TypeName>(aspect); \
212 inline void set##AspectName(std::unique_ptr<TypeName>&& aspect) \
214 this->template set<TypeName>(std::move(aspect)); \
218 template <typename... Args> \
219 inline TypeName* create##AspectName(Args&&... args) \
221 return this->template createAspect<TypeName>(std::forward<Args>(args)...); \
225 inline void remove##AspectName() \
227 this->template removeAspect<TypeName>(); \
235 inline std::unique_ptr<TypeName> release##AspectName() \
237 return this->template releaseAspect<TypeName>(); \
241 #define DART_BAKE_SPECIALIZED_ASPECT(AspectName) \
242 DART_BAKE_SPECIALIZED_ASPECT_IRREGULAR(AspectName, AspectName);
#define DART_BLANK
Definition: NoOp.hpp:55
Composite is a base class that should be virtually inherited by any class that wants to be able to ma...
Definition: Composite.hpp:53
RequiredAspectSet mRequiredAspects
A set containing type information for Aspects which are not allowed to leave this composite.
Definition: Composite.hpp:185
static constexpr bool isSpecializedFor()
Check if this Composite is specialized for a specific type of Aspect.
Definition: Composite.hpp:131
void removeAspect()
Remove an Aspect from this Composite.
Definition: Composite.hpp:102
bool requiresAspect() const
Check if this Composite requires this specific type of Aspect.
Definition: Composite.hpp:138
void _set(std::type_index type_idx, const Aspect *aspect)
Non-templated version of set(const T*)
Definition: Composite.cpp:287
T * get()
Get a certain type of Aspect from this Composite.
Definition: Composite.hpp:59
void addToComposite(Aspect *aspect)
Add this Aspect to the Composite.
Definition: Composite.cpp:273
void removeFromComposite(Aspect *aspect)
Remove this Aspect from the Composite.
Definition: Composite.cpp:280
std::unique_ptr< T > releaseAspect()
Remove an Aspect from this Composite, but return its unique_ptr instead of letting it be deleted.
Definition: Composite.hpp:115
bool has() const
Check if this Composite currently has a certain type of Aspect.
Definition: Composite.hpp:52
T * createAspect(Args &&... args)
Construct an Aspect inside of this Composite.
Definition: Composite.hpp:91
AspectMap mAspectMap
A map that relates the type of Aspect to its pointer.
Definition: Composite.hpp:181
void set(const T *aspect)
Make a clone of the aspect and place the clone into this Composite.
Definition: Composite.hpp:77
#define DART_COMMON_CHECK_ILLEGAL_ASPECT_ERASE(Func, T, ReturnType)
Definition: Composite.hpp:38
void createAspects(T *)
Attach an arbitrary number of Aspects to the specified Composite type.
Definition: Composite.hpp:145
std::multimap< dart::dynamics::Shape *, SimpleFrameShapeDnD * >::iterator iterator
Definition: Viewer.cpp:620
Definition: BulletCollisionDetector.cpp:65