Skip to content
Snippets Groups Projects
ExprtkWrapperSerialization.h 2.19 KiB
Newer Older

#ifndef LIB4NEURO_EXPRTKWRAPPERSERIALIZATION_H
#define LIB4NEURO_EXPRTKWRAPPERSERIALIZATION_H

#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/serialization/export.hpp>

//TODO check different order of headers - possible bug
#include "ExprtkWrapper.h"
#include "exprtk.hpp"

BOOST_CLASS_EXPORT_KEY(ExprtkWrapper);

typedef exprtk::symbol_table<double> symbol_table_t;
typedef exprtk::expression<double>   expression_t;
typedef exprtk::parser<double>       parser_t;

/**
 * Class implementing the private properties
 * of ExprtkWrapper class.
 */
Martin Beseda's avatar
Martin Beseda committed
class ExprtkWrapper::ExprtkWrapperImpl {

public:

    /**
     * Struct used to access private properties from
     * the serialization function
     */
    struct access;

    /**
     *
     */
Martin Beseda's avatar
Martin Beseda committed
    expression_t* expression = nullptr;
Martin Beseda's avatar
Martin Beseda committed
    symbol_table_t* symbol_table = nullptr;
Martin Beseda's avatar
Martin Beseda committed
    parser_t* parser = nullptr;

    /**
     * variables
     */
    double x, y, z, t, f;

    /**
     * referential expression string
     */
    std::string expression_str;
};

Martin Beseda's avatar
Martin Beseda committed
struct ExprtkWrapper::access {
    template<class Archive>
    static void serialize(Archive& ar,
                          ExprtkWrapper& n,
                          const unsigned int version) {
        ar & n.p_impl->expression_str;
        ar & n.p_impl->x & n.p_impl->y & n.p_impl->z & n.p_impl->t & n.p_impl->f;
    }
};

namespace boost {
    namespace serialization {

        /**
         * Serialization function
         * @tparam Archive Boost library template
         * @param ar Boost parameter - filled automatically during serialization!
         * @param n ExprtkWrapper instance
         * @param version Boost parameter - filled automatically during serialization!
         */
        template<class Archive>
Martin Beseda's avatar
Martin Beseda committed
        void serialize(Archive& ar,
                       ExprtkWrapper& n,
                       const unsigned int version) {
            ExprtkWrapper::access::serialize(ar,
                                             n,
                                             version);
#endif //LIB4NEURO_EXPRTKWRAPPERSERIALIZATION_H