Skip to content

Commit

Permalink
Improve any poly serialization macros
Browse files Browse the repository at this point in the history
  • Loading branch information
Levi-Armstrong committed Jul 12, 2024
1 parent 0c6f05c commit 0de0151
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
50 changes: 18 additions & 32 deletions tesseract_common/include/tesseract_common/any_poly.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,54 +29,40 @@
TESSERACT_COMMON_IGNORE_WARNINGS_PUSH
#include <boost/serialization/base_object.hpp>
#include <boost/serialization/export.hpp>
#include <boost/serialization/shared_ptr.hpp>
#include <boost/concept_check.hpp>
TESSERACT_COMMON_IGNORE_WARNINGS_POP

#include <tesseract_common/serialization.h>
#include <tesseract_common/type_erasure.h>

/** @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<C, tesseract_common::TypeErasureInterface>; \
using C##AnyInstance = tesseract_common::detail_any::AnyInstance<C>; \
using C##AnyInstanceWrapper = tesseract_common::TypeErasureInstanceWrapper<C##AnyInstance>; \
using C##SharedPtrAnyInstanceBase = \
tesseract_common::TypeErasureInstance<std::shared_ptr<C>, tesseract_common::TypeErasureInterface>; /* NOLINT */ \
using C##SharedPtrAnyInstance = tesseract_common::detail_any::AnyInstance<std::shared_ptr<C>>; /* NOLINT */ \
using C##SharedPtrAnyInstanceWrapper = tesseract_common::TypeErasureInstanceWrapper<C##SharedPtrAnyInstance>; \
using K##AnyInstanceBase = tesseract_common::TypeErasureInstance<C, tesseract_common::TypeErasureInterface>; \
using K##AnyInstance = tesseract_common::detail_any::AnyInstance<C>; \
using K##AnyInstanceWrapper = tesseract_common::TypeErasureInstanceWrapper<K##AnyInstance>; \
} \
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
{
Expand Down
3 changes: 2 additions & 1 deletion tesseract_common/test/tesseract_common_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<tesseract_common::JointState>, TesseractCommonJointStateSharedPtr)

TEST(TesseractCommonUnit, anyUnit) // NOLINT
{
Expand Down

0 comments on commit 0de0151

Please sign in to comment.