QxOrm 1.1.9
C++ Object Relational Mapping library
QxClassX.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_CLASS_X_H_
00027 #define _QX_CLASS_X_H_
00028 
00029 #ifdef _MSC_VER
00030 #pragma once
00031 #endif
00032 
00040 #include <boost/mpl/if.hpp>
00041 #include <boost/mpl/or.hpp>
00042 #include <boost/mpl/logical.hpp>
00043 #include <boost/type_traits/is_pointer.hpp>
00044 
00045 #include <QxCommon/QxBool.h>
00046 
00047 #include <QxRegister/IxClass.h>
00048 
00049 #include <QxSingleton/QxSingleton.h>
00050 
00051 #include <QxCollection/QxCollection.h>
00052 
00053 #include <QxTraits/is_smart_ptr.h>
00054 #include <QxTraits/get_sql_type.h>
00055 
00056 namespace qx {
00057 
00062 class QX_DLL_EXPORT QxClassX : public QxSingleton<QxClassX>
00063 {
00064 
00065    friend class QxSingleton<QxClassX>;
00066    friend class IxClass;
00067 
00068 public:
00069 
00070    typedef IxFunction::type_any_params type_any_params;
00071 
00072 protected:
00073 
00074    QxCollection<QString, IxClass *> m_lstClass;
00075    QHash<QString, QString> m_lstSqlTypeByClassName;
00076 
00077 private:
00078 
00079    QxClassX() : QxSingleton<QxClassX>("qx::QxClassX") { this->initSqlTypeByClassName(); }
00080    virtual ~QxClassX() { ; }
00081 
00082    QxCollection<QString, IxClass *> * getAll();
00083    IxClass * get(const QString & sKey) const;
00084    bool exist(const QString & sKey) const;
00085    bool insert(const QString & sKey, IxClass * pClass);
00086    bool remove(const QString & sKey);
00087    void clear();
00088    void initSqlTypeByClassName();
00089 
00090 public:
00091 
00092    static boost::any create(const QString & sKey);
00093    static IxClass * getClass(const QString & sKey);
00094    static IxDataMemberX * getDataMemberX(const QString & sKey);
00095    static IxFunctionX * getFctMemberX(const QString & sKey);
00096    static IxDataMember * getDataMember(const QString & sClassKey, const QString & sDataKey, bool bRecursive = true);
00097    static IxFunction * getFctMember(const QString & sClassKey, const QString & sFctKey, bool bRecursive = true);
00098 
00099    static QxCollection<QString, IxClass *> * getAllClasses();
00100    static void registerAllClasses();
00101    static QString dumpAllClasses();
00102    static QString dumpSqlSchema();
00103 
00104    static QHash<QString, QString> * getAllSqlTypeByClassName()       { return (& QxClassX::getSingleton()->m_lstSqlTypeByClassName); }
00105    static QString getSqlTypeByClassName(const QString & sClassName)  { return (QxClassX::getAllSqlTypeByClassName()->value(sClassName)); }
00106 
00107    template <class U>
00108    static inline qx_bool invoke(const QString & sClassKey, const QString & sFctKey, U & pOwner, const QString & params = QString(), boost::any * ret = NULL)
00109    {
00110       typedef typename boost::mpl::if_c< boost::is_pointer<U>::value, QxClassX::invoke_ptr<U>, QxClassX::invoke_default<U> >::type type_invoke_1;
00111       typedef typename boost::mpl::if_c< qx::trait::is_smart_ptr<U>::value, QxClassX::invoke_ptr<U>, type_invoke_1 >::type type_invoke_2;
00112       return type_invoke_2::invoke(sClassKey, sFctKey, pOwner, params, ret);
00113    }
00114 
00115    template <class U>
00116    static inline qx_bool invoke(const QString & sClassKey, const QString & sFctKey, U & pOwner, const type_any_params & params, boost::any * ret = NULL)
00117    {
00118       typedef typename boost::mpl::if_c< boost::is_pointer<U>::value, QxClassX::invoke_ptr<U>, QxClassX::invoke_default<U> >::type type_invoke_1;
00119       typedef typename boost::mpl::if_c< qx::trait::is_smart_ptr<U>::value, QxClassX::invoke_ptr<U>, type_invoke_1 >::type type_invoke_2;
00120       return type_invoke_2::invoke(sClassKey, sFctKey, pOwner, params, ret);
00121    }
00122 
00123 private:
00124 
00125    template <class U>
00126    struct invoke_ptr
00127    {
00128       static inline qx_bool invoke(const QString & sClassKey, const QString & sFctKey, U & pOwner, const QString & params = QString(), boost::any * ret = NULL)
00129       { return QxClassX::invokeVoidPtr(sClassKey, sFctKey, static_cast<void *>(& (* pOwner)), params, ret); }
00130       static inline qx_bool invoke(const QString & sClassKey, const QString & sFctKey, U & pOwner, const type_any_params & params, boost::any * ret = NULL)
00131       { return QxClassX::invokeVoidPtr(sClassKey, sFctKey, static_cast<void *>(& (* pOwner)), params, ret); }
00132    };
00133 
00134    template <class U>
00135    struct invoke_default
00136    {
00137       static inline qx_bool invoke(const QString & sClassKey, const QString & sFctKey, U & pOwner, const QString & params = QString(), boost::any * ret = NULL)
00138       { return QxClassX::invokeVoidPtr(sClassKey, sFctKey, static_cast<void *>(& pOwner), params, ret); }
00139       static inline qx_bool invoke(const QString & sClassKey, const QString & sFctKey, U & pOwner, const type_any_params & params, boost::any * ret = NULL)
00140       { return QxClassX::invokeVoidPtr(sClassKey, sFctKey, static_cast<void *>(& pOwner), params, ret); }
00141    };
00142 
00143    static qx_bool invokeVoidPtr(const QString & sClassKey, const QString & sFctKey, void * pOwner, const QString & params = QString(), boost::any * ret = NULL);
00144    static qx_bool invokeVoidPtr(const QString & sClassKey, const QString & sFctKey, void * pOwner, const type_any_params & params, boost::any * ret = NULL);
00145 
00146    static bool isValid_DataMember(IxDataMember * p);
00147    static bool isValid_SqlRelation(IxDataMember * p);
00148 
00149 };
00150 
00151 } // namespace qx
00152 
00153 QX_DLL_EXPORT_QX_SINGLETON_HPP(qx::QxClassX)
00154 
00155 #endif // _QX_CLASS_X_H_
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines