QxOrm  1.2.9
C++ Object Relational Mapping library
QxArchive.h
Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** http://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 #ifndef _QX_ARCHIVE_H_
00033 #define _QX_ARCHIVE_H_
00034 
00035 #ifdef _MSC_VER
00036 #pragma once
00037 #endif
00038 
00046 #include <string>
00047 #include <iostream>
00048 #include <sstream>
00049 #include <fstream>
00050 #include <exception>
00051 
00052 #include <boost/archive/archive_exception.hpp>
00053 #include <boost/serialization/serialization.hpp>
00054 #include <boost/serialization/nvp.hpp>
00055 
00056 #include <QxTraits/archive_wide_traits.h>
00057 #include <QxTraits/get_class_name.h>
00058 #include <QxTraits/is_qx_registered.h>
00059 
00060 #include <QxCommon/QxConfig.h>
00061 #include <QxCommon/QxBool.h>
00062 
00063 #include <QxRegister/QxClass.h>
00064 #include <QxRegister/QxClassName.h>
00065 
00066 #include <QxSerialize/QxSerializeMacro.h>
00067 #include <QxSerialize/boost/QxSerializeInclude.h>
00068 #include <QxSerialize/QxBoostSerializeHelper/QxBoostSerializeRegisterHelperX.h>
00069 
00070 #define QX_STR_SERIALIZATION_ERROR "Serialization error : '%ERR%'"
00071 #define QX_STR_DESERIALIZATION_ERROR "Deserialization error : '%ERR%'"
00072 
00073 namespace qx {
00074 
00079 template <class T, class ArchiveInput = QX_DEFAULT_ARCHIVE_INPUT, class ArchiveOutput = QX_DEFAULT_ARCHIVE_OUTPUT>
00080 class QxArchive
00081 {
00082 
00083 public:
00084 
00085    typedef typename qx::trait::archive_wide_traits<ArchiveInput>::type_string type_string;
00086 
00087    static qx_bool toFile(const T & obj, const QString & sFileName, unsigned int flags = boost::archive::no_header);
00088    static qx_bool fromFile(T & obj, const QString & sFileName, unsigned int flags = boost::archive::no_header);
00089 
00090    static qx_bool toFileCompressed(const T & obj, const QString & sFileName, unsigned int flags = boost::archive::no_header, int iCompressionLevel = -1);
00091    static qx_bool fromFileCompressed(T & obj, const QString & sFileName, unsigned int flags = boost::archive::no_header);
00092 
00093    static QString toString(const T & obj, unsigned int flags = boost::archive::no_header);
00094    static qx_bool fromString(T & obj, const QString & sString, unsigned int flags = boost::archive::no_header);
00095 
00096    static QByteArray toByteArray(const T & obj, type_string * owner = NULL, unsigned int flags = boost::archive::no_header);
00097    static qx_bool fromByteArray(T & obj, const QByteArray & data, unsigned int flags = boost::archive::no_header);
00098 
00099 };
00100 
00101 } // namespace qx
00102 
00103 #include "../../inl/QxSerialize/QxArchive.inl"
00104 
00105 namespace qx {
00106 namespace serialization {
00107 
00108 QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, QX_DEFAULT_ARCHIVE_INPUT, QX_DEFAULT_ARCHIVE_OUTPUT)
00109 
00110 #if _QX_SERIALIZE_POLYMORPHIC
00111 
00116 namespace polymorphic_binary {      QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::polymorphic_binary_iarchive, boost::archive::polymorphic_binary_oarchive)
00117 } // namespace polymorphic_binary
00118 
00123 namespace polymorphic_text {        QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::polymorphic_text_iarchive, boost::archive::polymorphic_text_oarchive)
00124 } // namespace polymorphic_text
00125 
00130 namespace polymorphic_xml {         QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::polymorphic_xml_iarchive, boost::archive::polymorphic_xml_oarchive)
00131 } // namespace polymorphic_xml
00132 
00133 #endif // _QX_SERIALIZE_POLYMORPHIC
00134 
00135 #if _QX_SERIALIZE_BINARY
00136 
00141 namespace binary {            QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::binary_iarchive, boost::archive::binary_oarchive)
00142 } // namespace binary
00143 
00144 #endif // _QX_SERIALIZE_BINARY
00145 
00146 #if _QX_SERIALIZE_TEXT
00147 
00152 namespace text {              QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::text_iarchive, boost::archive::text_oarchive)
00153 } // namespace text
00154 
00155 #endif // _QX_SERIALIZE_TEXT
00156 
00157 #if _QX_SERIALIZE_XML
00158 
00163 namespace xml {               QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::xml_iarchive, boost::archive::xml_oarchive)
00164 } // namespace xml
00165 
00166 #endif // _QX_SERIALIZE_XML
00167 
00168 #if _QX_SERIALIZE_PORTABLE_BINARY
00169 
00174 namespace portable_binary {   QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, eos::portable_iarchive, eos::portable_oarchive)
00175 } // namespace portable_binary
00176 
00177 #endif // _QX_SERIALIZE_PORTABLE_BINARY
00178 
00179 namespace wide {
00180 
00181 #if _QX_SERIALIZE_WIDE_BINARY
00182 
00187 namespace binary {            QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::binary_wiarchive, boost::archive::binary_woarchive)
00188 } // namespace binary
00189 
00190 #endif // _QX_SERIALIZE_WIDE_BINARY
00191 
00192 #if _QX_SERIALIZE_WIDE_TEXT
00193 
00198 namespace text {              QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::text_wiarchive, boost::archive::text_woarchive)
00199 } // namespace text
00200 
00201 #endif // _QX_SERIALIZE_WIDE_TEXT
00202 
00203 #if _QX_SERIALIZE_WIDE_XML
00204 
00209 namespace xml {               QX_ARCHIVE_NAMESPACE_FCT_IMPL(T, boost::archive::xml_wiarchive, boost::archive::xml_woarchive)
00210 } // namespace xml
00211 
00212 #endif // _QX_SERIALIZE_WIDE_XML
00213 
00214 } // namespace wide
00215 } // namespace serialization
00216 } // namespace qx
00217 
00218 #endif // _QX_ARCHIVE_H_