From 0de0151cc99792e5836024fd6d56832503630a57 Mon Sep 17 00:00:00 2001 From: Levi Armstrong Date: Thu, 11 Jul 2024 14:05:09 -0500 Subject: [PATCH] Improve any poly serialization macros --- .../include/tesseract_common/any_poly.h | 50 +++++++------------ .../test/tesseract_common_unit.cpp | 3 +- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/tesseract_common/include/tesseract_common/any_poly.h b/tesseract_common/include/tesseract_common/any_poly.h index 875671cbfa3..4c20ffb47d4 100644 --- a/tesseract_common/include/tesseract_common/any_poly.h +++ b/tesseract_common/include/tesseract_common/any_poly.h @@ -29,7 +29,6 @@ TESSERACT_COMMON_IGNORE_WARNINGS_PUSH #include #include -#include #include TESSERACT_COMMON_IGNORE_WARNINGS_POP @@ -37,46 +36,33 @@ TESSERACT_COMMON_IGNORE_WARNINGS_POP #include /** @brief If shared library, this must go in the header after the class definition */ -#define TESSERACT_ANY_EXPORT_KEY(N, C) \ - namespace N \ +#define TESSERACT_ANY_EXPORT_KEY(C, K) \ + namespace tesseract_serialization::any_poly \ { \ - using C##AnyInstanceBase = tesseract_common::TypeErasureInstance; \ - using C##AnyInstance = tesseract_common::detail_any::AnyInstance; \ - using C##AnyInstanceWrapper = tesseract_common::TypeErasureInstanceWrapper; \ - using C##SharedPtrAnyInstanceBase = \ - tesseract_common::TypeErasureInstance, tesseract_common::TypeErasureInterface>; /* NOLINT */ \ - using C##SharedPtrAnyInstance = tesseract_common::detail_any::AnyInstance>; /* NOLINT */ \ - using C##SharedPtrAnyInstanceWrapper = tesseract_common::TypeErasureInstanceWrapper; \ + using K##AnyInstanceBase = tesseract_common::TypeErasureInstance; \ + using K##AnyInstance = tesseract_common::detail_any::AnyInstance; \ + using K##AnyInstanceWrapper = tesseract_common::TypeErasureInstanceWrapper; \ } \ - BOOST_CLASS_EXPORT_KEY(N::C##AnyInstanceBase) \ - BOOST_CLASS_EXPORT_KEY(N::C##AnyInstance) \ - BOOST_CLASS_EXPORT_KEY(N::C##AnyInstanceWrapper) \ - BOOST_CLASS_EXPORT_KEY(N::C##SharedPtrAnyInstanceBase) \ - BOOST_CLASS_EXPORT_KEY(N::C##SharedPtrAnyInstance) \ - BOOST_CLASS_EXPORT_KEY(N::C##SharedPtrAnyInstanceWrapper) \ - BOOST_CLASS_TRACKING(N::C##AnyInstanceBase, boost::serialization::track_never) \ - BOOST_CLASS_TRACKING(N::C##AnyInstance, boost::serialization::track_never) \ - BOOST_CLASS_TRACKING(N::C##AnyInstanceWrapper, boost::serialization::track_never) \ - BOOST_CLASS_TRACKING(N::C##SharedPtrAnyInstanceBase, boost::serialization::track_never) \ - BOOST_CLASS_TRACKING(N::C##SharedPtrAnyInstance, boost::serialization::track_never) \ - BOOST_CLASS_TRACKING(N::C##SharedPtrAnyInstanceWrapper, boost::serialization::track_never) + BOOST_CLASS_EXPORT_KEY(tesseract_serialization::any_poly::K##AnyInstanceBase) \ + BOOST_CLASS_EXPORT_KEY(tesseract_serialization::any_poly::K##AnyInstance) \ + BOOST_CLASS_EXPORT_KEY(tesseract_serialization::any_poly::K##AnyInstanceWrapper) \ + BOOST_CLASS_TRACKING(tesseract_serialization::any_poly::K##AnyInstanceBase, boost::serialization::track_never) \ + BOOST_CLASS_TRACKING(tesseract_serialization::any_poly::K##AnyInstance, boost::serialization::track_never) \ + BOOST_CLASS_TRACKING(tesseract_serialization::any_poly::K##AnyInstanceWrapper, boost::serialization::track_never) /** @brief If shared library, this must go in the cpp after the implicit instantiation of the serialize function */ -#define TESSERACT_ANY_EXPORT_IMPLEMENT(inst) \ - BOOST_CLASS_EXPORT_IMPLEMENT(inst##AnyInstanceBase) \ - BOOST_CLASS_EXPORT_IMPLEMENT(inst##AnyInstance) \ - BOOST_CLASS_EXPORT_IMPLEMENT(inst##AnyInstanceWrapper) \ - BOOST_CLASS_EXPORT_IMPLEMENT(inst##SharedPtrAnyInstanceBase) \ - BOOST_CLASS_EXPORT_IMPLEMENT(inst##SharedPtrAnyInstance) \ - BOOST_CLASS_EXPORT_IMPLEMENT(inst##SharedPtrAnyInstanceWrapper) +#define TESSERACT_ANY_EXPORT_IMPLEMENT(K) \ + BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_serialization::any_poly::K##AnyInstanceBase) \ + BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_serialization::any_poly::K##AnyInstance) \ + BOOST_CLASS_EXPORT_IMPLEMENT(tesseract_serialization::any_poly::K##AnyInstanceWrapper) /** * @brief This should not be used within shared libraries use the two above. * If not in a shared library it can go in header or cpp */ -#define TESSERACT_ANY_EXPORT(N, C) \ - TESSERACT_ANY_EXPORT_KEY(N, C) \ - TESSERACT_ANY_EXPORT_IMPLEMENT(N::C) +#define TESSERACT_ANY_EXPORT(C, K) \ + TESSERACT_ANY_EXPORT_KEY(C, K) \ + TESSERACT_ANY_EXPORT_IMPLEMENT(K) namespace tesseract_common::detail_any { diff --git a/tesseract_common/test/tesseract_common_unit.cpp b/tesseract_common/test/tesseract_common_unit.cpp index d44ddddb3cb..2a01b4e9c49 100644 --- a/tesseract_common/test/tesseract_common_unit.cpp +++ b/tesseract_common/test/tesseract_common_unit.cpp @@ -355,7 +355,8 @@ TEST(TesseractCommonUnit, JointStateTest) // NOLINT EXPECT_TRUE(joint_state.position.isApprox(positons, 1e-5)); } -TESSERACT_ANY_EXPORT(tesseract_common, JointState); // NOLINT +TESSERACT_ANY_EXPORT(tesseract_common::JointState, TesseractCommonJointState); // NOLINT +TESSERACT_ANY_EXPORT(std::shared_ptr, TesseractCommonJointStateSharedPtr) TEST(TesseractCommonUnit, anyUnit) // NOLINT {