33 #ifndef DART_COMMON_DETAIL_COMPOSITEDATA_HPP_
34 #define DART_COMMON_DETAIL_COMPOSITEDATA_HPP_
41 #include <unordered_set>
52 template <
class AspectOrComposite,
bool isAspect>
55 using Type = AspectOrComposite;
61 template <
class AspectOrComposite>
72 using Type =
typename AspectOrComposite::Aspect;
76 template <
class AspectT>
85 template <
class AspectT>
92 template <
class AspectT>
100 = std::map<std::type_index, std::unique_ptr<Aspect::State>>;
102 = std::map<std::type_index, std::unique_ptr<Aspect::Properties>>;
105 template <
typename MapType,
template <
class>
class GetData>
110 template <
typename... Args>
120 template <
class AspectT,
typename... Args>
121 typename GetData<AspectT>::Type&
create(Args&&... args)
123 using Data =
typename GetData<AspectT>::Type;
125 using DataType =
typename GetData<Aspect>::Type;
127 std::unique_ptr<DataType>& data = this->
mMap[
typeid(AspectType)]
128 = std::make_unique<Data>(std::forward<Args>(args)...);
129 return static_cast<Data&
>(*data);
132 template <
class AspectT>
133 typename GetData<AspectT>::Type*
get()
135 using Data =
typename GetData<AspectT>::Type;
139 if (this->
mMap.end() == it)
142 return static_cast<Data*
>(it->second.get());
145 template <
class AspectT>
146 const typename GetData<AspectT>::Type*
get()
const
151 template <
class AspectT,
typename... Args>
154 using Data =
typename GetData<AspectT>::Type;
157 auto& it = this->
mMap.insert(
158 std::make_pair<std::type_index, std::unique_ptr<Data>>(
159 typeid(AspectType),
nullptr));
161 const bool exists = !it.second;
163 it.first = std::make_unique<Data>(std::forward<Args>(args)...);
165 return static_cast<Data&
>(*it.first);
168 template <
class AspectT>
171 return (get<AspectT>() !=
nullptr);
183 template <
class>
class GetData,
212 template <
class>
class GetData,
214 typename... Remainder>
216 :
public GetData<AspectT>::Type,
217 public ComposeData<CompositeType, GetData, Remainder...>
226 using Base =
typename GetData<AspectT>::Type;
227 using Data =
typename Base::Data;
230 template <
typename Arg>
233 using Type =
typename std::conditional<
234 std::is_base_of<typename Base::Data, Arg>::value,
239 template <
typename Arg>
240 struct ConvertIfComposite
242 using Type =
typename std::conditional<
243 std::is_base_of<CompositeType, Arg>::value,
249 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
257 template <typename Arg1, typename... Args>
261 static_cast<const typename ConvertIfData<Arg1>::Type&>(arg1),
269 :
ComposeData<CompositeType, GetData, Remainder...>(composite)
271 _setBaseFrom(composite);
274 template <
typename... Aspects>
276 :
ComposeData(static_cast<const CompositeType&>(composite))
287 :
ComposeData(static_cast<const CompositeType&>(composite))
292 operator CompositeType()
const
294 CompositeType composite;
302 _setBaseFrom(composite);
316 template <
typename... Args>
323 template <
typename... Args>
325 :
ComposeData<CompositeType, GetData, Remainder...>(args...)
330 template <
typename... Args>
332 :
Base(arg1),
ComposeData<CompositeType, GetData, Remainder...>(args...)
339 const Base* data = composite.template get<AspectType>();
341 static_cast<Base&
>(*this) = *data;
346 composite.template create<AspectType>(
static_cast<const Base&
>(*
this));
355 template <
typename Arg1,
typename... Args>
362 template <
typename Arg>
370 static_cast<Base&
>(*this) = data;
375 _setBaseFrom(composite);
380 template <
typename... Aspects>
383 template <
typename... Data>
#define DART_DEFINE_ALIGNED_SHARED_OBJECT_CREATOR(class_name)
Definition: Memory.hpp:155
std::string type
Definition: SdfParser.cpp:82
MapHolder is a templated wrapper class that is used to allow maps of Aspect::State and Aspect::Proper...
Definition: Cloneable.hpp:221
MapType mMap
A map containing the collection of States for the Aspect.
Definition: Cloneable.hpp:280
Definition: CompositeData.hpp:186
ComposeData(const CompositeType &)
Definition: CompositeData.hpp:190
void _addData(CompositeType &) const
Definition: CompositeData.hpp:203
virtual ~ComposeData()=default
void setFrom(const CompositeType &)
Definition: CompositeData.hpp:197
Definition: CompositeData.hpp:107
bool has() const
Definition: CompositeData.hpp:169
virtual ~CompositeData()=default
GetData< AspectT >::Type & getOrCreate(Args &&... args)
Definition: CompositeData.hpp:152
GetData< AspectT >::Type & create(Args &&... args)
Create (or replace) a piece of data in this.
Definition: CompositeData.hpp:121
GetData< AspectT >::Type * get()
Definition: CompositeData.hpp:133
CompositeData(Args &&... args)
Forwarding constructor.
Definition: CompositeData.hpp:111
const GetData< AspectT >::Type * get() const
Definition: CompositeData.hpp:146
CompositeData< CompositeStateMap, GetState > CompositeState
Definition: CompositeData.hpp:176
std::map< std::type_index, std::unique_ptr< Aspect::State > > CompositeStateMap
Definition: CompositeData.hpp:100
std::map< std::type_index, std::unique_ptr< Aspect::Properties > > CompositePropertiesMap
Definition: CompositeData.hpp:102
CompositeData< CompositePropertiesMap, GetProperties > CompositeProperties
Definition: CompositeData.hpp:178
std::multimap< dart::dynamics::Shape *, SimpleFrameShapeDnD * >::iterator iterator
Definition: Viewer.cpp:620
Definition: BulletCollisionDetector.cpp:65
Definition: SharedLibraryManager.hpp:46
typename std::conditional< std::is_base_of< CompositeType, Arg >::value, CompositeType, Arg >::type Type
Definition: CompositeData.hpp:245
typename std::conditional< std::is_base_of< typename Base::Data, Arg >::value, typename Base::Data, Arg >::type Type
Definition: CompositeData.hpp:236
Definition: CompositeData.hpp:218
void _addData(CompositeType &composite) const
Definition: CompositeData.hpp:344
typename GetData< AspectT >::Type Base
Definition: CompositeData.hpp:226
void _setBaseFrom(const CompositeType &composite)
Definition: CompositeData.hpp:337
ComposeData(DelegateTag, const Args &... args)
Definition: CompositeData.hpp:324
void copy(const Args &... args)
Grab any relevant data and copy it into this composite.
Definition: CompositeData.hpp:317
void _attemptToUse(const Arg &)
Definition: CompositeData.hpp:363
void _attemptToUse(const CompositeType &composite)
Definition: CompositeData.hpp:373
void _findData(const Arg1 &arg1, const Args &... args)
Definition: CompositeData.hpp:356
void setFrom(const CompositeType &composite)
Definition: CompositeData.hpp:300
ComposeData & operator=(const CompositeType &composite)
Definition: CompositeData.hpp:306
ComposeData(DelegateTag, const Data &arg1, const Args &... args)
Definition: CompositeData.hpp:331
DelegateTag
Definition: CompositeData.hpp:221
void _attemptToUse(const typename Base::Data &data)
Definition: CompositeData.hpp:368
ComposeData(const ComposeData< CompositeType, GetData, Aspects... > &composite)
Definition: CompositeData.hpp:275
void _findData()
Definition: CompositeData.hpp:350
ComposeData(CompositeType &&composite)
Definition: CompositeData.hpp:286
typename GetAspect< AspectT >::Type AspectType
Definition: CompositeData.hpp:228
typename Base::Data Data
Definition: CompositeData.hpp:227
ComposeData(const CompositeType &composite)
Grab relevant data out of a composite object.
Definition: CompositeData.hpp:268
typename AspectOrComposite::Aspect Type
Definition: CompositeData.hpp:72
Definition: CompositeData.hpp:54
AspectOrComposite Type
Definition: CompositeData.hpp:55
Definition: CompositeData.hpp:78
typename GetAspectImpl< AspectT, std::is_base_of< Aspect, AspectT >::value >::Type Type
Definition: CompositeData.hpp:81
Definition: CompositeData.hpp:94
typename GetAspect< AspectT >::Type::Properties Type
Definition: CompositeData.hpp:95
Definition: CompositeData.hpp:87
typename GetAspect< AspectT >::Type::State Type
Definition: CompositeData.hpp:88