any_poly.cpp
Go to the documentation of this file.
1 
29 #include <boost/serialization/nvp.hpp>
30 #include <boost/serialization/unique_ptr.hpp>
31 #if (BOOST_VERSION >= 107400) && (BOOST_VERSION < 107500)
32 #include <boost/serialization/library_version_type.hpp>
33 #endif
34 #include <boost/serialization/unordered_map.hpp>
36 
38 
39 namespace tesseract_common
40 {
41 std::type_index AnyInterface::getType() const { return typeid(*this); }
42 
43 // Operators
44 bool AnyInterface::operator==(const AnyInterface& rhs) const { return equals(rhs); }
45 
46 // LCOV_EXCL_START
47 bool AnyInterface::operator!=(const AnyInterface& rhs) const { return !operator==(rhs); }
48 // LCOV_EXCL_STOP
49 
50 template <class Archive>
51 void AnyInterface::serialize(Archive& /*ar*/, const unsigned int /*version*/)
52 {
53 }
54 
56 {
57  if (other.impl_)
58  impl_ = other.impl_->clone(); // Deep copy
59 }
60 
62 {
63  if (this != &other)
64  impl_ = other.impl_ ? other.impl_->clone() : nullptr;
65 
66  return *this;
67 }
68 
69 AnyPoly::AnyPoly(const AnyInterface& impl) : impl_(impl.clone()) {}
70 
71 std::type_index AnyPoly::getType() const
72 {
73  if (impl_ == nullptr)
74  return typeid(nullptr);
75 
76  return impl_->getType();
77 }
78 
79 bool AnyPoly::isNull() const { return (impl_ == nullptr); }
81 const AnyInterface& AnyPoly::get() const { return *impl_; }
82 
83 bool AnyPoly::operator==(const AnyPoly& rhs) const
84 {
85  if (impl_ == nullptr && rhs.impl_ == nullptr)
86  return true;
87 
88  if (impl_ == nullptr || rhs.impl_ == nullptr)
89  return false;
90 
91  if (getType() != rhs.getType())
92  return false;
93 
94  return (*impl_ == *rhs.impl_);
95 }
96 // LCOV_EXCL_START
97 bool AnyPoly::operator!=(const AnyPoly& rhs) const { return !operator==(rhs); }
98 // LCOV_EXCL_STOP
99 
100 template <class Archive>
101 void AnyPoly::serialize(Archive& ar, const unsigned int /*version*/)
102 {
103  ar& boost::serialization::make_nvp("impl", impl_);
104 }
105 } // namespace tesseract_common
106 
110 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::AnyPoly)
111 
113 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::BoolAnyPoly)
114 
116 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::IntAnyPoly)
117 
119 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::UnsignedAnyPoly)
120 
122 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::DoubleAnyPoly)
123 
125 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::FloatAnyPoly)
126 
128 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::StringAnyPoly)
129 
131 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::SizeTAnyPoly)
132 
134 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::UMapStringStringAnyPoly)
135 
137 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::UMapStringBoolAnyPoly)
138 
140 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::UMapStringIntAnyPoly)
141 
143 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::UMapStringUnsignedAnyPoly)
144 
146 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::UMapStringDoubleAnyPoly)
147 
149 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::UMapStringFloatAnyPoly)
150 
152 BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_common::UMapStringSizeTAnyPoly)
tesseract_common::AnyInterface::getType
virtual std::type_index getType() const
Get the type index of the object stored.
Definition: any_poly.cpp:41
tesseract_common::AnyPoly::get
AnyInterface & get()
Get the instruction being stored.
Definition: any_poly.cpp:80
tesseract_common
Definition: allowed_collision_matrix.h:19
any_poly.h
tesseract_common::AnyInterface::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: any_poly.cpp:51
tesseract_common::AnyPoly::operator!=
bool operator!=(const AnyPoly &rhs) const
Definition: any_poly.cpp:97
TESSERACT_SERIALIZE_ARCHIVES_INSTANTIATE
#define TESSERACT_SERIALIZE_ARCHIVES_INSTANTIATE(Type)
Definition: serialization.h:49
macros.h
Common Tesseract Macros.
tesseract_common::AnyPoly::operator==
bool operator==(const AnyPoly &rhs) const
Definition: any_poly.cpp:83
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#define TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
Definition: macros.h:71
tesseract_common::AnyWrapper
Definition: any_poly.h:80
tesseract_common::AnyPoly::serialize
void serialize(Archive &ar, const unsigned int version)
Definition: any_poly.cpp:101
tesseract_common::AnyPoly
Definition: any_poly.h:113
tesseract_common::AnyInterface
Definition: any_poly.h:43
tesseract_common::AnyPoly::getType
std::type_index getType() const
Get the stored derived type.
Definition: any_poly.cpp:71
tesseract_common::AnyInterface::equals
virtual bool equals(const AnyInterface &other) const =0
Check if two objects are equal.
tesseract_common::AnyPoly::impl_
std::unique_ptr< AnyInterface > impl_
Definition: any_poly.h:229
tesseract_common::AnyPoly::operator=
AnyPoly & operator=(const AnyPoly &other)
Definition: any_poly.cpp:61
tesseract_common::AnyInterface::operator!=
bool operator!=(const AnyInterface &rhs) const
Definition: any_poly.cpp:47
TESSERACT_COMMON_IGNORE_WARNINGS_POP
#define TESSERACT_COMMON_IGNORE_WARNINGS_POP
Definition: macros.h:72
serialization.h
Additional Boost serialization wrappers.
tesseract_common::AnyPoly::AnyPoly
AnyPoly()=default
tesseract_common::AnyInterface::operator==
bool operator==(const AnyInterface &rhs) const
Definition: any_poly.cpp:44
tesseract_common::AnyPoly::isNull
bool isNull() const
Check if the poly type is null.
Definition: any_poly.cpp:79


tesseract_common
Author(s): Levi Armstrong
autogenerated on Sun May 18 2025 03:01:40