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>
66 template <
class Base,
class Mixin>
68 : Mixin(
std::move(mixin))
74 template <
class Base,
class Mixin>
83 template <
class Base,
class Mixin>
91 template <
class Base,
class Mixin>
95 static_cast<Mixin&
>(*this) = mixin;
100 template <
class Base,
class Mixin>
103 static_cast<Mixin&
>(*this) = std::move(mixin);
108 template <
class Base,
class Mixin>
112 static_cast<Mixin&
>(*this) =
static_cast<const Mixin&
>(other);
117 template <
class Base,
class Mixin>
121 static_cast<Mixin&
>(*this) = std::move(
static_cast<Mixin&&
>(other));
125 template <
class Base,
class Mixin>
128 return std::make_unique<MakeCloneable<Base, Mixin>>(*this);
132 template <
class Base,
class Mixin>
143 void (*setData)(OwnerT*,
const DataT&),
144 DataT (*getData)(
const OwnerT*)>
146 : mOwner(
nullptr), mData(std::make_unique<Data>())
156 void (*setData)(OwnerT*,
const DataT&),
157 DataT (*getData)(
const OwnerT*)>
170 void (*setData)(OwnerT*,
const DataT&),
171 DataT (*getData)(
const OwnerT*)>
172 template <typename... Args>
174 OwnerT* owner, Args&&... args)
177 set(
Data(std::forward<Args>(args)...));
185 void (*setData)(OwnerT*,
const DataT&),
186 DataT (*getData)(
const OwnerT*)>
187 template <typename... Args>
190 : mOwner(
nullptr), mData(std::make_unique<Data>(std::forward<Args>(args)...))
200 void (*setData)(OwnerT*,
const DataT&),
201 DataT (*getData)(
const OwnerT*)>
204 : mOwner(
nullptr), mData(
nullptr)
214 void (*setData)(OwnerT*,
const DataT&),
215 DataT (*getData)(
const OwnerT*)>
228 void (*setData)(OwnerT*,
const DataT&),
229 DataT (*getData)(
const OwnerT*)>
242 void (*setData)(OwnerT*,
const DataT&),
243 DataT (*getData)(
const OwnerT*)>
256 void (*setData)(OwnerT*,
const DataT&),
257 DataT (*getData)(
const OwnerT*)>
271 void (*setData)(OwnerT*,
const DataT&),
272 DataT (*getData)(
const OwnerT*)>
286 void (*setData)(OwnerT*,
const DataT&),
287 DataT (*getData)(
const OwnerT*)>
293 (*setData)(mOwner, data);
297 mData = std::make_unique<Data>(data);
305 void (*setData)(OwnerT*,
const DataT&),
306 DataT (*getData)(
const OwnerT*)>
311 (*setData)(mOwner, data);
315 mData = std::make_unique<Data>(std::move(data));
323 void (*setData)(OwnerT*,
const DataT&),
324 DataT (*getData)(
const OwnerT*)>
336 void (*setData)(OwnerT*,
const DataT&),
337 DataT (*getData)(
const OwnerT*)>
349 void (*setData)(OwnerT*,
const DataT&),
350 DataT (*getData)(
const OwnerT*)>
354 return (*getData)(mOwner);
364 void (*setData)(OwnerT*,
const DataT&),
365 DataT (*getData)(
const OwnerT*)>
376 void (*setData)(OwnerT*,
const DataT&),
377 DataT (*getData)(
const OwnerT*)>
389 void (*setData)(OwnerT*,
const DataT&),
390 DataT (*getData)(
const OwnerT*)>
391 std::unique_ptr<Base>
394 return std::make_unique<ProxyCloneable>(get());
402 void (*setData)(OwnerT*,
const DataT&),
403 DataT (*getData)(
const OwnerT*)>
411 template <
typename MapType>
418 template <
typename MapType>
421 *
this = std::move(otherHolder);
425 template <
typename MapType>
432 template <
typename MapType>
435 *
this = std::move(otherMap);
439 template <
typename MapType>
448 template <
typename MapType>
452 mMap = std::move(otherHolder.mMap);
458 template <
typename MapType>
466 template <
typename MapType>
469 mMap = std::move(otherHolder);
475 template <
typename MapType>
478 copy(otherMap.
getMap(), merge);
482 template <
typename MapType>
486 typename MapType::const_iterator sender = otherMap.begin();
488 while (otherMap.end() != sender)
490 if (mMap.end() == receiver)
494 mMap[sender->first] = sender->second->clone();
497 else if (receiver->first == sender->first)
502 if (receiver->second)
505 receiver->second->copy(*sender->second);
507 receiver->second = sender->second->clone();
512 receiver->second =
nullptr;
518 else if (receiver->first < sender->first)
524 receiver->second =
nullptr;
535 mMap[sender->first] = sender->second->clone();
543 while (mMap.end() != receiver)
545 mMap.erase(receiver++);
551 template <
typename MapType>
554 copy(otherMap,
true);
558 template <
typename MapType>
561 copy(otherMap,
true);
565 template <
typename MapType>
572 template <
typename MapType>
579 template <
typename T>
581 : mVector(regularVector)
587 template <
typename T>
590 mVector = std::move(regularVector);
594 template <
typename T>
601 template <
typename T>
609 template <
typename T>
612 std::vector<T> clonedVector;
613 clonedVector.reserve(mVector.size());
615 for (
const T& entry : mVector)
616 clonedVector.push_back(entry->clone());
618 return std::make_unique<CloneableVector<T>>(std::move(clonedVector));
622 template <
typename T>
625 const std::vector<T>& other = anotherVector.
getVector();
626 mVector.resize(other.size());
628 for (std::size_t i = 0; i < other.size(); ++i)
630 if (mVector[i] && other[i])
631 mVector[i]->copy(*other[i]);
633 mVector[i] = other[i]->clone();
635 mVector[i] =
nullptr;
640 template <
typename T>
647 template <
typename T>
MapHolder is a templated wrapper class that is used to allow maps of Aspect::State and Aspect::Proper...
Definition: Cloneable.hpp:221
CloneableMap()=default
Default constructor.
void merge(const CloneableMap &otherMap)
Merge the contents of another cloneable map into this one.
Definition: Cloneable.hpp:552
MapType & getMap()
Get the map that is being held.
Definition: Cloneable.hpp:566
void copy(const CloneableMap &otherMap, bool merge=false)
Copy the contents of another cloneable map into this one.
Definition: Cloneable.hpp:476
CloneableMap & operator=(const CloneableMap &otherStates)
Assignment operator.
Definition: Cloneable.hpp:440
The CloneableVector type wraps a std::vector of an Cloneable type allowing it to be handled by an Clo...
Definition: Cloneable.hpp:288
CloneableVector & operator=(const CloneableVector &other)
Call copy(other) on this vector.
Definition: Cloneable.hpp:602
void copy(const CloneableVector< T > &anotherVector)
Copy the contents of another cloneable vector into this one.
Definition: Cloneable.hpp:623
std::unique_ptr< CloneableVector< T > > clone() const
Create a copy of this CloneableVector's contents.
Definition: Cloneable.hpp:610
std::vector< T > & getVector()
Get a reference to the std::vector that this class is wrapping.
Definition: Cloneable.hpp:641
CloneableVector()=default
Default constructor.
The MakeCloneable class is used to easily create an Cloneable (such as Node::State) which simply take...
Definition: Cloneable.hpp:84
void copy(const Base &other) override final
Definition: Cloneable.hpp:133
std::unique_ptr< Base > clone() const override final
Definition: Cloneable.hpp:126
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:92
Definition: Cloneable.hpp:140
Data get() const
Get the Data of this ProxyCloneable.
Definition: Cloneable.hpp:351
DataT Data
Definition: Cloneable.hpp:142
OwnerT * mOwner
The ProxyCloneable will not store any data in mData if it has an Owner.
Definition: Cloneable.hpp:208
std::multimap< dart::dynamics::Shape *, SimpleFrameShapeDnD * >::iterator iterator
Definition: Viewer.cpp:620
Definition: BulletCollisionDetector.cpp:65
Definition: SharedLibraryManager.hpp:46