33 #ifndef DART_COMMON_DETAIL_CLONEABLE_HPP_
34 #define DART_COMMON_DETAIL_CLONEABLE_HPP_
43 template <
class Base,
class Mixin>
50 template <
class Base,
class Mixin>
51 template <
typename ... Args>
53 : Mixin(
std::forward<Args>(args)...)
59 template <
class Base,
class Mixin>
67 template <
class Base,
class Mixin>
69 : Mixin(
std::move(mixin))
75 template <
class Base,
class Mixin>
84 template <
class Base,
class Mixin>
92 template <
class Base,
class Mixin>
96 static_cast<Mixin&
>(*this) = mixin;
101 template <
class Base,
class Mixin>
104 static_cast<Mixin&
>(*this) = std::move(mixin);
109 template <
class Base,
class Mixin>
113 static_cast<Mixin&
>(*this) =
static_cast<const Mixin&
>(other);
118 template <
class Base,
class Mixin>
122 static_cast<Mixin&
>(*this) = std::move(
static_cast<Mixin&&
>(other));
126 template <
class Base,
class Mixin>
129 return common::make_unique<MakeCloneable<Base, Mixin>>(*this);
133 template <
class Base,
class Mixin>
140 template <
class Base,
class OwnerT,
class DataT,
141 void (*setData)(OwnerT*,
const DataT&),
142 DataT (*getData)(
const OwnerT*)>
145 mData(make_unique<Data>())
151 template <
class Base,
class OwnerT,
class DataT,
152 void (*setData)(OwnerT*,
const DataT&),
153 DataT (*getData)(
const OwnerT*)>
162 template <
class Base,
class OwnerT,
class DataT,
163 void (*setData)(OwnerT*,
const DataT&),
164 DataT (*getData)(
const OwnerT*)>
165 template <typename... Args>
167 OwnerT* owner, Args&&... args)
170 set(
Data(std::forward<Args>(args)...));
174 template <
class Base,
class OwnerT,
class DataT,
175 void (*setData)(OwnerT*,
const DataT&),
176 DataT (*getData)(
const OwnerT*)>
177 template <typename... Args>
181 mData(dart::common::make_unique<Data>(std::forward<Args>(args)...))
187 template <
class Base,
class OwnerT,
class DataT,
188 void (*setData)(OwnerT*,
const DataT&),
189 DataT (*getData)(
const OwnerT*)>
199 template <
class Base,
class OwnerT,
class DataT,
200 void (*setData)(OwnerT*,
const DataT&),
201 DataT (*getData)(
const OwnerT*)>
210 template <
class Base,
class OwnerT,
class DataT,
211 void (*setData)(OwnerT*,
const DataT&),
212 DataT (*getData)(
const OwnerT*)>
221 template <
class Base,
class OwnerT,
class DataT,
222 void (*setData)(OwnerT*,
const DataT&),
223 DataT (*getData)(
const OwnerT*)>
232 template <
class Base,
class OwnerT,
class DataT,
233 void (*setData)(OwnerT*,
const DataT&),
234 DataT (*getData)(
const OwnerT*)>
243 template <
class Base,
class OwnerT,
class DataT,
244 void (*setData)(OwnerT*,
const DataT&),
245 DataT (*getData)(
const OwnerT*)>
254 template <
class Base,
class OwnerT,
class DataT,
255 void (*setData)(OwnerT*,
const DataT&),
256 DataT (*getData)(
const OwnerT*)>
262 (*setData)(mOwner, data);
266 mData = make_unique<Data>(data);
270 template <
class Base,
class OwnerT,
class DataT,
271 void (*setData)(OwnerT*,
const DataT&),
272 DataT (*getData)(
const OwnerT*)>
278 (*setData)(mOwner, data);
282 mData = dart::common::make_unique<Data>(std::move(data));
286 template <
class Base,
class OwnerT,
class DataT,
287 void (*setData)(OwnerT*,
const DataT&),
288 DataT (*getData)(
const OwnerT*)>
296 template <
class Base,
class OwnerT,
class DataT,
297 void (*setData)(OwnerT*,
const DataT&),
298 DataT (*getData)(
const OwnerT*)>
306 template <
class Base,
class OwnerT,
class DataT,
307 void (*setData)(OwnerT*,
const DataT&),
308 DataT (*getData)(
const OwnerT*)>
312 return (*getData)(mOwner);
318 template <
class Base,
class OwnerT,
class DataT,
319 void (*setData)(OwnerT*,
const DataT&),
320 DataT (*getData)(
const OwnerT*)>
327 template <
class Base,
class OwnerT,
class DataT,
328 void (*setData)(OwnerT*,
const DataT&),
329 DataT (*getData)(
const OwnerT*)>
336 template <
class Base,
class OwnerT,
class DataT,
337 void (*setData)(OwnerT*,
const DataT&),
338 DataT (*getData)(
const OwnerT*)>
340 Base, OwnerT, DataT, setData, getData>::clone()
const
342 return dart::common::make_unique<ProxyCloneable>(get());
346 template <
class Base,
class OwnerT,
class DataT,
347 void (*setData)(OwnerT*,
const DataT&),
348 DataT (*getData)(
const OwnerT*)>
356 template <
typename MapType>
364 template <
typename MapType>
368 *
this = std::move(otherHolder);
372 template <
typename MapType>
379 template <
typename MapType>
382 *
this = std::move(otherMap);
386 template <
typename MapType>
395 template <
typename MapType>
399 mMap = std::move(otherHolder.mMap);
405 template <
typename MapType>
407 const MapType& otherMap)
414 template <
typename MapType>
416 MapType&& otherHolder)
418 mMap = std::move(otherHolder);
424 template <
typename MapType>
427 copy(otherMap.
getMap(), merge);
431 template <
typename MapType>
435 typename MapType::const_iterator sender = otherMap.begin();
437 while( otherMap.end() != sender )
439 if( mMap.end() == receiver )
443 mMap[sender->first] = sender->second->clone();
446 else if( receiver->first == sender->first )
454 receiver->second->copy(*sender->second);
456 receiver->second = sender->second->clone();
461 receiver->second =
nullptr;
467 else if( receiver->first < sender->first )
473 receiver->second =
nullptr;
484 mMap[sender->first] = sender->second->clone();
492 while( mMap.end() != receiver )
494 mMap.erase(receiver++);
500 template <
typename MapType>
503 copy(otherMap,
true);
507 template <
typename MapType>
510 copy(otherMap,
true);
514 template <
typename MapType>
521 template <
typename MapType>
528 template <
typename T>
530 : mVector(regularVector)
536 template <
typename T>
539 mVector = std::move(regularVector);
543 template <
typename T>
550 template <
typename T>
558 template <
typename T>
561 std::vector<T> clonedVector;
562 clonedVector.reserve(mVector.size());
564 for(
const T& entry : mVector)
565 clonedVector.push_back(entry->clone());
567 return common::make_unique< CloneableVector<T> >( std::move(clonedVector) );
571 template <
typename T>
574 const std::vector<T>& other = anotherVector.
getVector();
575 mVector.resize(other.size());
577 for(std::size_t i=0; i < other.size(); ++i)
579 if(mVector[i] && other[i])
580 mVector[i]->copy(*other[i]);
582 mVector[i] = other[i]->clone();
584 mVector[i] =
nullptr;
589 template <
typename T>
596 template <
typename T>
MapHolder is a templated wrapper class that is used to allow maps of Aspect::State and Aspect::Proper...
Definition: Cloneable.hpp:224
CloneableMap()=default
Default constructor.
void merge(const CloneableMap &otherMap)
Merge the contents of another cloneable map into this one.
Definition: Cloneable.hpp:501
MapType & getMap()
Get the map that is being held.
Definition: Cloneable.hpp:515
void copy(const CloneableMap &otherMap, bool merge=false)
Copy the contents of another cloneable map into this one.
Definition: Cloneable.hpp:425
CloneableMap & operator=(const CloneableMap &otherStates)
Assignment operator.
Definition: Cloneable.hpp:387
The CloneableVector type wraps a std::vector of an Cloneable type allowing it to be handled by an Clo...
Definition: Cloneable.hpp:293
CloneableVector & operator=(const CloneableVector &other)
Call copy(other) on this vector.
Definition: Cloneable.hpp:551
void copy(const CloneableVector< T > &anotherVector)
Copy the contents of another cloneable vector into this one.
Definition: Cloneable.hpp:572
std::unique_ptr< CloneableVector< T > > clone() const
Create a copy of this CloneableVector's contents.
Definition: Cloneable.hpp:559
std::vector< T > & getVector()
Get a reference to the std::vector that this class is wrapping.
Definition: Cloneable.hpp:590
CloneableVector()=default
Default constructor.
The MakeCloneable class is used to easily create an Cloneable (such as Node::State) which simply take...
Definition: Cloneable.hpp:85
void copy(const Base &other) override final
Definition: Cloneable.hpp:134
std::unique_ptr< Base > clone() const override final
Definition: Cloneable.hpp:127
MakeCloneable()
Default constructor. Uses the default constructor of Mixin.
Definition: Cloneable.hpp:44
MakeCloneable & operator=(const Mixin &mixin)
Copy assignment operator that uses a Mixin instance.
Definition: Cloneable.hpp:93
Definition: Cloneable.hpp:140
Data get() const
Get the Data of this ProxyCloneable.
Definition: Cloneable.hpp:309
DataT Data
Definition: Cloneable.hpp:143
std::multimap< dart::dynamics::Shape *, SimpleFrameShapeDnD * >::iterator iterator
Definition: Viewer.cpp:622
Definition: BulletCollisionDetector.cpp:63
Definition: SharedLibraryManager.hpp:43