| QxOrm 1.1.6 C++ Object Relational Mapping library

- Main Page
- Modules
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

QxClass.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_H_
    00027 #define _QX_CLASS_H_
    00028
    00029 #ifdef _MSC_VER
    00030 #pragma once
    00031 #endif
    00032
    00040 #include <boost/static_assert.hpp>
    00041 #include <boost/type_traits/is_same.hpp>
    00042 #include <boost/type_traits/is_base_of.hpp>
    00043 #include <boost/serialization/version.hpp>
    00044
    00045 #include <QxRegister/IxClass.h>
    00046
    00047 #include <QxDataMember/QxDataMemberX.h>
    00048
    00049 #include <QxFunction/QxFunctionInclude.h>
    00050
    00051 #include <QxSingleton/QxSingleton.h>
    00052
    00053 #include <QxTraits/get_class_name.h>
    00054 #include <QxTraits/get_base_class.h>
    00055 #include <QxTraits/get_primary_key.h>
    00056
    00057 namespace qx {
    00058
    00063 template <class T>
    00064 void register_class(T & t) { Q_UNUSED(t); qAssert(false); };
    00065
    00070 template <class T>
    00071 class QxClass : public IxClass, public QxSingleton< QxClass<T> >
    00072 {
    00073
    00074    friend class QxSingleton< QxClass<T> >;
    00075
    00076 public:
    00077
    00078    typedef typename qx::trait::get_primary_key<T>::type type_primary_key;
    00079    typedef typename qx::trait::get_base_class<T>::type type_base_class;
    00080    typedef IxFunction::type_any_params type_any_params;
    00081
    00082    enum { is_valid_base_class = ((! boost::is_same<type_base_class, T>::value) && (boost::is_base_of<type_base_class, T>::value || boost::is_same<type_base_class, qx::trait::no_base_class_defined>::value)) };
    00083
    00084 protected:
    00085
    00086    QMutex m_oMutexClass;
    00087
    00088 protected:
    00089
    00090    QxClass() : IxClass(), QxSingleton< QxClass<T> >(QString("qx::QxClass_") + qx::trait::get_class_name<T>::get_xml_tag()) { init(); }
    00091    virtual ~QxClass() { ; }
    00092
    00093 public:
    00094
    00095    inline QxDataMemberX<T> * dataMemberX() const   { return static_cast<QxDataMemberX<T> *>(m_pDataMemberX); }
    00096    inline IxFunctionX * fctMemberX() const         { return m_pFctMemberX.get(); }
    00097
    00098    IxDataMember * id(type_primary_key T::* pDataMemberId, const QString & sKey);
    00099    IxDataMember * id(type_primary_key T::* pDataMemberId, const QString & sKey, long lVersion);
    00100
    00101    template <typename V, typename U> IxDataMember * data(V U::* pData, const QString & sKey);
    00102    template <typename V, typename U> IxDataMember * data(V U::* pData, const QString & sKey, long lVersion);
    00103    template <typename V, typename U> IxDataMember * data(V U::* pData, const QString & sKey, long lVersion, bool bSerialize);
    00104    template <typename V, typename U> IxDataMember * data(V U::* pData, const QString & sKey, long lVersion, bool bSerialize, bool bDao);
    00105
    00106    template <typename V, typename U> IxSqlRelation * relationOneToOne(V U::* pData, const QString & sKey);
    00107    template <typename V, typename U> IxSqlRelation * relationOneToOne(V U::* pData, const QString & sKey, long lVersion);
    00108    template <typename V, typename U> IxSqlRelation * relationManyToOne(V U::* pData, const QString & sKey);
    00109    template <typename V, typename U> IxSqlRelation * relationManyToOne(V U::* pData, const QString & sKey, long lVersion);
    00110    template <typename V, typename U> IxSqlRelation * relationOneToMany(V U::* pData, const QString & sKey, const QString & sForeignKey);
    00111    template <typename V, typename U> IxSqlRelation * relationOneToMany(V U::* pData, const QString & sKey, const QString & sForeignKey, long lVersion);
    00112    template <typename V, typename U> IxSqlRelation * relationManyToMany(V U::* pData, const QString & sKey, const QString & sExtraTable, const QString & sForeignKeyOwner, const QString & sForeignKeyDataType);
    00113    template <typename V, typename U> IxSqlRelation * relationManyToMany(V U::* pData, const QString & sKey, const QString & sExtraTable, const QString & sForeignKeyOwner, const QString & sForeignKeyDataType, long lVersion);
    00114
    00115    template <typename R> IxFunction * fct_0(const typename QxFunction_0<T, R>::type_fct & fct, const QString & sKey);
    00116    template <typename R, typename P1> IxFunction * fct_1(const typename QxFunction_1<T, R, P1>::type_fct & fct, const QString & sKey);
    00117    template <typename R, typename P1, typename P2> IxFunction * fct_2(const typename QxFunction_2<T, R, P1, P2>::type_fct & fct, const QString & sKey);
    00118    template <typename R, typename P1, typename P2, typename P3> IxFunction * fct_3(const typename QxFunction_3<T, R, P1, P2, P3>::type_fct & fct, const QString & sKey);
    00119    template <typename R, typename P1, typename P2, typename P3, typename P4> IxFunction * fct_4(const typename QxFunction_4<T, R, P1, P2, P3, P4>::type_fct & fct, const QString & sKey);
    00120    template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5> IxFunction * fct_5(const typename QxFunction_5<T, R, P1, P2, P3, P4, P5>::type_fct & fct, const QString & sKey);
    00121    template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6> IxFunction * fct_6(const typename QxFunction_6<T, R, P1, P2, P3, P4, P5, P6>::type_fct & fct, const QString & sKey);
    00122    template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7> IxFunction * fct_7(const typename QxFunction_7<T, R, P1, P2, P3, P4, P5, P6, P7>::type_fct & fct, const QString & sKey);
    00123    template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8> IxFunction * fct_8(const typename QxFunction_8<T, R, P1, P2, P3, P4, P5, P6, P7, P8>::type_fct & fct, const QString & sKey);
    00124    template <typename R, typename P1, typename P2, typename P3, typename P4, typename P5, typename P6, typename P7, typename P8, typename P9> IxFunction * fct_9(const typename QxFunction_9<T, R, P1, P2, P3, P4, P5, P6, P7, P8, P9>::type_fct & fct, const QString & sKey);
    00125
    00126    static qx_bool invoke(const QString & sKey, T * pOwner, const QString & params = QString(), boost::any * ret = NULL) { return QxClass<T>::getSingleton()->invokeHelper(sKey, pOwner, params, ret); }
    00127    static qx_bool invoke(const QString & sKey, T * pOwner, const type_any_params & params, boost::any * ret = NULL)     { return QxClass<T>::getSingleton()->invokeHelper(sKey, pOwner, params, ret); }
    00128
    00129 private:
    00130
    00131    void init();
    00132    IxFunction * insertFct(IxFunction_ptr pFct, const QString & sKey);
    00133
    00134    void registerClass() { qx::register_class(* this); }
    00135
    00136    void beforeRegisterClass()
    00137    {
    00138       BOOST_STATIC_ASSERT(is_valid_base_class);
    00139       QMutexLocker locker(& m_oMutexClass);
    00140       QxClass<type_base_class>::getSingleton();
    00141       bool bNeedReg = (m_pDataMemberX && (m_pDataMemberX->count() <= 0));
    00142       bNeedReg = (bNeedReg && m_pFctMemberX && (m_pFctMemberX->count() <= 0));
    00143       if (bNeedReg) { registerClass(); }
    00144    }
    00145
    00146    qx_bool invokeHelper(const QString & sKey, T * pOwner, const QString & params, boost::any * ret)
    00147    { return ((pOwner && m_pFctMemberX && m_pFctMemberX->exist(sKey)) ? m_pFctMemberX->getByKey(sKey)->invoke(pOwner, params, ret) : QxClass<type_base_class>::invoke(sKey, dynamic_cast<type_base_class *>(pOwner), params, ret)); }
    00148
    00149    qx_bool invokeHelper(const QString & sKey, T * pOwner, const type_any_params & params, boost::any * ret)
    00150    { return ((pOwner && m_pFctMemberX && m_pFctMemberX->exist(sKey)) ? m_pFctMemberX->getByKey(sKey)->invoke(pOwner, params, ret) : QxClass<type_base_class>::invoke(sKey, dynamic_cast<type_base_class *>(pOwner), params, ret)); }
    00151
    00152 };
    00153
    00154 } // namespace qx
    00155
    00156 #include "../../inl/QxRegister/QxClass.inl"
    00157
    00158 #endif // _QX_CLASS_H_

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines