File: serialize.h

package info (click to toggle)
sdpb 1.0-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 1,556 kB
  • ctags: 1,456
  • sloc: cpp: 12,762; makefile: 75; xml: 44
file content (87 lines) | stat: -rw-r--r-- 2,486 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
//=======================================================================
// Copyright 2014-2015 David Simmons-Duffin.
// Distributed under the MIT License.
// (See accompanying file LICENSE or copy at
//  http://opensource.org/licenses/MIT)
//=======================================================================


#ifndef SDPB_SERIALIZE_H_
#define SDPB_SERIALIZE_H_

#include <string>
#include <vector>
#include <sstream>
#include "boost/serialization/serialization.hpp"
#include "boost/serialization/base_object.hpp"
#include "boost/serialization/utility.hpp"
#include "boost/serialization/vector.hpp"
#include "boost/serialization/string.hpp"
#include "boost/serialization/split_free.hpp"
#include "boost/archive/text_iarchive.hpp"
#include "boost/archive/text_oarchive.hpp"
//Tweak to allow Ubuntu-14.04/gcc-4.8.4 and similar environments to compile
#define BOOST_NO_CXX11_SCOPED_ENUMS
#include <boost/filesystem.hpp>
#undef BOOST_NO_CXX11_SCOPED_ENUMS
#include "boost/filesystem/fstream.hpp"
#include "types.h"
#include "Vector.h"
#include "Matrix.h"
#include "BlockDiagonalMatrix.h"

using boost::filesystem::path;
using boost::archive::text_iarchive;
using std::vector;

namespace boost {
  namespace serialization {

    template<class Archive>
    void load(Archive& ar, Real& f, unsigned int version) {
      std::string s;
      ar & s;
      f = Real(s.c_str());
    }

    template<class Archive>
    void save(Archive& ar, Real const& f, unsigned int version) {
      std::ostringstream os;
      os.precision(f.get_prec());
      os << f;
      std::string s = os.str();
      ar & s;
    }

    template<class Archive>
    void serialize(Archive& ar, Matrix& m, const unsigned int version) {
      ar & m.rows;
      ar & m.cols;
      ar & m.elements;
    }

    template<class Archive>
    void serialize(Archive& ar, BlockDiagonalMatrix& m, const unsigned int version) {
      ar & m.dim;
      ar & m.blocks;
      ar & m.blockStartIndices;
    }

    template<class Archive>
    void serializeSDPSolverState(Archive& ar, Vector &x, BlockDiagonalMatrix &X, Vector &y, BlockDiagonalMatrix &Y) {
      ar & x;
      ar & X;
      ar & y;
      ar & Y;
    }

  }  // namespace serialization
}  // namespace boost


BOOST_SERIALIZATION_SPLIT_FREE(Real)
BOOST_CLASS_VERSION(Real, 0)
BOOST_CLASS_TRACKING(Matrix,              boost::serialization::track_never)
BOOST_CLASS_TRACKING(BlockDiagonalMatrix, boost::serialization::track_never)

#endif  // SDPB_SERIALIZE_H_