-
Notifications
You must be signed in to change notification settings - Fork 0
/
q_xml_oarchive.hpp
95 lines (82 loc) · 2.89 KB
/
q_xml_oarchive.hpp
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
88
89
90
91
92
93
94
95
/**
qarchive - XML Archive class for boost serialization of Qt classes
Copyright (C) 2016 Kamil 'konserw' Strzempowicz, konserw@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
**/
#ifndef Q_XML_OARCHIVE_HPP
#define Q_XML_OARCHIVE_HPP
#include <QList>
#include <list>
#include <QString>
#include <string>
#define BOOST_ARCHIVE_SOURCE
#include <boost/archive/detail/register_archive.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/version.hpp>
using namespace boost::archive;
using boost::serialization::make_nvp;
using boost::serialization::nvp;
class q_xml_oarchive :
public xml_oarchive_impl<q_xml_oarchive>
{
typedef xml_oarchive_impl<q_xml_oarchive> base_t;
public:
// pass on most types to normal handling in the base class xml_oarchive
template<class T>
#if ((BOOST_VERSION / 100) % 1000) > 58
void save_override(T & t) {
base_t::save_override(t);
#else
void save_override(T & t, BOOST_PFTO int pfto){
base_t::save_override(t, pfto);
#endif
}
// catch QString
#if ((BOOST_VERSION / 100) % 1000) > 58
void save_override(const nvp<QString> & t)
#else
void save_override(const nvp<QString> & t, BOOST_PFTO int pfto)
#endif
{
std::string str = t.value().toStdString();
#if ((BOOST_VERSION / 100) % 1000) > 58
base_t::save_override(make_nvp(t.name(), str));
#else
base_t::save_override(make_nvp(t.name(), str), pfto);
#endif
}
// catch QList
template<class T>
#if ((BOOST_VERSION / 100) % 1000) > 58
void save_override(const nvp<QList<T> > & t)
#else
void save_override(const nvp<QList<T> > & t, BOOST_PFTO int pfto)
#endif
{
std::list<T> list = t.value().toStdList();
#if ((BOOST_VERSION / 100) % 1000) > 58
base_t::save_override(make_nvp(t.name(), list));
#else
base_t::save_override(make_nvp(t.name(), list), pfto);
#endif
}
//stuff needed by boost
q_xml_oarchive(std::ostream & os, unsigned int flags = 0) : base_t(os, flags){}
~q_xml_oarchive(){}
friend class detail::interface_oarchive<q_xml_oarchive>;
friend class detail::common_oarchive<q_xml_oarchive>;
friend class basic_xml_oarchive<q_xml_oarchive>;
// friend class save_access;
};
// required by export
BOOST_SERIALIZATION_REGISTER_ARCHIVE(q_xml_oarchive)
#endif // Q_XML_OARCHIVE_HPP