DART
6.10.1
|
Composite is a base class that should be virtually inherited by any class that wants to be able to manage Aspects. More...
#include <Composite.hpp>
Public Types | |
using | State = detail::CompositeState |
using | Properties = detail::CompositeProperties |
using | AspectMap = std::map< std::type_index, std::unique_ptr< Aspect > > |
using | RequiredAspectSet = std::unordered_set< std::type_index > |
template<typename... Aspects> | |
using | MakeState = detail::MakeCompositeState< Aspects... > |
template<typename... Aspects> | |
using | MakeProperties = detail::MakeCompositeProperties< Aspects... > |
Public Member Functions | |
virtual | ~Composite ()=default |
Virtual destructor. More... | |
Composite ()=default | |
Default constructor. More... | |
Composite (const Composite &)=delete | |
It is currently unsafe to copy an Composite. More... | |
Composite (Composite &&)=delete | |
It is currently unsafe to move an Composite. More... | |
Composite & | operator= (const Composite &)=delete |
It is currently unsafe to copy an Composite. More... | |
Composite & | operator= (Composite &&)=delete |
It is currently unsafe to move an Composite. More... | |
template<class T > | |
bool | has () const |
Check if this Composite currently has a certain type of Aspect. More... | |
template<class T > | |
T * | get () |
Get a certain type of Aspect from this Composite. More... | |
template<class T > | |
const T * | get () const |
Get a certain type of Aspect from this Composite. More... | |
template<class T > | |
void | set (const T *aspect) |
Make a clone of the aspect and place the clone into this Composite. More... | |
template<class T > | |
void | set (std::unique_ptr< T > &&aspect) |
Use move semantics to place aspect into this Composite. More... | |
template<class T , typename... Args> | |
T * | createAspect (Args &&... args) |
Construct an Aspect inside of this Composite. More... | |
template<class T > | |
void | removeAspect () |
Remove an Aspect from this Composite. More... | |
template<class T > | |
std::unique_ptr< T > | releaseAspect () |
Remove an Aspect from this Composite, but return its unique_ptr instead of letting it be deleted. More... | |
template<class T > | |
bool | requiresAspect () const |
Check if this Composite requires this specific type of Aspect. More... | |
void | setCompositeState (const State &newStates) |
Set the states of the aspects in this Composite based on the given Composite::State. More... | |
State | getCompositeState () const |
Get the states of the aspects inside of this Composite. More... | |
void | copyCompositeStateTo (State &outgoingStates) const |
Fill outgoingStates with the states of the aspects inside this Composite. More... | |
void | setCompositeProperties (const Properties &newProperties) |
Set the properties of the aspects in this Composite based on the given Composite::Properties. More... | |
Properties | getCompositeProperties () const |
Get the properties of the aspects inside of this Composite. More... | |
void | copyCompositePropertiesTo (Properties &outgoingProperties) const |
Fill outgoingProperties with the properties of the aspects inside this Composite. More... | |
void | duplicateAspects (const Composite *fromComposite) |
Give this Composite a copy of each Aspect from otherComposite. More... | |
void | matchAspects (const Composite *otherComposite) |
Make the Aspects of this Composite match the Aspects of otherComposite. More... | |
Static Public Member Functions | |
template<class T > | |
static constexpr bool | isSpecializedFor () |
Check if this Composite is specialized for a specific type of Aspect. More... | |
Protected Member Functions | |
void | addToComposite (Aspect *aspect) |
Add this Aspect to the Composite. More... | |
void | removeFromComposite (Aspect *aspect) |
Remove this Aspect from the Composite. More... | |
void | _set (std::type_index type_idx, const Aspect *aspect) |
Non-templated version of set(const T*) More... | |
void | _set (std::type_index type_idx, std::unique_ptr< Aspect > aspect) |
Non-templated version of set(std::unqiue_ptr<T>&&) More... | |
Protected Attributes | |
AspectMap | mAspectMap |
A map that relates the type of Aspect to its pointer. More... | |
RequiredAspectSet | mRequiredAspects |
A set containing type information for Aspects which are not allowed to leave this composite. More... | |
Composite is a base class that should be virtually inherited by any class that wants to be able to manage Aspects.
The base Composite class is completely agnostic to what kind of Aspects it is given. Aspects are stored in a std::map, so access to its Aspects happens on average in log(N) time. Most often, a class that accepts Aspects will have certain Aspect types that it will need to access frequently, and it would be beneficial to have constant-time access to those Aspect types. To get constant-time access to specific Aspect types, you can use the templated class SpecializedForAspect.
using dart::common::Composite::AspectMap = std::map<std::type_index, std::unique_ptr<Aspect> > |
using dart::common::Composite::MakeProperties = detail::MakeCompositeProperties<Aspects...> |
using dart::common::Composite::MakeState = detail::MakeCompositeState<Aspects...> |
using dart::common::Composite::RequiredAspectSet = std::unordered_set<std::type_index> |
|
virtualdefault |
Virtual destructor.
|
default |
Default constructor.
|
delete |
It is currently unsafe to copy an Composite.
|
delete |
It is currently unsafe to move an Composite.
|
protected |
Non-templated version of set(const T*)
|
protected |
Non-templated version of set(std::unqiue_ptr<T>&&)
|
protected |
Add this Aspect to the Composite.
This allows derived Composite types to call the protected Aspect::setComposite function.
void dart::common::Composite::copyCompositePropertiesTo | ( | Properties & | outgoingProperties | ) | const |
Fill outgoingProperties with the properties of the aspects inside this Composite.
void dart::common::Composite::copyCompositeStateTo | ( | State & | outgoingStates | ) | const |
Fill outgoingStates with the states of the aspects inside this Composite.
T * dart::common::Composite::createAspect | ( | Args &&... | args | ) |
void dart::common::Composite::duplicateAspects | ( | const Composite * | fromComposite | ) |
T * dart::common::Composite::get |
const T * dart::common::Composite::get |
Composite::Properties dart::common::Composite::getCompositeProperties | ( | ) | const |
Get the properties of the aspects inside of this Composite.
Composite::State dart::common::Composite::getCompositeState | ( | ) | const |
Get the states of the aspects inside of this Composite.
bool dart::common::Composite::has |
|
staticconstexpr |
void dart::common::Composite::matchAspects | ( | const Composite * | otherComposite | ) |
It is currently unsafe to move an Composite.
It is currently unsafe to copy an Composite.
std::unique_ptr< T > dart::common::Composite::releaseAspect |
|
protected |
Remove this Aspect from the Composite.
This allows derived Composite types to call the protected Aspect::loseComposite function.
bool dart::common::Composite::requiresAspect |
void dart::common::Composite::set | ( | const T * | aspect | ) |
void dart::common::Composite::set | ( | std::unique_ptr< T > && | aspect | ) |
void dart::common::Composite::setCompositeProperties | ( | const Properties & | newProperties | ) |
Set the properties of the aspects in this Composite based on the given Composite::Properties.
The properties of any Aspect types that do not exist within this composite will be ignored.
void dart::common::Composite::setCompositeState | ( | const State & | newStates | ) |
Set the states of the aspects in this Composite based on the given Composite::State.
The states of any Aspect types that do not exist within this composite will be ignored.
|
protected |
A map that relates the type of Aspect to its pointer.
|
protected |
A set containing type information for Aspects which are not allowed to leave this composite.