-
Notifications
You must be signed in to change notification settings - Fork 122
/
serialization.h
61 lines (53 loc) · 1.8 KB
/
serialization.h
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
#ifndef I3D_LINE3D_PP_SERIALIZATION_H_
#define I3D_LINE3D_PP_SERIALIZATION_H_
/*
* Line3D++ - Line-based Multi View Stereo
* Copyright (C) 2015 Manuel Hofer
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include <boost/filesystem.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <boost/serialization/nvp.hpp>
#include <boost/serialization/list.hpp>
#include <boost/serialization/vector.hpp>
#include <boost/serialization/map.hpp>
#include <boost/serialization/version.hpp>
#include <boost/serialization/split_free.hpp>
#include <fstream>
/**
* Line3D++ - Serialization
* ====================
* Handles serialization of view- and
* matching-data to the hard drive
* using boost.
* ====================
* Author: M.Hofer, 2015
*/
namespace L3DPP
{
// serialization
template <typename T>
inline void
serializeToFile(std::string file, T const& data, bool binary = true)
{
std::ofstream os(file.c_str(), binary? std::ios::binary : std::ios::out);
boost::archive::binary_oarchive ar(os);
ar & boost::serialization::make_nvp("data", data);
}
template <typename T>
inline void
serializeFromFile(std::string file, T& data, bool binary = true)
{
std::ifstream is(file.c_str(), binary? std::ios::binary : std::ios::in);
if(is.bad()) {
std::cout << "[L3D++] serializeFromFileArchive(): File '" << file << "'' could not be opened " << std::endl;
exit(1);
}
boost::archive::binary_iarchive ar(is);
ar & boost::serialization::make_nvp("data", data);
}
}
#endif //I3D_LINE3D_PP_SERIALIZATION_H_