Skip to content

Commit

Permalink
Merge pull request #1409 from kartikarcot/verdant/boost-serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
dellaert committed Jan 24, 2023
2 parents 21bd4f7 + 1d7181b commit dd95757
Show file tree
Hide file tree
Showing 176 changed files with 591 additions and 34 deletions.
7 changes: 7 additions & 0 deletions cmake/HandleGeneralOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ option(GTSAM_ALLOW_DEPRECATED_SINCE_V43 "Allow use of methods/functions depr
option(GTSAM_SUPPORT_NESTED_DISSECTION "Support Metis-based nested dissection" ON)
option(GTSAM_TANGENT_PREINTEGRATION "Use new ImuFactor with integration on tangent space" ON)
option(GTSAM_SLOW_BUT_CORRECT_BETWEENFACTOR "Use the slower but correct version of BetweenFactor" OFF)
option(GTSAM_ENABLE_BOOST_SERIALIZATION "Enable Boost serialization" ON)

#TODO(kartikarcot) defining it in config.h.in did not work
if (GTSAM_ENABLE_BOOST_SERIALIZATION)
add_definitions(-DGTSAM_ENABLE_BOOST_SERIALIZATION)
endif()

if(NOT MSVC AND NOT XCODE_VERSION)
option(GTSAM_BUILD_WITH_CCACHE "Use ccache compiler cache" ON)
endif()
Expand Down
8 changes: 8 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,12 @@ set (excluded_examples
elaboratePoint2KalmanFilter.cpp
)

# if GTSAM_ENABLE_BOOST_SERIALIZATION is not set then SolverComparer.cpp will not compile
if (NOT GTSAM_ENABLE_BOOST_SERIALIZATION)
set (excluded_examples
${excluded_examples}
SolverComparer.cpp
)
endif()

gtsamAddExamplesGlob("*.cpp" "${excluded_examples}" "gtsam;gtsam_unstable;${Boost_PROGRAM_OPTIONS_LIBRARY}")
4 changes: 4 additions & 0 deletions gtsam/base/ConcurrentMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ using ConcurrentMapBase = gtsam::FastMap<KEY, VALUE>;

#endif

#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/split_member.hpp>
#endif
#include <boost/static_assert.hpp>

#include <gtsam/base/FastVector.h>
Expand Down Expand Up @@ -100,6 +102,7 @@ class ConcurrentMap : public ConcurrentMapBase<KEY,VALUE> {
#endif

private:
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template<class Archive>
Expand All @@ -120,6 +123,7 @@ class ConcurrentMap : public ConcurrentMapBase<KEY,VALUE> {
this->insert(map.begin(), map.end());
}
BOOST_SERIALIZATION_SPLIT_MEMBER()
#endif
};

}
5 changes: 4 additions & 1 deletion gtsam/base/FastList.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
#include <gtsam/base/FastDefaultAllocator.h>
#include <list>
#include <boost/utility/enable_if.hpp>
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/version.hpp>
#include <boost/serialization/optional.hpp>
#include <boost/serialization/list.hpp>
#endif

namespace gtsam {

Expand Down Expand Up @@ -76,12 +77,14 @@ class FastList: public std::list<VALUE, typename internal::FastDefaultAllocator<
}

private:
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template<class ARCHIVE>
void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
}
#endif

};

Expand Down
4 changes: 4 additions & 0 deletions gtsam/base/FastMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
#pragma once

#include <gtsam/base/FastDefaultAllocator.h>
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/map.hpp>
#endif
#include <map>

namespace gtsam {
Expand Down Expand Up @@ -67,12 +69,14 @@ class FastMap : public std::map<KEY, VALUE, std::less<KEY>,
bool exists(const KEY& e) const { return this->find(e) != this->end(); }

private:
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template<class ARCHIVE>
void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
}
#endif
};

}
4 changes: 4 additions & 0 deletions gtsam/base/FastSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@
#pragma once

#include <boost/version.hpp>
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
#if BOOST_VERSION >= 107400
#include <boost/serialization/library_version_type.hpp>
#endif
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/set.hpp>
#endif
#include <gtsam/base/FastDefaultAllocator.h>
#include <gtsam/base/Testable.h>

Expand Down Expand Up @@ -121,12 +123,14 @@ class FastSet: public std::set<VALUE, std::less<VALUE>,
}

private:
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template<class ARCHIVE>
void serialize(ARCHIVE & ar, const unsigned int /*version*/) {
ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Base);
}
#endif
};

}
2 changes: 2 additions & 0 deletions gtsam/base/GenericValue.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ class GenericValue: public Value {

private:

#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template<class ARCHIVE>
Expand All @@ -183,6 +184,7 @@ class GenericValue: public Value {
boost::serialization::base_object<Value>(*this));
ar & boost::serialization::make_nvp("value", value_);
}
#endif


// Alignment, see https://eigen.tuxfamily.org/dox/group__TopicStructHavingEigenMembers.html
Expand Down
3 changes: 3 additions & 0 deletions gtsam/base/MatrixSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@

// \callgraph

// Defined only if boost serialization is enabled
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
#pragma once

#include <gtsam/base/Matrix.h>
Expand Down Expand Up @@ -87,3 +89,4 @@ void serialize(Archive& ar, gtsam::Matrix& m, const unsigned int version) {

} // namespace serialization
} // namespace boost
#endif
4 changes: 4 additions & 0 deletions gtsam/base/SymmetricBlockMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <gtsam/base/Matrix.h>
#include <gtsam/base/types.h>
#include <gtsam/dllexport.h>
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/nvp.hpp>
#endif
#include <cassert>
#include <stdexcept>
#include <array>
Expand Down Expand Up @@ -384,6 +386,7 @@ namespace gtsam {
template<typename SymmetricBlockMatrixType> friend class SymmetricBlockMatrixBlockExpr;

private:
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template<class ARCHIVE>
Expand All @@ -396,6 +399,7 @@ namespace gtsam {
ar & BOOST_SERIALIZATION_NVP(variableColOffsets_);
ar & BOOST_SERIALIZATION_NVP(blockStart_);
}
#endif
};

/// Foward declare exception class
Expand Down
6 changes: 6 additions & 0 deletions gtsam/base/Value.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@
#include <gtsam/config.h> // Configuration from CMake

#include <gtsam/base/Vector.h>
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/assume_abstract.hpp>
#endif
#include <memory>

namespace gtsam {
Expand Down Expand Up @@ -119,13 +121,17 @@ namespace gtsam {
* The last two links explain why these export lines have to be in the same source module that includes
* any of the archive class headers.
* */
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
friend class boost::serialization::access;
template<class ARCHIVE>
void serialize(ARCHIVE & /*ar*/, const unsigned int /*version*/) {
}
#endif

};

} /* namespace gtsam */

#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
BOOST_SERIALIZATION_ASSUME_ABSTRACT(gtsam::Value)
#endif
3 changes: 3 additions & 0 deletions gtsam/base/VectorSerialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* @date February 2022
*/

// Defined only if boost serialization is enabled
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
#pragma once

#include <gtsam/base/Vector.h>
Expand Down Expand Up @@ -63,3 +65,4 @@ BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector)
BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector2)
BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector3)
BOOST_SERIALIZATION_SPLIT_FREE(gtsam::Vector6)
#endif
2 changes: 2 additions & 0 deletions gtsam/base/VerticalBlockMatrix.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ namespace gtsam {
friend class SymmetricBlockMatrix;

private:
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template<class ARCHIVE>
Expand All @@ -229,6 +230,7 @@ namespace gtsam {
ar & BOOST_SERIALIZATION_NVP(rowEnd_);
ar & BOOST_SERIALIZATION_NVP(blockStart_);
}
#endif
};

}
2 changes: 2 additions & 0 deletions gtsam/base/serializationTestHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @date Feb 7, 2012
*/

#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
#pragma once

#include <iostream>
Expand Down Expand Up @@ -175,3 +176,4 @@ bool equalsDereferencedBinary(const T& input = T()) {

} // \namespace serializationTestHelpers
} // \namespace gtsam
#endif
4 changes: 3 additions & 1 deletion gtsam/base/std_optional_serialization.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
* Inspired from this PR: https://github.com/boostorg/serialization/pull/163
* ---------------------------------------------------------------------------- */

// Defined only if boost serialization is enabled
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
#pragma once
#include <optional>
#include <boost/config.hpp>
Expand Down Expand Up @@ -97,4 +99,4 @@ void serialize(Archive& ar, std::optional<T>& t, const unsigned int version) {

} // namespace serialization
} // namespace boost

#endif
10 changes: 9 additions & 1 deletion gtsam/base/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
gtsamAddTestsGlob(base "test*.cpp" "" "gtsam")
# if GTSAM_ENABLE_BOOST_SERIALIZATION is OFF then exclude some tests
if (NOT GTSAM_ENABLE_BOOST_SERIALIZATION)
# create a semicolon seperated list of files to exclude
set(EXCLUDE_TESTS "testSerializationBase.cpp" "testStdOptionalSerialization.cpp")
else()
set(EXCLUDE_TESTS "")
endif()

gtsamAddTestsGlob(base "test*.cpp" "${EXCLUDE_TESTS}" "gtsam")
1 change: 1 addition & 0 deletions gtsam/base/timing.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <boost/version.hpp>

#include <memory>
#include <cstddef>
#include <string>

Expand Down
1 change: 1 addition & 0 deletions gtsam/base/treeTraversal-inst.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <vector>
#include <string>
#include <memory>
#include <cassert>

namespace gtsam {

Expand Down
4 changes: 4 additions & 0 deletions gtsam/discrete/DecisionTree-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ namespace gtsam {
private:
using Base = DecisionTree<L, Y>::Node;

#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template <class ARCHIVE>
Expand All @@ -162,6 +163,7 @@ namespace gtsam {
ar& BOOST_SERIALIZATION_NVP(constant_);
ar& BOOST_SERIALIZATION_NVP(nrAssignments_);
}
#endif
}; // Leaf

/****************************************************************************/
Expand Down Expand Up @@ -443,6 +445,7 @@ namespace gtsam {
private:
using Base = DecisionTree<L, Y>::Node;

#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template <class ARCHIVE>
Expand All @@ -452,6 +455,7 @@ namespace gtsam {
ar& BOOST_SERIALIZATION_NVP(branches_);
ar& BOOST_SERIALIZATION_NVP(allSame_);
}
#endif
}; // Choice

/****************************************************************************/
Expand Down
6 changes: 6 additions & 0 deletions gtsam/discrete/DecisionTree.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
#include <gtsam/base/types.h>
#include <gtsam/discrete/Assignment.h>

#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
#include <boost/serialization/nvp.hpp>
#endif
#include <memory>
#include <functional>
#include <iostream>
Expand Down Expand Up @@ -117,10 +119,12 @@ namespace gtsam {
virtual bool isLeaf() const = 0;

private:
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template <class ARCHIVE>
void serialize(ARCHIVE& ar, const unsigned int /*version*/) {}
#endif
};
/** ------------------------ Node base class --------------------------- */

Expand Down Expand Up @@ -374,12 +378,14 @@ namespace gtsam {
/// @}

private:
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template <class ARCHIVE>
void serialize(ARCHIVE& ar, const unsigned int /*version*/) {
ar& BOOST_SERIALIZATION_NVP(root_);
}
#endif
}; // DecisionTree

template <class L, class Y>
Expand Down
2 changes: 2 additions & 0 deletions gtsam/discrete/DecisionTreeFactor.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ namespace gtsam {
/// @}

private:
#ifdef GTSAM_ENABLE_BOOST_SERIALIZATION
/** Serialization function */
friend class boost::serialization::access;
template <class ARCHIVE>
Expand All @@ -261,6 +262,7 @@ namespace gtsam {
ar& BOOST_SERIALIZATION_BASE_OBJECT_NVP(ADT);
ar& BOOST_SERIALIZATION_NVP(cardinalities_);
}
#endif
};

// traits
Expand Down
Loading

0 comments on commit dd95757

Please sign in to comment.