DART  6.7.3
dart::common::SpecializedForAspect< SpecAspect > Class Template Reference

SpecializedForAspect allows classes that inherit Composite to have constant-time access to a specific type of Aspect. More...

#include <SpecializedForAspect.hpp>

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

Classes

struct  type
 

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

 SpecializedForAspect ()
 Default Constructor. More...
 
virtual ~SpecializedForAspect ()=default
 
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 an 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

template<class T >
bool _has (type< T >) const
 Redirect to Composite::has() More...
 
bool _has (type< SpecAspect >) const
 Specialized implementation of has() More...
 
template<class T >
T * _get (type< T >)
 Redirect to Composite::get() More...
 
SpecAspect * _get (type< SpecAspect >)
 Specialized implementation of get() More...
 
template<class T >
const T * _get (type< T >) const
 Redirect to Composite::get() More...
 
const SpecAspect * _get (type< SpecAspect >) const
 Specialized implementation of get() More...
 
template<class T >
void _set (type< T >, const T *aspect)
 Redirect to Composite::set() More...
 
void _set (type< SpecAspect >, const SpecAspect *aspect)
 Specialized implementation of set() More...
 
template<class T >
void _set (type< T >, std::unique_ptr< T > &&aspect)
 Redirect to Composite::set() More...
 
void _set (type< SpecAspect >, std::unique_ptr< SpecAspect > &&aspect)
 Specialized implementation of set() More...
 
template<class T , typename ... Args>
T * _createAspect (type< T >, Args &&... args)
 Redirect to Composite::create() More...
 
template<typename ... Args>
SpecAspect * _createAspect (type< SpecAspect >, Args &&... args)
 Specialized implementation of create() More...
 
template<class T >
void _removeAspect (type< T >)
 Redirect to Composite::erase() More...
 
void _removeAspect (type< SpecAspect >)
 Specialized implementation of erase() More...
 
template<class T >
std::unique_ptr< T > _releaseAspect (type< T >)
 Redirect to Composite::release() More...
 
std::unique_ptr< SpecAspect > _releaseAspect (type< SpecAspect >)
 Specialized implementation of release() More...
 
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...
 

Static Protected Member Functions

template<class T >
static constexpr bool _isSpecializedFor (type< T >)
 Return false. More...
 
static constexpr bool _isSpecializedFor (type< SpecAspect >)
 Return true. More...
 

Protected Attributes

Composite::AspectMap::iterator mSpecAspectIterator
 Iterator that points to the Aspect of this SpecializedForAspect. More...
 
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

template<class SpecAspect>
class dart::common::SpecializedForAspect< SpecAspect >

SpecializedForAspect allows classes that inherit Composite to have constant-time access to a specific type of Aspect.

Member Typedef Documentation

◆ AspectMap

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

◆ MakeProperties

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

◆ MakeState

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

◆ Properties

◆ RequiredAspectSet

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

◆ State

Constructor & Destructor Documentation

◆ SpecializedForAspect()

template<class SpecAspect >
dart::common::SpecializedForAspect< SpecAspect >::SpecializedForAspect

Default Constructor.

◆ ~SpecializedForAspect()

template<class SpecAspect >
virtual dart::common::SpecializedForAspect< SpecAspect >::~SpecializedForAspect ( )
virtualdefault

Member Function Documentation

◆ _createAspect() [1/2]

template<class SpecAspect >
template<typename ... Args>
SpecAspect * dart::common::SpecializedForAspect< SpecAspect >::_createAspect ( type< SpecAspect >  ,
Args &&...  args 
)
protected

Specialized implementation of create()

◆ _createAspect() [2/2]

template<class SpecAspect >
template<class T , typename ... Args>
T * dart::common::SpecializedForAspect< SpecAspect >::_createAspect ( type< T >  ,
Args &&...  args 
)
protected

Redirect to Composite::create()

◆ _get() [1/4]

template<class SpecAspect >
SpecAspect * dart::common::SpecializedForAspect< SpecAspect >::_get ( type< SpecAspect >  )
protected

Specialized implementation of get()

◆ _get() [2/4]

template<class SpecAspect >
const SpecAspect * dart::common::SpecializedForAspect< SpecAspect >::_get ( type< SpecAspect >  ) const
protected

Specialized implementation of get()

◆ _get() [3/4]

template<class SpecAspect >
template<class T >
T * dart::common::SpecializedForAspect< SpecAspect >::_get ( type< T >  )
protected

Redirect to Composite::get()

◆ _get() [4/4]

template<class SpecAspect >
template<class T >
const T * dart::common::SpecializedForAspect< SpecAspect >::_get ( type< T >  ) const
protected

Redirect to Composite::get()

◆ _has() [1/2]

template<class SpecAspect >
bool dart::common::SpecializedForAspect< SpecAspect >::_has ( type< SpecAspect >  ) const
protected

Specialized implementation of has()

◆ _has() [2/2]

template<class SpecAspect >
template<class T >
bool dart::common::SpecializedForAspect< SpecAspect >::_has ( type< T >  ) const
protected

Redirect to Composite::has()

◆ _isSpecializedFor() [1/2]

template<class SpecAspect >
constexpr bool dart::common::SpecializedForAspect< SpecAspect >::_isSpecializedFor ( type< SpecAspect >  )
staticconstexprprotected

Return true.

◆ _isSpecializedFor() [2/2]

template<class SpecAspect >
template<class T >
constexpr bool dart::common::SpecializedForAspect< SpecAspect >::_isSpecializedFor ( type< T >  )
staticconstexprprotected

Return false.

◆ _releaseAspect() [1/2]

template<class SpecAspect >
std::unique_ptr< SpecAspect > dart::common::SpecializedForAspect< SpecAspect >::_releaseAspect ( type< SpecAspect >  )
protected

Specialized implementation of release()

◆ _releaseAspect() [2/2]

template<class SpecAspect >
template<class T >
std::unique_ptr< T > dart::common::SpecializedForAspect< SpecAspect >::_releaseAspect ( type< T >  )
protected

Redirect to Composite::release()

◆ _removeAspect() [1/2]

template<class SpecAspect >
void dart::common::SpecializedForAspect< SpecAspect >::_removeAspect ( type< SpecAspect >  )
protected

Specialized implementation of erase()

◆ _removeAspect() [2/2]

template<class SpecAspect >
template<class T >
void dart::common::SpecializedForAspect< SpecAspect >::_removeAspect ( type< T >  )
protected

Redirect to Composite::erase()

◆ _set() [1/6]

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

Non-templated version of set(const T*)

◆ _set() [2/6]

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

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

◆ _set() [3/6]

template<class SpecAspect >
void dart::common::SpecializedForAspect< SpecAspect >::_set ( type< SpecAspect >  ,
const SpecAspect *  aspect 
)
protected

Specialized implementation of set()

◆ _set() [4/6]

template<class SpecAspect >
void dart::common::SpecializedForAspect< SpecAspect >::_set ( type< SpecAspect >  ,
std::unique_ptr< SpecAspect > &&  aspect 
)
protected

Specialized implementation of set()

◆ _set() [5/6]

template<class SpecAspect >
template<class T >
void dart::common::SpecializedForAspect< SpecAspect >::_set ( type< T >  ,
const T *  aspect 
)
protected

Redirect to Composite::set()

Using the type<T> tag for this is not be necessary, but it helps to avoid confusion between the set() versus _set() function.

◆ _set() [6/6]

template<class SpecAspect >
template<class T >
void dart::common::SpecializedForAspect< SpecAspect >::_set ( type< T >  ,
std::unique_ptr< T > &&  aspect 
)
protected

Redirect to Composite::set()

Using the type<T> tag for this is not be necessary, but it helps to avoid confusion between the set() versus _set() function.

◆ addToComposite()

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

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
inherited

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

◆ copyCompositeStateTo()

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

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

◆ createAspect()

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

Construct an Aspect inside of this Composite.

◆ duplicateAspects()

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

Give this Composite a copy of each Aspect from otherComposite.

◆ get() [1/2]

template<class SpecAspect >
template<class T >
T * dart::common::SpecializedForAspect< SpecAspect >::get

Get a certain type of Aspect from this Composite.

◆ get() [2/2]

template<class SpecAspect >
template<class T >
const T * dart::common::SpecializedForAspect< SpecAspect >::get

Get a certain type of Aspect from this Composite.

◆ getCompositeProperties()

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

Get the properties of the aspects inside of this Composite.

◆ getCompositeState()

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

Get the states of the aspects inside of this Composite.

◆ has()

template<class SpecAspect >
template<class T >
bool dart::common::SpecializedForAspect< SpecAspect >::has

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

◆ isSpecializedFor()

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

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

◆ matchAspects()

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

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.

◆ releaseAspect()

template<class SpecAspect >
template<class T >
std::unique_ptr< T > dart::common::SpecializedForAspect< SpecAspect >::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 SpecAspect >
template<class T >
void dart::common::SpecializedForAspect< SpecAspect >::removeAspect

Remove an Aspect from this Composite.

◆ removeFromComposite()

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

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
inherited

Check if this Composite requires this specific type of Aspect.

◆ set() [1/2]

template<class SpecAspect >
template<class T >
void dart::common::SpecializedForAspect< SpecAspect >::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 SpecAspect >
template<class T >
void dart::common::SpecializedForAspect< SpecAspect >::set ( std::unique_ptr< T > &&  aspect)

Use move semantics to place an 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)
inherited

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)
inherited

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
protectedinherited

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

◆ mRequiredAspects

RequiredAspectSet dart::common::Composite::mRequiredAspects
protectedinherited

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

◆ mSpecAspectIterator

template<class SpecAspect >
Composite::AspectMap::iterator dart::common::SpecializedForAspect< SpecAspect >::mSpecAspectIterator
protected

Iterator that points to the Aspect of this SpecializedForAspect.