26#ifndef TESSERACT_COMMON_TYPE_ERASURE_H
27#define TESSERACT_COMMON_TYPE_ERASURE_H
31#include <boost/serialization/base_object.hpp>
32#include <boost/serialization/nvp.hpp>
33#include <boost/serialization/unique_ptr.hpp>
47 virtual std::type_index
getType()
const = 0;
56 virtual std::unique_ptr<TypeErasureInterface>
clone()
const = 0;
61 template <
class Archive>
65template <
typename ConcreteType,
typename ConceptInterface>
97 template <
class Archive>
101 ar& boost::serialization::make_nvp(
"base", boost::serialization::base_object<ConceptInterface>(*
this));
102 ar& boost::serialization::make_nvp(
"impl",
value_);
116 std::unique_ptr<TypeErasureInterface>
clone() const final
118 return std::make_unique<TypeErasureInstanceWrapper<F>>(this->get());
124 template <
class Archive>
128 ar& boost::serialization::make_nvp(
"base", boost::serialization::base_object<F>(*
this));
132template <
typename ConceptInterface,
template <
typename>
class ConceptInstance>
136 template <
typename T>
137 using uncvref_t = std::remove_cv_t<typename std::remove_reference<T>::type>;
141 template <
typename T>
147 template <
typename T,
generic_ctor_enabler<T> = 0>
167 value_.swap(other.value_);
178 template <
typename T,
generic_ctor_enabler<T> = 0>
188 return std::type_index{
typeid(
nullptr) };
212 template <
typename T>
216 throw std::runtime_error(
"TypeErasureBase, tried to cast '" + std::string(
getType().
name()) +
"' to '" +
217 std::string(
typeid(
T).
name()) +
"'!");
223 template <
typename T>
227 throw std::runtime_error(
"TypeErasureBase, tried to cast '" + std::string(
getType().
name()) +
"' to '" +
228 std::string(
typeid(
T).
name()) +
"'!");
238 template <
class Archive>
241 ar& boost::serialization::make_nvp(
"value",
value_);
244 std::unique_ptr<TypeErasureInterface>
value_{
nullptr };
Definition: polygon_mesh.h:46
auto clone
Definition: clone_cache_unit.cpp:126
Definition: allowed_collision_matrix.h:16
Definition: serialization.h:90
Definition: type_erasure.h:134
TypeErasureBase(TypeErasureBase &&other) noexcept
Definition: type_erasure.h:162
TypeErasureBase(T &&value)
Definition: type_erasure.h:148
bool isNull() const
Definition: type_erasure.h:193
TypeErasureBase & operator=(T &&other)
Definition: type_erasure.h:179
TypeErasureBase & operator=(TypeErasureBase &&other) noexcept
Definition: type_erasure.h:165
~TypeErasureBase()=default
std::enable_if_t<!std::is_base_of< TypeErasureBase, uncvref_t< T > >::value, int > generic_ctor_enabler
Definition: type_erasure.h:142
TypeErasureBase()
Definition: type_erasure.h:153
std::unique_ptr< TypeErasureInterface > value_
Definition: type_erasure.h:244
TypeErasureBase(const TypeErasureBase &other)
Definition: type_erasure.h:159
bool operator==(const TypeErasureBase &rhs) const
Definition: type_erasure.h:195
ConceptInterfaceType & getInterface()
Definition: type_erasure.h:208
const T & as() const
Definition: type_erasure.h:224
bool operator!=(const TypeErasureBase &rhs) const
Definition: type_erasure.h:206
std::type_index getType() const
Definition: type_erasure.h:185
const ConceptInterfaceType & getInterface() const
Definition: type_erasure.h:210
void serialize(Archive &ar, const unsigned int)
Definition: type_erasure.h:239
friend class boost::serialization::access
Definition: type_erasure.h:235
std::remove_cv_t< typename std::remove_reference< T >::type > uncvref_t
Definition: type_erasure.h:137
TypeErasureBase & operator=(const TypeErasureBase &other)
Definition: type_erasure.h:172
ConceptInterface ConceptInterfaceType
Definition: type_erasure.h:145
T & as()
Definition: type_erasure.h:213
Definition: type_erasure.h:108
TypeErasureInstanceWrapper(const ConceptValueType &x)
Definition: type_erasure.h:113
void serialize(Archive &ar, const unsigned int)
Definition: type_erasure.h:125
typename F::ConceptInterfaceType ConceptInterfaceType
Definition: type_erasure.h:110
std::unique_ptr< TypeErasureInterface > clone() const final
Definition: type_erasure.h:116
TypeErasureInstanceWrapper(TypeErasureInstanceWrapper &&x) noexcept
Definition: type_erasure.h:114
TypeErasureInstanceWrapper()=default
friend class boost::serialization::access
Definition: type_erasure.h:122
typename F::ConceptValueType ConceptValueType
Definition: type_erasure.h:109
Definition: type_erasure.h:67
const void * recover() const final
Definition: type_erasure.h:83
ConceptValueType & get()
Definition: type_erasure.h:79
void * recover() final
Definition: type_erasure.h:81
TypeErasureInstance(ConcreteType value)
Definition: type_erasure.h:73
ConcreteType ConceptValueType
Definition: type_erasure.h:68
ConcreteType value_
Definition: type_erasure.h:92
std::type_index getType() const final
Definition: type_erasure.h:85
TypeErasureInstance(ConcreteType &&value)
Definition: type_erasure.h:75
TypeErasureInstance()=default
void serialize(Archive &ar, const unsigned int)
Definition: type_erasure.h:98
bool equals(const TypeErasureInterface &other) const final
Definition: type_erasure.h:87
friend class boost::serialization::access
Definition: type_erasure.h:95
ConceptInterface ConceptInterfaceType
Definition: type_erasure.h:69
const ConceptValueType & get() const
Definition: type_erasure.h:77
This is the interface that all type erasures interfaces must inherit from.
Definition: type_erasure.h:40
virtual std::type_index getType() const =0
virtual std::unique_ptr< TypeErasureInterface > clone() const =0
virtual bool equals(const TypeErasureInterface &other) const =0
virtual ~TypeErasureInterface()=default
void serialize(Archive &, const unsigned int)
Definition: type_erasure.h:62
friend class boost::serialization::access
Definition: type_erasure.h:59
virtual const void * recover() const =0
virtual void * recover()=0
Additional Boost serialization wrappers.
object value
Definition: tesseract_common_serialization_unit.cpp:495
m name
Definition: tesseract_scene_graph_link_unit.cpp:77