QxOrm
1.5.0
C++ Object Relational Mapping library
|
00001 /**************************************************************************** 00002 ** 00003 ** https://www.qxorm.com/ 00004 ** Copyright (C) 2013 Lionel Marty (contact@qxorm.com) 00005 ** 00006 ** This file is part of the QxOrm library 00007 ** 00008 ** This software is provided 'as-is', without any express or implied 00009 ** warranty. In no event will the authors be held liable for any 00010 ** damages arising from the use of this software 00011 ** 00012 ** Commercial Usage 00013 ** Licensees holding valid commercial QxOrm licenses may use this file in 00014 ** accordance with the commercial license agreement provided with the 00015 ** Software or, alternatively, in accordance with the terms contained in 00016 ** a written agreement between you and Lionel Marty 00017 ** 00018 ** GNU General Public License Usage 00019 ** Alternatively, this file may be used under the terms of the GNU 00020 ** General Public License version 3.0 as published by the Free Software 00021 ** Foundation and appearing in the file 'license.gpl3.txt' included in the 00022 ** packaging of this file. Please review the following information to 00023 ** ensure the GNU General Public License version 3.0 requirements will be 00024 ** met : http://www.gnu.org/copyleft/gpl.html 00025 ** 00026 ** If you are unsure which license is appropriate for your use, or 00027 ** if you have questions regarding the use of this file, please contact : 00028 ** contact@qxorm.com 00029 ** 00030 ****************************************************************************/ 00031 00032 #ifdef _QX_ENABLE_BOOST_SERIALIZATION 00033 #ifndef _QX_ARCHIVE_H_ 00034 #define _QX_ARCHIVE_H_ 00035 00036 #ifdef _MSC_VER 00037 #pragma once 00038 #endif 00039 00047 #include <string> 00048 #include <iostream> 00049 #include <sstream> 00050 #include <fstream> 00051 #include <exception> 00052 00053 #include <boost/archive/archive_exception.hpp> 00054 #include <boost/serialization/serialization.hpp> 00055 #include <boost/serialization/nvp.hpp> 00056 00057 #include <QxTraits/archive_wide_traits.h> 00058 #include <QxTraits/get_class_name.h> 00059 #include <QxTraits/is_qx_registered.h> 00060 00061 #include <QxCommon/QxConfig.h> 00062 #include <QxCommon/QxBool.h> 00063 00064 #include <QxRegister/QxClass.h> 00065 #include <QxRegister/QxClassName.h> 00066 00067 #include <QxSerialize/QxSerializeMacro.h> 00068 #include <QxSerialize/boost/QxSerializeInclude.h> 00069 #include <QxSerialize/QxBoostSerializeHelper/QxBoostSerializeRegisterHelperX.h> 00070 00071 #define QX_STR_SERIALIZATION_ERROR "Serialization error : '%ERR%'" 00072 #define QX_STR_DESERIALIZATION_ERROR "Deserialization error : '%ERR%'" 00073 00074 namespace qx { 00075 00080 template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT> 00081 class QxArchive_ToFile 00082 { public: static qx_bool toFile(const T & obj, const QString & sFileName, unsigned int flags = boost::archive::no_header); }; 00083 00088 template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT> 00089 class QxArchive_FromFile 00090 { public: static qx_bool fromFile(T & obj, const QString & sFileName, unsigned int flags = boost::archive::no_header); }; 00091 00096 template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT> 00097 class QxArchive_ToFileCompressed 00098 { public: static qx_bool toFileCompressed(const T & obj, const QString & sFileName, unsigned int flags = boost::archive::no_header, int iCompressionLevel = -1); }; 00099 00104 template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT> 00105 class QxArchive_FromFileCompressed 00106 { public: static qx_bool fromFileCompressed(T & obj, const QString & sFileName, unsigned int flags = boost::archive::no_header); }; 00107 00112 template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT> 00113 class QxArchive_ToString 00114 { public: static QString toString(const T & obj, unsigned int flags = boost::archive::no_header); }; 00115 00120 template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT> 00121 class QxArchive_FromString 00122 { public: static qx_bool fromString(T & obj, const QString & sString, unsigned int flags = boost::archive::no_header); }; 00123 00128 template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT> 00129 class QxArchive_ToByteArray 00130 { 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); }; 00131 00136 template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT> 00137 class QxArchive_FromByteArray 00138 { public: static qx_bool fromByteArray(T & obj, const QByteArray & data, unsigned int flags = boost::archive::no_header); }; 00139 00140 } // namespace qx 00141 00142 #include "../../inl/QxSerialize/QxArchive.inl" 00143 00144 namespace qx { 00145 namespace serialization { 00146 00147 QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, QX_DEFAULT_ARCHIVE_INPUT, QX_DEFAULT_ARCHIVE_OUTPUT) 00148 00149 #if _QX_SERIALIZE_POLYMORPHIC 00150 00155 namespace polymorphic_binary { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::polymorphic_binary_iarchive, boost::archive::polymorphic_binary_oarchive) 00156 } // namespace polymorphic_binary 00157 00162 namespace polymorphic_text { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::polymorphic_text_iarchive, boost::archive::polymorphic_text_oarchive) 00163 } // namespace polymorphic_text 00164 00169 namespace polymorphic_xml { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::polymorphic_xml_iarchive, boost::archive::polymorphic_xml_oarchive) 00170 } // namespace polymorphic_xml 00171 00172 #endif // _QX_SERIALIZE_POLYMORPHIC 00173 00174 #if _QX_SERIALIZE_BINARY 00175 00180 namespace binary { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::binary_iarchive, boost::archive::binary_oarchive) 00181 } // namespace binary 00182 00183 #endif // _QX_SERIALIZE_BINARY 00184 00185 #if _QX_SERIALIZE_TEXT 00186 00191 namespace text { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::text_iarchive, boost::archive::text_oarchive) 00192 } // namespace text 00193 00194 #endif // _QX_SERIALIZE_TEXT 00195 00196 #if _QX_SERIALIZE_XML 00197 00202 namespace xml { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::xml_iarchive, boost::archive::xml_oarchive) 00203 } // namespace xml 00204 00205 #endif // _QX_SERIALIZE_XML 00206 00207 #if _QX_SERIALIZE_PORTABLE_BINARY 00208 00213 namespace portable_binary { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, eos::portable_iarchive, eos::portable_oarchive) 00214 } // namespace portable_binary 00215 00216 #endif // _QX_SERIALIZE_PORTABLE_BINARY 00217 00218 namespace wide { 00219 00220 #if _QX_SERIALIZE_WIDE_BINARY 00221 00226 namespace binary { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::binary_wiarchive, boost::archive::binary_woarchive) 00227 } // namespace binary 00228 00229 #endif // _QX_SERIALIZE_WIDE_BINARY 00230 00231 #if _QX_SERIALIZE_WIDE_TEXT 00232 00237 namespace text { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::text_wiarchive, boost::archive::text_woarchive) 00238 } // namespace text 00239 00240 #endif // _QX_SERIALIZE_WIDE_TEXT 00241 00242 #if _QX_SERIALIZE_WIDE_XML 00243 00248 namespace xml { QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::xml_wiarchive, boost::archive::xml_woarchive) 00249 } // namespace xml 00250 00251 #endif // _QX_SERIALIZE_WIDE_XML 00252 00253 } // namespace wide 00254 } // namespace serialization 00255 } // namespace qx 00256 00257 #endif // _QX_ARCHIVE_H_ 00258 #endif // _QX_ENABLE_BOOST_SERIALIZATION