33#ifndef DART_COMMON_DETAIL_CLONEABLE_HPP_
34#define DART_COMMON_DETAIL_CLONEABLE_HPP_
43template <
class Base,
class Mixin>
50template <
class Base,
class Mixin>
51template <
typename ... Args>
53 : Mixin(
std::forward<Args>(args)...)
59template <
class Base,
class Mixin>
67template <
class Base,
class Mixin>
69 : Mixin(
std::move(mixin))
75template <
class Base,
class Mixin>
84template <
class Base,
class Mixin>
92template <
class Base,
class Mixin>
96 static_cast<Mixin&
>(*this) = mixin;
101template <
class Base,
class Mixin>
104 static_cast<Mixin&
>(*this) = std::move(mixin);
109template <
class Base,
class Mixin>
113 static_cast<Mixin&
>(*this) =
static_cast<const Mixin&
>(other);
118template <
class Base,
class Mixin>
122 static_cast<Mixin&
>(*this) = std::move(
static_cast<Mixin&&
>(other));
126template <
class Base,
class Mixin>
129 return common::make_unique<MakeCloneable<Base, Mixin>>(*this);
133template <
class Base,
class Mixin>
140template <
class Base,
class OwnerT,
class DataT,
141 void (*setData)(OwnerT*,
const DataT&),
142 DataT (*getData)(
const OwnerT*)>
145 mData(make_unique<Data>())
151template <
class Base,
class OwnerT,
class DataT,
152 void (*setData)(OwnerT*,
const DataT&),
153 DataT (*getData)(
const OwnerT*)>
162template <
class Base,
class OwnerT,
class DataT,
163 void (*setData)(OwnerT*,
const DataT&),
164 DataT (*getData)(
const OwnerT*)>
165template <typename... Args>
167 OwnerT* owner, Args&&... args)
170 set(
Data(std::forward<Args>(args)...));
174template <
class Base,
class OwnerT,
class DataT,
175 void (*setData)(OwnerT*,
const DataT&),
176 DataT (*getData)(
const OwnerT*)>
177template <typename... Args>
181 mData(dart::common::make_unique<Data>(std::forward<Args>(args)...))
187template <
class Base,
class OwnerT,
class DataT,
188 void (*setData)(OwnerT*,
const DataT&),
189 DataT (*getData)(
const OwnerT*)>
199template <
class Base,
class OwnerT,
class DataT,
200 void (*setData)(OwnerT*,
const DataT&),
201 DataT (*getData)(
const OwnerT*)>
210template <
class Base,
class OwnerT,
class DataT,
211 void (*setData)(OwnerT*,
const DataT&),
212 DataT (*getData)(
const OwnerT*)>
221template <
class Base,
class OwnerT,
class DataT,
222 void (*setData)(OwnerT*,
const DataT&),
223 DataT (*getData)(
const OwnerT*)>
232template <
class Base,
class OwnerT,
class DataT,
233 void (*setData)(OwnerT*,
const DataT&),
234 DataT (*getData)(
const OwnerT*)>
243template <
class Base,
class OwnerT,
class DataT,
244 void (*setData)(OwnerT*,
const DataT&),
245 DataT (*getData)(
const OwnerT*)>
254template <
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);
270template <
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));
286template <
class Base,
class OwnerT,
class DataT,
287 void (*setData)(OwnerT*,
const DataT&),
288 DataT (*getData)(
const OwnerT*)>
296template <
class Base,
class OwnerT,
class DataT,
297 void (*setData)(OwnerT*,
const DataT&),
298 DataT (*getData)(
const OwnerT*)>
306template <
class Base,
class OwnerT,
class DataT,
307 void (*setData)(OwnerT*,
const DataT&),
308 DataT (*getData)(
const OwnerT*)>
312 return (*getData)(mOwner);
318template <
class Base,
class OwnerT,
class DataT,
319 void (*setData)(OwnerT*,
const DataT&),
320 DataT (*getData)(
const OwnerT*)>
327template <
class Base,
class OwnerT,
class DataT,
328 void (*setData)(OwnerT*,
const DataT&),
329 DataT (*getData)(
const OwnerT*)>
336template <
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());
346template <
class Base,
class OwnerT,
class DataT,
347 void (*setData)(OwnerT*,
const DataT&),
348 DataT (*getData)(
const OwnerT*)>
356template <
typename MapType>
364template <
typename MapType>
368 *
this = std::move(otherHolder);
372template <
typename MapType>
379template <
typename MapType>
382 *
this = std::move(otherMap);
386template <
typename MapType>
395template <
typename MapType>
399 mMap = std::move(otherHolder.mMap);
405template <
typename MapType>
407 const MapType& otherMap)
414template <
typename MapType>
416 MapType&& otherHolder)
418 mMap = std::move(otherHolder);
424template <
typename MapType>
427 copy(otherMap.
getMap(), merge);
431template <
typename MapType>
434 typename MapType::iterator receiver = mMap.begin();
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++);
500template <
typename MapType>
503 copy(otherMap,
true);
507template <
typename MapType>
510 copy(otherMap,
true);
514template <
typename MapType>
521template <
typename MapType>
530 : mVector(regularVector)
539 mVector = std::move(regularVector);
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) );
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;
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
Definition BulletCollisionDetector.cpp:63
Definition SharedLibraryManager.hpp:43