33 #ifndef DART_COMMON_DETAIL_COMPOSITEDATA_HPP_
34 #define DART_COMMON_DETAIL_COMPOSITEDATA_HPP_
39 #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>
80 AspectT, std::is_base_of<Aspect, AspectT>::value>
::Type;
84 template <
class AspectT>
91 template <
class AspectT>
102 template <
typename MapType,
template <
class>
class GetData>
108 template <
typename... Args>
118 template <
class AspectT,
typename... Args>
119 typename GetData<AspectT>::Type&
create(Args&&... args)
121 using Data =
typename GetData<AspectT>::Type;
123 using DataType =
typename GetData<Aspect>::Type;
125 std::unique_ptr<DataType>& data = this->
mMap[
typeid(AspectType)]
126 = make_unique<Data>(std::forward<Args>(args)...);
127 return static_cast<Data&
>(*data);
130 template <
class AspectT>
131 typename GetData<AspectT>::Type*
get()
133 using Data =
typename GetData<AspectT>::Type;
137 if(this->
mMap.end() == it)
140 return static_cast<Data*
>(it->second.get());
143 template <
class AspectT>
144 const typename GetData<AspectT>::Type*
get()
const
149 template <
class AspectT,
typename... Args>
152 using Data =
typename GetData<AspectT>::Type;
155 auto& it = this->
mMap.insert(
156 std::make_pair<std::type_index, std::unique_ptr<Data>>(
157 typeid(AspectType),
nullptr));
159 const bool exists = !it.second;
161 it.first = make_unique<Data>(std::forward<Args>(args)...);
163 return static_cast<Data&
>(*it.first);
166 template <
class AspectT>
169 return (get<AspectT>() !=
nullptr);
178 template <
class CompositeType,
template<
class>
class GetData,
typename... Aspects>
206 template <
class CompositeType,
template<
class>
class GetData,
class AspectT,
207 typename... Remainder>
208 struct ComposeData<CompositeType, GetData, AspectT, Remainder...> :
209 public GetData<AspectT>::Type,
210 public ComposeData<CompositeType, GetData, Remainder...>
217 using Base =
typename GetData<AspectT>::Type;
218 using Data =
typename Base::Data;
221 template <
typename Arg>
224 using Type =
typename std::conditional<
225 std::is_base_of<typename Base::Data, Arg>::value,
226 typename Base::Data, Arg>
::type;
229 template <
typename Arg>
230 struct ConvertIfComposite
232 using Type =
typename std::conditional<
233 std::is_base_of<CompositeType, Arg>::value,
234 CompositeType, Arg>
::type;
238 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
246 template <typename Arg1, typename... Args>
250 static_cast<const typename ConvertIfData<Arg1>::Type&>(arg1),
258 :
ComposeData<CompositeType, GetData, Remainder...>(composite)
260 _setBaseFrom(composite);
263 template <
typename... Aspects>
265 :
ComposeData(static_cast<const CompositeType&>(composite))
276 :
ComposeData(static_cast<const CompositeType&>(composite))
281 operator CompositeType()
const
283 CompositeType composite;
291 _setBaseFrom(composite);
305 template <
typename... Args>
313 template <
typename... Args>
315 :
ComposeData<CompositeType, GetData, Remainder...>(args...)
320 template <
typename... Args>
323 ComposeData<CompositeType, GetData, Remainder...>(args...)
330 const Base* data = composite.template get<AspectType>();
332 static_cast<Base&
>(*this) = *data;
337 composite.template create<AspectType>(
static_cast<const Base&
>(*
this));
346 template <
typename Arg1,
typename... Args>
353 template <
typename Arg>
361 static_cast<Base&
>(*this) = data;
366 _setBaseFrom(composite);
371 template <
typename... Aspects>
374 template <
typename... Data>
#define DART_DEFINE_ALIGNED_SHARED_OBJECT_CREATOR(class_name)
Definition: Memory.hpp:148
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:224
MapType mMap
A map containing the collection of States for the Aspect.
Definition: Cloneable.hpp:285
Definition: CompositeData.hpp:180
ComposeData(const CompositeType &)
Definition: CompositeData.hpp:185
void _addData(CompositeType &) const
Definition: CompositeData.hpp:199
virtual ~ComposeData()=default
void setFrom(const CompositeType &)
Definition: CompositeData.hpp:192
Definition: CompositeData.hpp:104
bool has() const
Definition: CompositeData.hpp:167
virtual ~CompositeData()=default
GetData< AspectT >::Type & getOrCreate(Args &&... args)
Definition: CompositeData.hpp:150
GetData< AspectT >::Type & create(Args &&... args)
Create (or replace) a piece of data in this.
Definition: CompositeData.hpp:119
GetData< AspectT >::Type * get()
Definition: CompositeData.hpp:131
CompositeData(Args &&... args)
Forwarding constructor.
Definition: CompositeData.hpp:109
const GetData< AspectT >::Type * get() const
Definition: CompositeData.hpp:144
CompositeData< CompositeStateMap, GetState > CompositeState
Definition: CompositeData.hpp:174
std::map< std::type_index, std::unique_ptr< Aspect::Properties > > CompositePropertiesMap
Definition: CompositeData.hpp:99
std::map< std::type_index, std::unique_ptr< Aspect::State > > CompositeStateMap
Definition: CompositeData.hpp:98
CompositeData< CompositePropertiesMap, GetProperties > CompositeProperties
Definition: CompositeData.hpp:175
std::multimap< dart::dynamics::Shape *, SimpleFrameShapeDnD * >::iterator iterator
Definition: Viewer.cpp:622
Definition: BulletCollisionDetector.cpp:63
Definition: SharedLibraryManager.hpp:43
typename std::conditional< std::is_base_of< CompositeType, Arg >::value, CompositeType, Arg >::type Type
Definition: CompositeData.hpp:234
typename std::conditional< std::is_base_of< typename Base::Data, Arg >::value, typename Base::Data, Arg >::type Type
Definition: CompositeData.hpp:226
Definition: CompositeData.hpp:211
void _addData(CompositeType &composite) const
Definition: CompositeData.hpp:335
typename GetData< AspectT >::Type Base
Definition: CompositeData.hpp:217
void _setBaseFrom(const CompositeType &composite)
Definition: CompositeData.hpp:328
ComposeData(DelegateTag, const Args &... args)
Definition: CompositeData.hpp:314
void copy(const Args &... args)
Grab any relevant data and copy it into this composite.
Definition: CompositeData.hpp:306
void _attemptToUse(const Arg &)
Definition: CompositeData.hpp:354
void _attemptToUse(const CompositeType &composite)
Definition: CompositeData.hpp:364
void _findData(const Arg1 &arg1, const Args &... args)
Definition: CompositeData.hpp:347
void setFrom(const CompositeType &composite)
Definition: CompositeData.hpp:289
ComposeData(DelegateTag, const Data &arg1, const Args &... args)
Definition: CompositeData.hpp:321
DelegateTag
Definition: CompositeData.hpp:214
void _attemptToUse(const typename Base::Data &data)
Definition: CompositeData.hpp:359
ComposeData(const ComposeData< CompositeType, GetData, Aspects... > &composite)
Definition: CompositeData.hpp:264
void _findData()
Definition: CompositeData.hpp:341
ComposeData(CompositeType &&composite)
Definition: CompositeData.hpp:275
typename GetAspect< AspectT >::Type AspectType
Definition: CompositeData.hpp:219
typename Base::Data Data
Definition: CompositeData.hpp:218
ComposeData(const CompositeType &composite)
Grab relevant data out of a composite object.
Definition: CompositeData.hpp:257
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:80
Definition: CompositeData.hpp:93
typename GetAspect< AspectT >::Type::Properties Type
Definition: CompositeData.hpp:94
Definition: CompositeData.hpp:86
typename GetAspect< AspectT >::Type::State Type
Definition: CompositeData.hpp:87