Skip to content

Commit

Permalink
Add any.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Jan 24, 2022
1 parent 95fca0b commit 6533573
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 26 deletions.
1 change: 1 addition & 0 deletions tesseract_common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
36 changes: 10 additions & 26 deletions tesseract_common/include/tesseract_common/any.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ struct AnyInnerBase
private:
friend class boost::serialization::access;
template <class Archive>
void serialize(Archive& /*ar*/, const unsigned int /*version*/)
{
}
void serialize(Archive& /*ar*/, const unsigned int /*version*/); // NOLINT
};

template <typename T>
Expand Down Expand Up @@ -130,7 +128,7 @@ struct AnyInner final : AnyInnerBase
private:
friend class boost::serialization::access;
template <class Archive>
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<AnyInnerBase>(*this));
Expand Down Expand Up @@ -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 <typename T, generic_ctor_enabler<T> = 0>
Any& operator=(T&& other)
Expand All @@ -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 <typename T>
T& as()
Expand All @@ -249,10 +236,7 @@ class Any
private:
friend class boost::serialization::access;
template <class Archive>
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<detail_any::AnyInnerBase> any_type_;
};
Expand Down
77 changes: 77 additions & 0 deletions tesseract_common/src/any.cpp
Original file line number Diff line number Diff line change
@@ -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 <tesseract_common/any.h>

namespace tesseract_common
{
template <class Archive>
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 <class Archive>
void Any::serialize(Archive& ar, const unsigned int /*version*/) // NOLINT
{
ar& boost::serialization::make_nvp("any_type", any_type_);
}

} // namespace tesseract_common

#include <boost/archive/xml_oarchive.hpp>
#include <boost/archive/xml_iarchive.hpp>
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);

0 comments on commit 6533573

Please sign in to comment.