diff --git a/gtsam/nonlinear/ExpressionFactor.h b/gtsam/nonlinear/ExpressionFactor.h index 53c183c91..c8137a098 100644 --- a/gtsam/nonlinear/ExpressionFactor.h +++ b/gtsam/nonlinear/ExpressionFactor.h @@ -52,6 +52,9 @@ public: initialize(expression); } + /// Destructor + virtual ~ExpressionFactor() {} + /// print relies on Testable traits being defined for T void print(const std::string& s, const KeyFormatter& keyFormatter) const { NoiseModelFactor::print(s, keyFormatter); @@ -161,47 +164,6 @@ private: // ExpressionFactor -/** - * ExpressionFactor variant that supports serialization - * Simply overload the pure virtual method [expression] to construct an expression from keys_ - */ -template -class SerializableExpressionFactor : public ExpressionFactor { - public: - /// Constructor takes only two arguments, still need to call initialize - SerializableExpressionFactor(const SharedNoiseModel& noiseModel, const T& measurement) - : ExpressionFactor(noiseModel, measurement) { - } - - protected: - - /// Return an expression that predicts the measurement given Values - virtual Expression expression() const = 0; - - /// Default constructor, for serialization - SerializableExpressionFactor() {} - - /// Save to an archive: just saves the base class - template - void save(Archive& ar, const unsigned int /*version*/) const { - ar << boost::serialization::make_nvp( - "ExpressionFactor", boost::serialization::base_object >(*this)); - } - - /// Load from an archive, creating a valid expression using the overloaded [expression] method - template - void load(Archive& ar, const unsigned int /*version*/) { - ar >> boost::serialization::make_nvp( - "ExpressionFactor", boost::serialization::base_object >(*this)); - this->initialize(expression()); - } - - // Indicate that we implement save/load separately, and be friendly to boost - BOOST_SERIALIZATION_SPLIT_MEMBER() - friend class boost::serialization::access; -}; -// SerializableExpressionFactor - /// traits template struct traits > : public Testable > {}; diff --git a/gtsam/nonlinear/SerializableExpressionFactor.h b/gtsam/nonlinear/SerializableExpressionFactor.h new file mode 100644 index 000000000..09b4faa57 --- /dev/null +++ b/gtsam/nonlinear/SerializableExpressionFactor.h @@ -0,0 +1,75 @@ +/* ---------------------------------------------------------------------------- + + * GTSAM Copyright 2010, Georgia Tech Research Corporation, + * Atlanta, Georgia 30332-0415 + * All Rights Reserved + * Authors: Frank Dellaert, et al. (see THANKS for the full author list) + + * See LICENSE for the license information + + * -------------------------------------------------------------------------- */ + +/** + * @file SerializableExpressionFactor.h + * @date July 2015 + * @author Frank Dellaert + * @brief ExpressionFactor variant that supports serialization + */ + +#pragma once + +#include + +namespace gtsam { + +/** + * ExpressionFactor variant that supports serialization + * Simply overload the pure virtual method [expression] to construct an expression from keys_ + */ +template +class SerializableExpressionFactor : public ExpressionFactor { + public: + /// Constructor takes only two arguments, still need to call initialize + SerializableExpressionFactor(const SharedNoiseModel& noiseModel, const T& measurement) + : ExpressionFactor(noiseModel, measurement) { + } + + /// Destructor + virtual ~SerializableExpressionFactor() {} + + protected: + + /// Return an expression that predicts the measurement given Values + virtual Expression expression() const = 0; + + /// Default constructor, for serialization + SerializableExpressionFactor() {} + + /// Save to an archive: just saves the base class + template + void save(Archive& ar, const unsigned int /*version*/) const { + ar << boost::serialization::make_nvp( + "ExpressionFactor", boost::serialization::base_object >(*this)); + } + + /// Load from an archive, creating a valid expression using the overloaded [expression] method + template + void load(Archive& ar, const unsigned int /*version*/) { + ar >> boost::serialization::make_nvp( + "ExpressionFactor", boost::serialization::base_object >(*this)); + this->initialize(expression()); + } + + // Indicate that we implement save/load separately, and be friendly to boost + BOOST_SERIALIZATION_SPLIT_MEMBER() + friend class boost::serialization::access; +}; +// SerializableExpressionFactor + +/// traits +template +struct traits > + : public Testable > {}; + +}// \ namespace gtsam +