QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxBoostSerializeRegisterHelperX.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_BOOST_SERIALIZE_REGISTER_HELPER_X_H_
34#define _QX_BOOST_SERIALIZE_REGISTER_HELPER_X_H_
35
36#ifdef _MSC_VER
37#pragma once
38#endif
39
40#include <QtCore/qmutex.h>
41
42#include <QxCommon/QxConfig.h>
43
45
47
50
51namespace qx {
52
53class QX_DLL_EXPORT QxBoostSerializeRegisterHelperX : public QxSingleton<QxBoostSerializeRegisterHelperX>
54{
55
58
59private:
60
61 QxCollection<QString, IxBoostSerializeRegisterHelper *> m_colHelperX; // Collection of all 'IxBoostSerializeRegisterHelper' pointer
62 QMutex m_oMutexHelperX; // Mutex -> 'QxBoostSerializeRegisterHelperX' is thread-safe
63
64 QxBoostSerializeRegisterHelperX() : QxSingleton<QxBoostSerializeRegisterHelperX>("qx::QxBoostSerializeRegisterHelperX") { ; }
66
67public:
68
69 void add(const QString & sKey, IxBoostSerializeRegisterHelper * p);
70 void remove(const QString & sKey);
71
72 template <class Archive>
73 static inline void helper(Archive & ar)
74#if _QX_USE_BOOST_SERIALIZE_REGISTER_HELPER
75 { QxBoostSerializeRegisterHelperX::getSingleton()->private_helper(ar); }
76#else
77 { Q_UNUSED(ar); }
78#endif // _QX_USE_BOOST_SERIALIZE_REGISTER_HELPER
79
80 static inline void helper()
81#if _QX_USE_BOOST_SERIALIZE_REGISTER_HELPER
82 { QxBoostSerializeRegisterHelperX::getSingleton()->private_helper(); }
83#else
84 { ; }
85#endif // _QX_USE_BOOST_SERIALIZE_REGISTER_HELPER
86
87private:
88
89 template <class Archive>
90 inline void private_helper(Archive & ar) const
91 {
92 static bool bDone = false;
93 if (bDone) { return; }
94 QMutexLocker locker(const_cast<QMutex *>(& m_oMutexHelperX));
95 if (bDone) { return; }
96 _foreach(IxBoostSerializeRegisterHelper * p, m_colHelperX) { p->helper(ar); }
97 bDone = true;
98 }
99
100 inline void private_helper() const
101 {
102 static bool bDone = false;
103 if (bDone) { return; }
104 QMutexLocker locker(const_cast<QMutex *>(& m_oMutexHelperX));
105 if (bDone) { return; }
106 _foreach(IxBoostSerializeRegisterHelper * p, m_colHelperX) { p->helper(); }
107 bDone = true;
108 }
109
110};
111
112} // namespace qx
113
115
116#endif // _QX_BOOST_SERIALIZE_REGISTER_HELPER_X_H_
117#endif // _QX_ENABLE_BOOST_SERIALIZATION
QxOrm thread-safe container (keep insertion order + quick access by index + quick access by key)
List of parameters to compile and build QxOrm library.
foreach-style (based on BOOST_FOREACH macro) to iterate over all stl, boost and Qt containers + qx::Q...
#define _foreach
Definition QxForeach.h:165
#define QX_DLL_EXPORT
Definition QxMacro.h:182
#define QX_DLL_EXPORT_QX_SINGLETON_HPP(x)
Definition QxMacro.h:190
Concrete class to define a thread-safe singleton of QxOrm library.
virtual void helper() const =0
void add(const QString &sKey, IxBoostSerializeRegisterHelper *p)
void remove(const QString &sKey)
QxCollection< QString, IxBoostSerializeRegisterHelper * > m_colHelperX
qx::QxCollection<Key, Value> : QxOrm thread-safe container (keep insertion order + quick access by in...
qx::QxSingleton<T> : concrete class to define a thread-safe singleton of type T
Definition QxSingleton.h:59
Root namespace for all QxOrm library features.