From b2514505c0f395ca5c96ae77a7ac3764bb033550 Mon Sep 17 00:00:00 2001 From: Levi Armstrong Date: Mon, 24 Jan 2022 11:29:53 -0600 Subject: [PATCH] Add any.cpp --- tesseract_common/CMakeLists.txt | 1 + .../include/tesseract_common/any.h | 36 +++------ tesseract_common/src/any.cpp | 77 +++++++++++++++++++ 3 files changed, 88 insertions(+), 26 deletions(-) create mode 100644 tesseract_common/src/any.cpp diff --git a/tesseract_common/CMakeLists.txt b/tesseract_common/CMakeLists.txt index 53e9a1ac67f..b7fd20962e3 100644 --- a/tesseract_common/CMakeLists.txt +++ b/tesseract_common/CMakeLists.txt @@ -44,6 +44,7 @@ add_code_coverage_all_targets(EXCLUDE ${COVERAGE_EXCLUDE} ENABLE ${TESSERACT_ENA add_library( ${PROJECT_NAME} + src/any.cpp src/joint_state.cpp src/manipulator_info.cpp src/kinematic_limits.cpp diff --git a/tesseract_common/include/tesseract_common/any.h b/tesseract_common/include/tesseract_common/any.h index c8a6e7fab2f..fd11c7be394 100644 --- a/tesseract_common/include/tesseract_common/any.h +++ b/tesseract_common/include/tesseract_common/any.h @@ -87,9 +87,7 @@ struct AnyInnerBase private: friend class boost::serialization::access; template - void serialize(Archive& /*ar*/, const unsigned int /*version*/) - { - } + void serialize(Archive& /*ar*/, const unsigned int /*version*/); // NOLINT }; template @@ -130,7 +128,7 @@ struct AnyInner final : AnyInnerBase private: friend class boost::serialization::access; template - void serialize(Archive& ar, const unsigned int /*version*/) + void serialize(Archive& ar, const unsigned int /*version*/) // NOLINT { // If this line is removed a exception is thrown for unregistered cast need to too look into this. ar& boost::serialization::make_nvp("base", boost::serialization::base_object(*this)); @@ -179,33 +177,22 @@ class Any { } - Any() // NOLINT - : any_type_(nullptr) - { - } + Any(); // NOLINT // Destructor ~Any() = default; // Copy constructor - Any(const Any& other) : any_type_(other.any_type_->clone()) {} + Any(const Any& other); // Move ctor. - Any(Any&& other) noexcept { any_type_.swap(other.any_type_); } + Any(Any&& other) noexcept; // Move assignment. - Any& operator=(Any&& other) noexcept - { - any_type_.swap(other.any_type_); - return (*this); - } + Any& operator=(Any&& other) noexcept; // Copy assignment. - Any& operator=(const Any& other) - { - (*this) = Any(other); - return (*this); - } + Any& operator=(const Any& other); template = 0> Any& operator=(T&& other) @@ -222,9 +209,9 @@ class Any return any_type_->getType(); } - bool operator==(const Any& rhs) const { return any_type_->operator==(*rhs.any_type_); } + bool operator==(const Any& rhs) const; - bool operator!=(const Any& rhs) const { return !operator==(rhs); } + bool operator!=(const Any& rhs) const; template T& as() @@ -249,10 +236,7 @@ class Any private: friend class boost::serialization::access; template - void serialize(Archive& ar, const unsigned int /*version*/) - { - ar& boost::serialization::make_nvp("any_type", any_type_); - } + void serialize(Archive& ar, const unsigned int /*version*/); // NOLINT std::unique_ptr any_type_; }; diff --git a/tesseract_common/src/any.cpp b/tesseract_common/src/any.cpp new file mode 100644 index 00000000000..db029890c4b --- /dev/null +++ b/tesseract_common/src/any.cpp @@ -0,0 +1,77 @@ +/** + * @file any.cpp + * @brief This a boost serializable any + * + * @author Levi Armstrong + * @date February 27, 2021 + * @version TODO + * @bug No known bugs + * + * @copyright Copyright (c) 2021, Southwest Research Institute + * + * @par License + * Software License Agreement (Apache License) + * @par + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * @par + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +namespace tesseract_common +{ +template +void detail_any::AnyInnerBase::serialize(Archive& /*ar*/, const unsigned int /*version*/) // NOLINT +{ +} + +Any::Any() // NOLINT + : any_type_(nullptr) +{ +} + +Any::Any(const Any& other) : any_type_(other.any_type_->clone()) {} + +Any::Any(Any&& other) noexcept { any_type_.swap(other.any_type_); } + +Any& Any::operator=(Any&& other) noexcept +{ + any_type_.swap(other.any_type_); + return (*this); +} + +Any& Any::operator=(const Any& other) +{ + (*this) = Any(other); + return (*this); +} + +bool Any::operator==(const Any& rhs) const { return any_type_->operator==(*rhs.any_type_); } + +bool Any::operator!=(const Any& rhs) const { return !operator==(rhs); } + +template +void Any::serialize(Archive& ar, const unsigned int /*version*/) // NOLINT +{ + ar& boost::serialization::make_nvp("any_type", any_type_); +} + +} // namespace tesseract_common + +#include +#include +template void tesseract_common::detail_any::AnyInnerBase::serialize(boost::archive::xml_oarchive& ar, + const unsigned int version); +template void tesseract_common::detail_any::AnyInnerBase::serialize(boost::archive::xml_iarchive& ar, + const unsigned int version); + +template void tesseract_common::Any::serialize(boost::archive::xml_oarchive& ar, const unsigned int version); +template void tesseract_common::Any::serialize(boost::archive::xml_iarchive& ar, const unsigned int version);