QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxSerializeInvoker.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_SERIALIZE_INVOKER_H_
34#define _QX_SERIALIZE_INVOKER_H_
35
36#ifdef _MSC_VER
37#pragma once
38#endif
39
40#ifdef _MSC_VER
41#pragma warning(push)
42#pragma warning(disable:4996)
43#pragma warning(disable:4094)
44#endif // _MSC_VER
45
46#include <boost/serialization/serialization.hpp>
47#include <boost/serialization/base_object.hpp>
48#include <boost/serialization/nvp.hpp>
49
52
53#include <QxRegister/QxClass.h>
54
55namespace qx {
56namespace serialization {
57namespace detail {
58
59template <class Base>
61{
62 template <class Archive, class T>
63 static inline void save(Archive & ar, const T & t, const unsigned int file_version)
64 {
65 Q_UNUSED(file_version);
66 static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
67 const char * sTag = QxClass<Base>::getSingleton()->getNamePtr();
68 ar << boost::serialization::make_nvp(sTag, boost::serialization::base_object<const Base>(t));
69 }
70 template <class Archive, class T>
71 static inline void load(Archive & ar, T & t, const unsigned int file_version)
72 {
73 Q_UNUSED(file_version);
74 static_assert(qx::trait::is_qx_registered<T>::value, "qx::trait::is_qx_registered<T>::value");
75 const char * sTag = QxClass<Base>::getSingleton()->getNamePtr();
76 ar >> boost::serialization::make_nvp(sTag, boost::serialization::base_object<Base>(t));
77 }
78};
79
80template <>
82{
83 template <class Archive, class T>
84 static inline void save(Archive & ar, const T & t, const unsigned int file_version)
85 { Q_UNUSED(ar); Q_UNUSED(t); Q_UNUSED(file_version); }
86 template <class Archive, class T>
87 static inline void load(Archive & ar, T & t, const unsigned int file_version)
88 { Q_UNUSED(ar); Q_UNUSED(t); Q_UNUSED(file_version); }
89};
90
91template <class Archive, class T>
92void save(Archive & ar, const T & t, const unsigned int file_version)
93{
94 typedef typename qx::trait::get_base_class<T>::type qx_type_base_class_tmp;
96 QxClass<T>::getSingleton()->dataMemberX()->toArchive(& t, ar, file_version);
97}
98
99template <class Archive, class T>
100void load(Archive & ar, T & t, const unsigned int file_version)
101{
102 typedef typename qx::trait::get_base_class<T>::type qx_type_base_class_tmp;
104 QxClass<T>::getSingleton()->dataMemberX()->fromArchive(& t, ar, file_version);
105}
106
107template <class Archive, class T>
108struct saver
109{
110 static inline void invoke(Archive & ar, const T & t, const unsigned int file_version)
111 { qx::serialization::detail::save(ar, t, file_version); }
112};
113
114template <class Archive, class T>
115struct loader
116{
117 static inline void invoke(Archive & ar, T & t, const unsigned int file_version)
118 { qx::serialization::detail::load(ar, t, file_version); }
119};
120
121} // namespace detail
122} // namespace serialization
123} // namespace qx
124
125#include "../../inl/QxSerialize/QxSerializeInvoker.inl"
126
127#ifdef _MSC_VER
128#pragma warning(pop)
129#endif // _MSC_VER
130
131#endif // _QX_SERIALIZE_INVOKER_H_
132#endif // _QX_ENABLE_BOOST_SERIALIZATION
Concrete class registered into QxOrm context.
qx::trait::get_base_class<T>::type : retrieve base class of type T registered into QxOrm context and ...
qx::trait::is_qx_registered<T>::value : return true if T is registered into QxOrm context to provide ...
void save(Archive &ar, const T &t, const unsigned int file_version)
void load(Archive &ar, T &t, const unsigned int file_version)
Root namespace for all QxOrm library features.
static void load(Archive &ar, T &t, const unsigned int file_version)
static void save(Archive &ar, const T &t, const unsigned int file_version)
static void save(Archive &ar, const T &t, const unsigned int file_version)
static void load(Archive &ar, T &t, const unsigned int file_version)
static void invoke(Archive &ar, T &t, const unsigned int file_version)
static void invoke(Archive &ar, const T &t, const unsigned int file_version)
qx::trait::is_qx_registered<T>::value : return true if T is registered into QxOrm context to provide ...