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