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