33 #ifndef DART_COMMON_COMPOSITE_HPP_
34 #define DART_COMMON_COMPOSITE_HPP_
58 using AspectMap = std::map< std::type_index, std::unique_ptr<Aspect> >;
61 template <
typename... Aspects>
64 template <
typename... Aspects>
102 void set(
const T* aspect);
108 void set(std::unique_ptr<T>&& aspect);
111 template <
class T,
typename ...Args>
176 void _set(std::type_index type_idx,
const Aspect* aspect);
179 void _set(std::type_index type_idx, std::unique_ptr<Aspect> aspect);
198 template <
class T,
class NextAspect,
class... Aspects>
Definition: Aspect.hpp:47
Composite is a base class that should be virtually inherited by any class that wants to be able to ma...
Definition: Composite.hpp:52
std::unordered_set< std::type_index > RequiredAspectSet
Definition: Composite.hpp:59
RequiredAspectSet mRequiredAspects
A set containing type information for Aspects which are not allowed to leave this composite.
Definition: Composite.hpp:186
State getCompositeState() const
Get the states of the aspects inside of this Composite.
Definition: Composite.cpp:154
void duplicateAspects(const Composite *fromComposite)
Give this Composite a copy of each Aspect from otherComposite.
Definition: Composite.cpp:197
static constexpr bool isSpecializedFor()
Check if this Composite is specialized for a specific type of Aspect.
Definition: Composite.hpp:131
void copyCompositeStateTo(State &outgoingStates) const
Fill outgoingStates with the states of the aspects inside this Composite.
Definition: Composite.cpp:163
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:278
T * get()
Get a certain type of Aspect from this Composite.
Definition: Composite.hpp:59
Composite & operator=(const Composite &)=delete
It is currently unsafe to copy an Composite.
Properties getCompositeProperties() const
Get the properties of the aspects inside of this Composite.
Definition: Composite.cpp:179
void addToComposite(Aspect *aspect)
Add this Aspect to the Composite.
Definition: Composite.cpp:264
void removeFromComposite(Aspect *aspect)
Remove this Aspect from the Composite.
Definition: Composite.cpp:271
Composite(Composite &&)=delete
It is currently unsafe to move an Composite.
Composite & operator=(Composite &&)=delete
It is currently unsafe to move an Composite.
Composite()=default
Default constructor.
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
void setCompositeProperties(const Properties &newProperties)
Set the properties of the aspects in this Composite based on the given Composite::Properties.
Definition: Composite.cpp:171
std::map< std::type_index, std::unique_ptr< Aspect > > AspectMap
Definition: Composite.hpp:58
bool has() const
Check if this Composite currently has a certain type of Aspect.
Definition: Composite.hpp:52
void copyCompositePropertiesTo(Properties &outgoingProperties) const
Fill outgoingProperties with the properties of the aspects inside this Composite.
Definition: Composite.cpp:188
Composite(const Composite &)=delete
It is currently unsafe to copy an Composite.
void setCompositeState(const State &newStates)
Set the states of the aspects in this Composite based on the given Composite::State.
Definition: Composite.cpp:147
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:182
virtual ~Composite()=default
Virtual destructor.
void matchAspects(const Composite *otherComposite)
Make the Aspects of this Composite match the Aspects of otherComposite.
Definition: Composite.cpp:247
void set(const T *aspect)
Make a clone of the aspect and place the clone into this Composite.
Definition: Composite.hpp:77
Definition: CompositeData.hpp:180
Definition: CompositeData.hpp:104
CompositeData< CompositeStateMap, GetState > CompositeState
Definition: CompositeData.hpp:174
CompositeData< CompositePropertiesMap, GetProperties > CompositeProperties
Definition: CompositeData.hpp:175
void createAspects(T *)
Attach an arbitrary number of Aspects to the specified Composite type.
Definition: Composite.hpp:145
Definition: BulletCollisionDetector.cpp:63