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
96
97
98
99
100
101
102
103
104
105
|
// Copyright (C) 2016 Jochen Becher
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0 WITH Qt-GPL-exception-1.0
#pragma once
#include "parameters.h"
#include "qstringparser/qstringparser.h"
#include <QString>
#include <QPointF>
#include <QRectF>
#include <QDateTime>
#define QARK_BASIC_SAVELOAD(TYPE) \
template<class Archive> \
inline void save(Archive &archive, TYPE v, const Parameters &) \
{ \
archive.write(v); \
} \
template<class Archive> \
inline void load(Archive &archive, TYPE &v, const Parameters &) \
{ \
archive.read(&v); \
}
namespace qark {
QARK_BASIC_SAVELOAD(char)
QARK_BASIC_SAVELOAD(signed char)
QARK_BASIC_SAVELOAD(unsigned char)
QARK_BASIC_SAVELOAD(short int)
QARK_BASIC_SAVELOAD(unsigned short int)
QARK_BASIC_SAVELOAD(int)
QARK_BASIC_SAVELOAD(unsigned int)
QARK_BASIC_SAVELOAD(long int)
QARK_BASIC_SAVELOAD(unsigned long int)
QARK_BASIC_SAVELOAD(long long int)
QARK_BASIC_SAVELOAD(unsigned long long int)
QARK_BASIC_SAVELOAD(float)
QARK_BASIC_SAVELOAD(double)
QARK_BASIC_SAVELOAD(long double)
QARK_BASIC_SAVELOAD(bool)
QARK_BASIC_SAVELOAD(QString)
#undef QARK_BASIC_SAVELOAD
// QPointF
template<class Archive>
inline void save(Archive &archive, const QPointF &point, const Parameters &)
{
archive.write(QString("x:%1;y:%2").arg(point.x()).arg(point.y()));
}
template<class Archive>
inline void load(Archive &archive, QPointF &point, const Parameters &)
{
QString s;
archive.read(&s);
if (QStringParser(s).parse("x:%1;y:%2")
.arg(point, &QPointF::setX).arg(point, &QPointF::setY).failed()) {
throw typename Archive::FileFormatException();
}
}
// QRectF
template<class Archive>
inline void save(Archive &archive, const QRectF &rect, const Parameters &)
{
archive.write(QString("x:%1;y:%2;w:%3;h:%4")
.arg(rect.x()).arg(rect.y()).arg(rect.width()).arg(rect.height()));
}
template<class Archive>
inline void load(Archive &archive, QRectF &point, const Parameters &)
{
QString s;
archive.read(&s);
if (QStringParser(s).parse("x:%1;y:%2;w:%3;h:%4")
.arg(point, &QRectF::setX).arg(point, &QRectF::setY)
.arg(point, &QRectF::setWidth).arg(point, &QRectF::setHeight).failed()) {
throw typename Archive::FileFormatException();
}
}
// QDateTime
template<class Archive>
inline void save(Archive &archive, const QDateTime &dateTime, const Parameters &)
{
archive << dateTime.toMSecsSinceEpoch();
}
template<class Archive>
inline void load(Archive &archive, QDateTime &dateTime, const Parameters &)
{
qint64 t;
archive >> t;
dateTime = QDateTime::fromMSecsSinceEpoch(t);
}
} // namespace qark
|