| QxOrm 1.2.2 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

QxSerializeInvoker.h
Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** http://www.qxorm.com/
    00004 ** http://sourceforge.net/projects/qxorm/
    00005 ** Original file by Lionel Marty
    00006 **
    00007 ** This file is part of the QxOrm library
    00008 **
    00009 ** This software is provided 'as-is', without any express or implied
    00010 ** warranty. In no event will the authors be held liable for any
    00011 ** damages arising from the use of this software.
    00012 **
    00013 ** GNU Lesser General Public License Usage
    00014 ** This file must be used under the terms of the GNU Lesser
    00015 ** General Public License version 2.1 as published by the Free Software
    00016 ** Foundation and appearing in the file 'license.lgpl.txt' included in the
    00017 ** packaging of this file.  Please review the following information to
    00018 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00019 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00020 **
    00021 ** If you have questions regarding the use of this file, please contact :
    00022 ** contact@qxorm.com
    00023 **
    00024 ****************************************************************************/
    00025
    00026 #ifndef _QX_SERIALIZE_INVOKER_H_
    00027 #define _QX_SERIALIZE_INVOKER_H_
    00028
    00029 #ifdef _MSC_VER
    00030 #pragma once
    00031 #endif
    00032
    00033 #ifdef _MSC_VER
    00034 #pragma warning(push)
    00035 #pragma warning(disable:4996)
    00036 #pragma warning(disable:4094)
    00037 #endif // _MSC_VER
    00038
    00039 #include <boost/mpl/if.hpp>
    00040 #include <boost/mpl/logical.hpp>
    00041 #include <boost/static_assert.hpp>
    00042
    00043 #include <boost/serialization/serialization.hpp>
    00044 #include <boost/serialization/base_object.hpp>
    00045 #include <boost/serialization/nvp.hpp>
    00046
    00047 #include <QxTraits/get_base_class.h>
    00048 #include <QxTraits/is_qx_registered.h>
    00049
    00050 #include <QxRegister/QxClass.h>
    00051
    00052 namespace qx {
    00053 namespace serialization {
    00054 namespace detail {
    00055
    00056 template <class Base>
    00057 struct base_class
    00058 {
    00059    template <class Archive, class T>
    00060    static inline void save(Archive & ar, const T & t, const unsigned int file_version)
    00061    {
    00062       Q_UNUSED(file_version);
    00063       BOOST_STATIC_ASSERT(qx::trait::is_qx_registered<T>::value);
    00064       const char * sTag = QxClass<Base>::getSingleton()->getNamePtr();
    00065       ar << boost::serialization::make_nvp(sTag, boost::serialization::base_object<const Base>(t));
    00066    }
    00067    template <class Archive, class T>
    00068    static inline void load(Archive & ar, T & t, const unsigned int file_version)
    00069    {
    00070       Q_UNUSED(file_version);
    00071       BOOST_STATIC_ASSERT(qx::trait::is_qx_registered<T>::value);
    00072       const char * sTag = QxClass<Base>::getSingleton()->getNamePtr();
    00073       ar >> boost::serialization::make_nvp(sTag, boost::serialization::base_object<Base>(t));
    00074    }
    00075 };
    00076
    00077 template <>
    00078 struct base_class<qx::trait::no_base_class_defined>
    00079 {
    00080    template <class Archive, class T>
    00081    static inline void save(Archive & ar, const T & t, const unsigned int file_version)
    00082    { Q_UNUSED(ar); Q_UNUSED(t); Q_UNUSED(file_version); }
    00083    template <class Archive, class T>
    00084    static inline void load(Archive & ar, T & t, const unsigned int file_version)
    00085    { Q_UNUSED(ar); Q_UNUSED(t); Q_UNUSED(file_version); }
    00086 };
    00087
    00088 template <class Archive, class T>
    00089 void save(Archive & ar, const T & t, const unsigned int file_version)
    00090 {
    00091    typedef typename qx::trait::get_base_class<T>::type qx_type_base_class_tmp;
    00092    qx::serialization::detail::base_class<qx_type_base_class_tmp>::save(ar, t, file_version);
    00093    QxClass<T>::getSingleton()->dataMemberX()->toArchive(& t, ar, file_version);
    00094 }
    00095
    00096 template <class Archive, class T>
    00097 void load(Archive & ar, T & t, const unsigned int file_version)
    00098 {
    00099    typedef typename qx::trait::get_base_class<T>::type qx_type_base_class_tmp;
    00100    qx::serialization::detail::base_class<qx_type_base_class_tmp>::load(ar, t, file_version);
    00101    QxClass<T>::getSingleton()->dataMemberX()->fromArchive(& t, ar, file_version);
    00102 }
    00103
    00104 template <class Archive, class T>
    00105 struct saver
    00106 {
    00107    static inline void invoke(Archive & ar, const T & t, const unsigned int file_version)
    00108    { qx::serialization::detail::save(ar, t, file_version); }
    00109 };
    00110
    00111 template <class Archive, class T>
    00112 struct loader
    00113 {
    00114    static inline void invoke(Archive & ar, T & t, const unsigned int file_version)
    00115    { qx::serialization::detail::load(ar, t, file_version); }
    00116 };
    00117
    00118 } // namespace detail
    00119 } // namespace serialization
    00120 } // namespace qx
    00121
    00122 #include "../../inl/QxSerialize/QxSerializeInvoker.inl"
    00123
    00124 #ifdef _MSC_VER
    00125 #pragma warning(pop)
    00126 #endif // _MSC_VER
    00127
    00128 #endif // _QX_SERIALIZE_INVOKER_H_