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*)>
244 template <
class Base,
class OwnerT,
class DataT,
245 void (*setData)(OwnerT*,
const DataT&),
246 DataT (*getData)(
const OwnerT*)>
256 template <
class Base,
class OwnerT,
class DataT,
257 void (*setData)(OwnerT*,
const DataT&),
258 DataT (*getData)(
const OwnerT*)>
264 (*setData)(mOwner, data);
268 mData = make_unique<Data>(data);
272 template <
class Base,
class OwnerT,
class DataT,
273 void (*setData)(OwnerT*,
const DataT&),
274 DataT (*getData)(
const OwnerT*)>
280 (*setData)(mOwner, data);
284 mData = dart::common::make_unique<Data>(std::move(data));
288 template <
class Base,
class OwnerT,
class DataT,
289 void (*setData)(OwnerT*,
const DataT&),
290 DataT (*getData)(
const OwnerT*)>
298 template <
class Base,
class OwnerT,
class DataT,
299 void (*setData)(OwnerT*,
const DataT&),
300 DataT (*getData)(
const OwnerT*)>
308 template <
class Base,
class OwnerT,
class DataT,
309 void (*setData)(OwnerT*,
const DataT&),
310 DataT (*getData)(
const OwnerT*)>
314 return (*getData)(mOwner);
320 template <
class Base,
class OwnerT,
class DataT,
321 void (*setData)(OwnerT*,
const DataT&),
322 DataT (*getData)(
const OwnerT*)>
329 template <
class Base,
class OwnerT,
class DataT,
330 void (*setData)(OwnerT*,
const DataT&),
331 DataT (*getData)(
const OwnerT*)>
338 template <
class Base,
class OwnerT,
class DataT,
339 void (*setData)(OwnerT*,
const DataT&),
340 DataT (*getData)(
const OwnerT*)>
342 Base, OwnerT, DataT, setData, getData>::clone()
const
344 return dart::common::make_unique<ProxyCloneable>(get());
348 template <
class Base,
class OwnerT,
class DataT,
349 void (*setData)(OwnerT*,
const DataT&),
350 DataT (*getData)(
const OwnerT*)>
358 template <
typename MapType>
366 template <
typename MapType>
370 *
this = std::move(otherHolder);
374 template <
typename MapType>
381 template <
typename MapType>
384 *
this = std::move(otherMap);
388 template <
typename MapType>
397 template <
typename MapType>
401 mMap = std::move(otherHolder.mMap);
407 template <
typename MapType>
409 const MapType& otherMap)
416 template <
typename MapType>
418 MapType&& otherHolder)
420 mMap = std::move(otherHolder);
426 template <
typename MapType>
429 copy(otherMap.
getMap(), merge);
433 template <
typename MapType>
437 typename MapType::const_iterator sender = otherMap.begin();
439 while( otherMap.end() != sender )
441 if( mMap.end() == receiver )
445 mMap[sender->first] = sender->second->clone();
448 else if( receiver->first == sender->first )
456 receiver->second->copy(*sender->second);
458 receiver->second = sender->second->clone();
463 receiver->second =
nullptr;
469 else if( receiver->first < sender->first )
475 receiver->second =
nullptr;
486 mMap[sender->first] = sender->second->clone();
494 while( mMap.end() != receiver )
496 mMap.erase(receiver++);
502 template <
typename MapType>
505 copy(otherMap,
true);
509 template <
typename MapType>
512 copy(otherMap,
true);
516 template <
typename MapType>
523 template <
typename MapType>
530 template <
typename T>
532 : mVector(regularVector)
538 template <
typename T>
541 mVector = std::move(regularVector);
545 template <
typename T>
552 template <
typename T>
560 template <
typename T>
563 std::vector<T> clonedVector;
564 clonedVector.reserve(mVector.size());
566 for(
const T& entry : mVector)
567 clonedVector.push_back(entry->clone());
569 return common::make_unique< CloneableVector<T> >( std::move(clonedVector) );
573 template <
typename T>
576 const std::vector<T>& other = anotherVector.
getVector();
577 mVector.resize(other.size());
579 for(std::size_t i=0; i < other.size(); ++i)
581 if(mVector[i] && other[i])
582 mVector[i]->copy(*other[i]);
584 mVector[i] = other[i]->clone();
586 mVector[i] =
nullptr;
591 template <
typename T>
598 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:503
MapType & getMap()
Get the map that is being held.
Definition: Cloneable.hpp:517
void copy(const CloneableMap &otherMap, bool merge=false)
Copy the contents of another cloneable map into this one.
Definition: Cloneable.hpp:427
CloneableMap & operator=(const CloneableMap &otherStates)
Assignment operator.
Definition: Cloneable.hpp:389
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:553
void copy(const CloneableVector< T > &anotherVector)
Copy the contents of another cloneable vector into this one.
Definition: Cloneable.hpp:574
std::unique_ptr< CloneableVector< T > > clone() const
Create a copy of this CloneableVector's contents.
Definition: Cloneable.hpp:561
std::vector< T > & getVector()
Get a reference to the std::vector that this class is wrapping.
Definition: Cloneable.hpp:592
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:311
DataT Data
Definition: Cloneable.hpp:143
OwnerT * mOwner
The ProxyCloneable will not store any data in mData if it has an Owner.
Definition: Cloneable.hpp:210
std::multimap< dart::dynamics::Shape *, SimpleFrameShapeDnD * >::iterator iterator
Definition: Viewer.cpp:622
Definition: BulletCollisionDetector.cpp:63
Definition: SharedLibraryManager.hpp:43