DART  6.7.3
dart::common::Composite Class Reference

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>

Inheritance diagram for dart::common::Composite:
dart::common::SpecializedForAspect< SpecAspect >

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...
 
Compositeoperator= (const Composite &)=delete
 It is currently unsafe to copy an Composite. More...
 
Compositeoperator= (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...
 

Detailed Description

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.

Member Typedef Documentation

◆ AspectMap

using dart::common::Composite::AspectMap = std::map< std::type_index, std::unique_ptr<Aspect> >

◆ MakeProperties

template<typename... Aspects>
using dart::common::Composite::MakeProperties = detail::MakeCompositeProperties<Aspects...>

◆ MakeState

template<typename... Aspects>
using dart::common::Composite::MakeState = detail::MakeCompositeState<Aspects...>

◆ Properties

◆ RequiredAspectSet

using dart::common::Composite::RequiredAspectSet = std::unordered_set<std::type_index>

◆ State

Constructor & Destructor Documentation

◆ ~Composite()

virtual dart::common::Composite::~Composite ( )
virtualdefault

Virtual destructor.

◆ Composite() [1/3]

dart::common::Composite::Composite ( )
default

Default constructor.

◆ Composite() [2/3]

dart::common::Composite::Composite ( const Composite )
delete

It is currently unsafe to copy an Composite.

◆ Composite() [3/3]

dart::common::Composite::Composite ( Composite &&  )
delete

It is currently unsafe to move an Composite.

Member Function Documentation

◆ _set() [1/2]

void dart::common::Composite::_set ( std::type_index  type_idx,
const Aspect aspect 
)
protected

Non-templated version of set(const T*)

◆ _set() [2/2]

void dart::common::Composite::_set ( std::type_index  type_idx,
std::unique_ptr< Aspect aspect 
)
protected

Non-templated version of set(std::unqiue_ptr<T>&&)

◆ addToComposite()

void dart::common::Composite::addToComposite ( Aspect aspect)
protected

Add this Aspect to the Composite.

This allows derived Composite types to call the protected Aspect::setComposite function.

◆ copyCompositePropertiesTo()

void dart::common::Composite::copyCompositePropertiesTo ( Properties outgoingProperties) const

Fill outgoingProperties with the properties of the aspects inside this Composite.

◆ copyCompositeStateTo()

void dart::common::Composite::copyCompositeStateTo ( State outgoingStates) const

Fill outgoingStates with the states of the aspects inside this Composite.

◆ createAspect()

template<class T , typename ... Args>
T * dart::common::Composite::createAspect ( Args &&...  args)

Construct an Aspect inside of this Composite.

◆ duplicateAspects()

void dart::common::Composite::duplicateAspects ( const Composite fromComposite)

Give this Composite a copy of each Aspect from otherComposite.

◆ get() [1/2]

template<class T >
T * dart::common::Composite::get

Get a certain type of Aspect from this Composite.

◆ get() [2/2]

template<class T >
const T * dart::common::Composite::get

Get a certain type of Aspect from this Composite.

◆ getCompositeProperties()

Composite::Properties dart::common::Composite::getCompositeProperties ( ) const

Get the properties of the aspects inside of this Composite.

◆ getCompositeState()

Composite::State dart::common::Composite::getCompositeState ( ) const

Get the states of the aspects inside of this Composite.

◆ has()

template<class T >
bool dart::common::Composite::has

Check if this Composite currently has a certain type of Aspect.

◆ isSpecializedFor()

template<class T >
constexpr bool dart::common::Composite::isSpecializedFor
staticconstexpr

Check if this Composite is specialized for a specific type of Aspect.

By default, this simply returns false.

◆ matchAspects()

void dart::common::Composite::matchAspects ( const Composite otherComposite)

Make the Aspects of this Composite match the Aspects of otherComposite.

Any Aspects in this Composite which do not exist in otherComposite will be erased.

◆ operator=() [1/2]

Composite& dart::common::Composite::operator= ( Composite &&  )
delete

It is currently unsafe to move an Composite.

◆ operator=() [2/2]

Composite& dart::common::Composite::operator= ( const Composite )
delete

It is currently unsafe to copy an Composite.

◆ releaseAspect()

template<class T >
std::unique_ptr< T > dart::common::Composite::releaseAspect

Remove an Aspect from this Composite, but return its unique_ptr instead of letting it be deleted.

This allows you to safely use move semantics to transfer an Aspect between two Composites.

◆ removeAspect()

template<class T >
void dart::common::Composite::removeAspect

Remove an Aspect from this Composite.

◆ removeFromComposite()

void dart::common::Composite::removeFromComposite ( Aspect aspect)
protected

Remove this Aspect from the Composite.

This allows derived Composite types to call the protected Aspect::loseComposite function.

◆ requiresAspect()

template<class T >
bool dart::common::Composite::requiresAspect

Check if this Composite requires this specific type of Aspect.

◆ set() [1/2]

template<class T >
void dart::common::Composite::set ( const T *  aspect)

Make a clone of the aspect and place the clone into this Composite.

If an Aspect of the same type already exists in this Composite, the existing Aspect will be destroyed.

◆ set() [2/2]

template<class T >
void dart::common::Composite::set ( std::unique_ptr< T > &&  aspect)

Use move semantics to place aspect into this Composite.

If an Aspect of the same type already exists in this Composite, the existing Aspect will be destroyed.

◆ setCompositeProperties()

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.

◆ setCompositeState()

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.

Member Data Documentation

◆ mAspectMap

AspectMap dart::common::Composite::mAspectMap
protected

A map that relates the type of Aspect to its pointer.

◆ mRequiredAspects

RequiredAspectSet dart::common::Composite::mRequiredAspects
protected

A set containing type information for Aspects which are not allowed to leave this composite.