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*)>
244template <
class Base,
class OwnerT,
class DataT,
245 void (*setData)(OwnerT*,
const DataT&),
246 DataT (*getData)(
const OwnerT*)>
256template <
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);
272template <
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));
288template <
class Base,
class OwnerT,
class DataT,
289 void (*setData)(OwnerT*,
const DataT&),
290 DataT (*getData)(
const OwnerT*)>
298template <
class Base,
class OwnerT,
class DataT,
299 void (*setData)(OwnerT*,
const DataT&),
300 DataT (*getData)(
const OwnerT*)>
308template <
class Base,
class OwnerT,
class DataT,
309 void (*setData)(OwnerT*,
const DataT&),
310 DataT (*getData)(
const OwnerT*)>
314 return (*getData)(mOwner);
320template <
class Base,
class OwnerT,
class DataT,
321 void (*setData)(OwnerT*,
const DataT&),
322 DataT (*getData)(
const OwnerT*)>
329template <
class Base,
class OwnerT,
class DataT,
330 void (*setData)(OwnerT*,
const DataT&),
331 DataT (*getData)(
const OwnerT*)>
338template <
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());
348template <
class Base,
class OwnerT,
class DataT,
349 void (*setData)(OwnerT*,
const DataT&),
350 DataT (*getData)(
const OwnerT*)>
358template <
typename MapType>
366template <
typename MapType>
370 *
this = std::move(otherHolder);
374template <
typename MapType>
381template <
typename MapType>
384 *
this = std::move(otherMap);
388template <
typename MapType>
397template <
typename MapType>
401 mMap = std::move(otherHolder.mMap);
407template <
typename MapType>
409 const MapType& otherMap)
416template <
typename MapType>
418 MapType&& otherHolder)
420 mMap = std::move(otherHolder);
426template <
typename MapType>
429 copy(otherMap.
getMap(), merge);
433template <
typename MapType>
436 typename MapType::iterator receiver = mMap.begin();
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++);
502template <
typename MapType>
505 copy(otherMap,
true);
509template <
typename MapType>
512 copy(otherMap,
true);
516template <
typename MapType>
523template <
typename MapType>
532 : mVector(regularVector)
541 mVector = std::move(regularVector);
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) );
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;
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
Definition BulletCollisionDetector.cpp:63
Definition SharedLibraryManager.hpp:43