![]() |
QxOrm 1.1.9
C++ Object Relational Mapping library
|
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_BOOST_SERIALIZE_REGISTER_HELPER_X_H_ 00027 #define _QX_BOOST_SERIALIZE_REGISTER_HELPER_X_H_ 00028 00029 #ifdef _MSC_VER 00030 #pragma once 00031 #endif 00032 00033 #include <QtCore/qmutex.h> 00034 00035 #include <QxCommon/QxConfig.h> 00036 00037 #include <QxSerialize/QxBoostSerializeHelper/IxBoostSerializeRegisterHelper.h> 00038 00039 #include <QxSingleton/QxSingleton.h> 00040 00041 #include <QxCollection/QxCollection.h> 00042 #include <QxCollection/QxForeach.h> 00043 00044 namespace qx { 00045 00046 class QX_DLL_EXPORT QxBoostSerializeRegisterHelperX : public QxSingleton<QxBoostSerializeRegisterHelperX> 00047 { 00048 00049 friend class QxSingleton<QxBoostSerializeRegisterHelperX>; 00050 friend class IxBoostSerializeRegisterHelper; 00051 00052 private: 00053 00054 QxCollection<QString, IxBoostSerializeRegisterHelper *> m_colHelperX; // Collection of all 'IxBoostSerializeRegisterHelper' pointer 00055 QMutex m_oMutexHelperX; // Mutex -> 'QxBoostSerializeRegisterHelperX' is thread-safe 00056 00057 QxBoostSerializeRegisterHelperX() : QxSingleton<QxBoostSerializeRegisterHelperX>("qx::QxBoostSerializeRegisterHelperX") { ; } 00058 virtual ~QxBoostSerializeRegisterHelperX() { ; } 00059 00060 public: 00061 00062 void add(const QString & sKey, IxBoostSerializeRegisterHelper * p); 00063 void remove(const QString & sKey); 00064 00065 template <class Archive> 00066 static inline void helper(Archive & ar) 00067 #if _QX_USE_BOOST_SERIALIZE_REGISTER_HELPER 00068 { QxBoostSerializeRegisterHelperX::getSingleton()->private_helper(ar); } 00069 #else 00070 { Q_UNUSED(ar); } 00071 #endif // _QX_USE_BOOST_SERIALIZE_REGISTER_HELPER 00072 00073 static inline void helper() 00074 #if _QX_USE_BOOST_SERIALIZE_REGISTER_HELPER 00075 { QxBoostSerializeRegisterHelperX::getSingleton()->private_helper(); } 00076 #else 00077 { ; } 00078 #endif // _QX_USE_BOOST_SERIALIZE_REGISTER_HELPER 00079 00080 private: 00081 00082 template <class Archive> 00083 inline void private_helper(Archive & ar) const 00084 { 00085 static bool bDone = false; 00086 if (bDone) { return; } 00087 QMutexLocker locker(const_cast<QMutex *>(& m_oMutexHelperX)); 00088 if (bDone) { return; } 00089 _foreach(IxBoostSerializeRegisterHelper * p, m_colHelperX) { p->helper(ar); } 00090 bDone = true; 00091 } 00092 00093 inline void private_helper() const 00094 { 00095 static bool bDone = false; 00096 if (bDone) { return; } 00097 QMutexLocker locker(const_cast<QMutex *>(& m_oMutexHelperX)); 00098 if (bDone) { return; } 00099 _foreach(IxBoostSerializeRegisterHelper * p, m_colHelperX) { p->helper(); } 00100 bDone = true; 00101 } 00102 00103 }; 00104 00105 } // namespace qx 00106 00107 QX_DLL_EXPORT_QX_SINGLETON_HPP(qx::QxBoostSerializeRegisterHelperX) 00108 00109 #endif // _QX_BOOST_SERIALIZE_REGISTER_HELPER_X_H_