QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxArchive.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifdef _QX_ENABLE_BOOST_SERIALIZATION
33#ifndef _QX_ARCHIVE_H_
34#define _QX_ARCHIVE_H_
35
36#ifdef _MSC_VER
37#pragma once
38#endif
39
47#include <string>
48#include <iostream>
49#include <sstream>
50#include <fstream>
51#include <exception>
52
53#include <boost/archive/archive_exception.hpp>
54#include <boost/serialization/serialization.hpp>
55#include <boost/serialization/nvp.hpp>
56
60
61#include <QxCommon/QxConfig.h>
62#include <QxCommon/QxBool.h>
63
64#include <QxRegister/QxClass.h>
66
70
71#define QX_STR_SERIALIZATION_ERROR "Serialization error : '%ERR%'"
72#define QX_STR_DESERIALIZATION_ERROR "Deserialization error : '%ERR%'"
73
74namespace qx {
75
80template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT>
82{ public: static qx_bool toFile(const T & obj, const QString & sFileName, unsigned int flags = boost::archive::no_header); };
83
88template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT>
90{ public: static qx_bool fromFile(T & obj, const QString & sFileName, unsigned int flags = boost::archive::no_header); };
91
96template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT>
98{ public: static qx_bool toFileCompressed(const T & obj, const QString & sFileName, unsigned int flags = boost::archive::no_header, int iCompressionLevel = -1); };
99
104template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT>
106{ public: static qx_bool fromFileCompressed(T & obj, const QString & sFileName, unsigned int flags = boost::archive::no_header); };
107
112template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT>
114{ public: static QString toString(const T & obj, unsigned int flags = boost::archive::no_header); };
115
120template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT>
122{ public: static qx_bool fromString(T & obj, const QString & sString, unsigned int flags = boost::archive::no_header); };
123
128template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT>
130{ public: typedef typename qx::trait::archive_wide_traits<ArchiveInput>::type_string type_string; static QByteArray toByteArray(const T & obj, type_string * owner = NULL, unsigned int flags = boost::archive::no_header); };
131
136template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT>
138{ public: static qx_bool fromByteArray(T & obj, const QByteArray & data, unsigned int flags = boost::archive::no_header); };
139
140} // namespace qx
141
142#include "../../inl/QxSerialize/QxArchive.inl"
143
144namespace qx {
145namespace serialization {
146
148
149#if _QX_SERIALIZE_POLYMORPHIC
150
155namespace polymorphic_binary { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::polymorphic_binary_iarchive, boost::archive::polymorphic_binary_oarchive)
156} // namespace polymorphic_binary
157
162namespace polymorphic_text { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::polymorphic_text_iarchive, boost::archive::polymorphic_text_oarchive)
163} // namespace polymorphic_text
164
169namespace polymorphic_xml { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::polymorphic_xml_iarchive, boost::archive::polymorphic_xml_oarchive)
170} // namespace polymorphic_xml
171
172#endif // _QX_SERIALIZE_POLYMORPHIC
173
174#if _QX_SERIALIZE_BINARY
175
180namespace binary { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::binary_iarchive, boost::archive::binary_oarchive)
181} // namespace binary
182
183#endif // _QX_SERIALIZE_BINARY
184
185#if _QX_SERIALIZE_TEXT
186
191namespace text { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::text_iarchive, boost::archive::text_oarchive)
192} // namespace text
193
194#endif // _QX_SERIALIZE_TEXT
195
196#if _QX_SERIALIZE_XML
197
202namespace xml { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::xml_iarchive, boost::archive::xml_oarchive)
203} // namespace xml
204
205#endif // _QX_SERIALIZE_XML
206
207#if _QX_SERIALIZE_PORTABLE_BINARY
208
214} // namespace portable_binary
215
216#endif // _QX_SERIALIZE_PORTABLE_BINARY
217
218namespace wide {
219
220#if _QX_SERIALIZE_WIDE_BINARY
221
226namespace binary { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
227} // namespace binary
228
229#endif // _QX_SERIALIZE_WIDE_BINARY
230
231#if _QX_SERIALIZE_WIDE_TEXT
232
237namespace text { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::text_wiarchive, boost::archive::text_woarchive)
238} // namespace text
239
240#endif // _QX_SERIALIZE_WIDE_TEXT
241
242#if _QX_SERIALIZE_WIDE_XML
243
248namespace xml { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
249} // namespace xml
250
251#endif // _QX_SERIALIZE_WIDE_XML
252
253} // namespace wide
254} // namespace serialization
255} // namespace qx
256
257#endif // _QX_ARCHIVE_H_
258#endif // _QX_ENABLE_BOOST_SERIALIZATION
qx_bool : QxOrm library boolean type with code and description message when an error occured
Concrete class registered into QxOrm context.
Provide a class helper to retrieve the class name under const char * format.
List of parameters to compile and build QxOrm library.
#define QX_DEFAULT_ARCHIVE_INPUT
#define QX_DEFAULT_ARCHIVE_OUTPUT
#define QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, INPUT, OUTPUT)
qx::trait::is_archive_wide<T>::value : define if a boost::archive type uses wide string character and...
Portable binary input archive using little endian format.
Portable binary output archive using little endian format.
qx::QxArchive_FromByteArray : provide some tools to serialize a class registered into QxOrm context i...
Definition QxArchive.h:138
static qx_bool fromByteArray(T &obj, const QByteArray &data, unsigned int flags=boost::archive::no_header)
qx::QxArchive_FromFileCompressed : provide some tools to serialize a class registered into QxOrm cont...
Definition QxArchive.h:106
static qx_bool fromFileCompressed(T &obj, const QString &sFileName, unsigned int flags=boost::archive::no_header)
qx::QxArchive_FromFile : provide some tools to serialize a class registered into QxOrm context into/f...
Definition QxArchive.h:90
static qx_bool fromFile(T &obj, const QString &sFileName, unsigned int flags=boost::archive::no_header)
qx::QxArchive_FromString : provide some tools to serialize a class registered into QxOrm context into...
Definition QxArchive.h:122
static qx_bool fromString(T &obj, const QString &sString, unsigned int flags=boost::archive::no_header)
qx::QxArchive_ToByteArray : provide some tools to serialize a class registered into QxOrm context int...
Definition QxArchive.h:130
static QByteArray toByteArray(const T &obj, type_string *owner=NULL, unsigned int flags=boost::archive::no_header)
qx::trait::archive_wide_traits< ArchiveInput >::type_string type_string
Definition QxArchive.h:130
qx::QxArchive_ToFileCompressed : provide some tools to serialize a class registered into QxOrm contex...
Definition QxArchive.h:98
static qx_bool toFileCompressed(const T &obj, const QString &sFileName, unsigned int flags=boost::archive::no_header, int iCompressionLevel=-1)
qx::QxArchive_ToFile : provide some tools to serialize a class registered into QxOrm context into/fro...
Definition QxArchive.h:82
static qx_bool toFile(const T &obj, const QString &sFileName, unsigned int flags=boost::archive::no_header)
qx::QxArchive_ToString : provide some tools to serialize a class registered into QxOrm context into/f...
Definition QxArchive.h:114
static QString toString(const T &obj, unsigned int flags=boost::archive::no_header)
qx_bool : boolean type with code and description message when an error occured
Definition QxBool.h:71
std::conditional< is_wide, std::wstring, std::string >::type type_string
qx::trait::get_class_name<T>::get() : return class name of type T under const char * format,...
qx::trait::is_qx_registered<T>::value : return true if T is registered into QxOrm context to provide ...
Root namespace for all QxOrm library features.