QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxClassX.h
Go to the documentation of this file.
1/****************************************************************************
2**
3** https://www.qxorm.com/
4** Copyright (C) 2013 Lionel Marty (contact@qxorm.com)
5**
6** This file is part of the QxOrm library
7**
8** This software is provided 'as-is', without any express or implied
9** warranty. In no event will the authors be held liable for any
10** damages arising from the use of this software
11**
12** Commercial Usage
13** Licensees holding valid commercial QxOrm licenses may use this file in
14** accordance with the commercial license agreement provided with the
15** Software or, alternatively, in accordance with the terms contained in
16** a written agreement between you and Lionel Marty
17**
18** GNU General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU
20** General Public License version 3.0 as published by the Free Software
21** Foundation and appearing in the file 'license.gpl3.txt' included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU General Public License version 3.0 requirements will be
24** met : http://www.gnu.org/copyleft/gpl.html
25**
26** If you are unsure which license is appropriate for your use, or
27** if you have questions regarding the use of this file, please contact :
28** contact@qxorm.com
29**
30****************************************************************************/
31
32#ifndef _QX_CLASS_X_H_
33#define _QX_CLASS_X_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
46#include <QxCommon/QxBool.h>
47
48#include <QxRegister/IxClass.h>
49
51
53
56
57namespace qx {
58
63class QX_DLL_EXPORT QxClassX : public QxSingleton<QxClassX>
64{
65
66 friend class QxSingleton<QxClassX>;
67 friend class IxClass;
68
69public:
70
72 typedef std::function<QString (const QVariant &, int, const unsigned int)> type_fct_save_qvariant_usertype;
73 typedef std::function<QVariant (const QString &, int, const unsigned int)> type_fct_load_qvariant_usertype;
74
75protected:
76
78 QHash<QString, QString> m_lstSqlTypeByClassName;
79 QHash<QString, QString> m_lstValidatorMessage;
82
83private:
84
86 virtual ~QxClassX();
87
89 IxClass * get(const QString & sKey) const;
90 bool exist(const QString & sKey) const;
91 bool insert(const QString & sKey, IxClass * pClass);
92 bool remove(const QString & sKey);
93 void clear();
96
97#ifndef _QX_NO_RTTI
98 const std::type_info & typeInfo(const QString & sKey) const;
99#endif // _QX_NO_RTTI
100
101public:
102
103 static qx::any create(const QString & sKey);
104 static IxClass * getClass(const QString & sKey);
105 static IxDataMemberX * getDataMemberX(const QString & sKey);
106 static IxFunctionX * getFctMemberX(const QString & sKey);
107 static IxFunctionX * getFctStaticX(const QString & sKey);
108 static IxDataMember * getDataMember(const QString & sClassKey, const QString & sDataKey, bool bRecursive = true);
109 static IxFunction * getFctMember(const QString & sClassKey, const QString & sFctKey, bool bRecursive = true);
110 static IxFunction * getFctStatic(const QString & sClassKey, const QString & sFctKey, bool bRecursive = true);
111 static bool implementIxPersistable(const QString & sKey, bool bTraceIfFalse = true);
112
114 static void registerAllClasses(bool bInitAllRelations = true, bool bInitValidator = true);
115 static QString dumpAllClasses();
116 static QString dumpSqlSchema();
117
118 static QHash<QString, QString> * getAllValidatorMessage() { return (& QxClassX::getSingleton()->m_lstValidatorMessage); }
119 static QHash<QString, QString> * getAllSqlTypeByClassName() { return (& QxClassX::getSingleton()->m_lstSqlTypeByClassName); }
120 static QString getSqlTypeByClassName(const QString & sClassName) { return QxClassX::getAllSqlTypeByClassName()->value(sClassName); }
121
122#ifndef _QX_NO_RTTI
123 static const std::type_info & getTypeInfo(const QString & sClassName) { return QxClassX::getSingleton()->typeInfo(sClassName); }
124#endif // _QX_NO_RTTI
125
126 static type_fct_save_qvariant_usertype getFctSaveQVariantUserType() { return QxClassX::getSingleton()->m_fctSaveQVariantUserType; }
127 static type_fct_load_qvariant_usertype getFctLoadQVariantUserType() { return QxClassX::getSingleton()->m_fctLoadQVariantUserType; }
128 static void setFctSaveQVariantUserType(type_fct_save_qvariant_usertype fct) { QxClassX::getSingleton()->m_fctSaveQVariantUserType = fct; }
129 static void setFctLoadQVariantUserType(type_fct_load_qvariant_usertype fct) { QxClassX::getSingleton()->m_fctLoadQVariantUserType = fct; }
130
131 template <class U>
132 static inline qx_bool invoke(const QString & sClassKey, const QString & sFctKey, U & pOwner, const QString & params = QString(), qx::any * ret = NULL)
133 {
134 typedef typename std::conditional< std::is_pointer<U>::value, QxClassX::invoke_ptr<U>, QxClassX::invoke_default<U> >::type type_invoke_1;
135 typedef typename std::conditional< qx::trait::is_smart_ptr<U>::value, QxClassX::invoke_ptr<U>, type_invoke_1 >::type type_invoke_2;
136 return type_invoke_2::invoke(sClassKey, sFctKey, pOwner, params, ret);
137 }
138
139 template <class U>
140 static inline qx_bool invoke(const QString & sClassKey, const QString & sFctKey, U & pOwner, const type_any_params & params, qx::any * ret = NULL)
141 {
142 typedef typename std::conditional< std::is_pointer<U>::value, QxClassX::invoke_ptr<U>, QxClassX::invoke_default<U> >::type type_invoke_1;
143 typedef typename std::conditional< qx::trait::is_smart_ptr<U>::value, QxClassX::invoke_ptr<U>, type_invoke_1 >::type type_invoke_2;
144 return type_invoke_2::invoke(sClassKey, sFctKey, pOwner, params, ret);
145 }
146
147 static qx_bool invokeStatic(const QString & sClassKey, const QString & sFctKey, const QString & params = QString(), qx::any * ret = NULL);
148 static qx_bool invokeStatic(const QString & sClassKey, const QString & sFctKey, const type_any_params & params, qx::any * ret = NULL);
149
150private:
151
152 template <class U>
154 {
155 static inline qx_bool invoke(const QString & sClassKey, const QString & sFctKey, U & pOwner, const QString & params = QString(), qx::any * ret = NULL)
156 { return QxClassX::invokeVoidPtr(sClassKey, sFctKey, static_cast<void *>(& (* pOwner)), params, ret); }
157 static inline qx_bool invoke(const QString & sClassKey, const QString & sFctKey, U & pOwner, const type_any_params & params, qx::any * ret = NULL)
158 { return QxClassX::invokeVoidPtr(sClassKey, sFctKey, static_cast<void *>(& (* pOwner)), params, ret); }
159 };
160
161 template <class U>
163 {
164 static inline qx_bool invoke(const QString & sClassKey, const QString & sFctKey, U & pOwner, const QString & params = QString(), qx::any * ret = NULL)
165 { return QxClassX::invokeVoidPtr(sClassKey, sFctKey, static_cast<void *>(& pOwner), params, ret); }
166 static inline qx_bool invoke(const QString & sClassKey, const QString & sFctKey, U & pOwner, const type_any_params & params, qx::any * ret = NULL)
167 { return QxClassX::invokeVoidPtr(sClassKey, sFctKey, static_cast<void *>(& pOwner), params, ret); }
168 };
169
170 static qx_bool invokeVoidPtr(const QString & sClassKey, const QString & sFctKey, void * pOwner, const QString & params = QString(), qx::any * ret = NULL);
171 static qx_bool invokeVoidPtr(const QString & sClassKey, const QString & sFctKey, void * pOwner, const type_any_params & params, qx::any * ret = NULL);
172
175
176};
177
178} // namespace qx
179
181
182#endif // _QX_CLASS_X_H_
Common interface for all classes registered into QxOrm context.
qx_bool : QxOrm library boolean type with code and description message when an error occured
QxOrm thread-safe container (keep insertion order + quick access by index + quick access by key)
#define QX_DLL_EXPORT
Definition QxMacro.h:182
#define QX_DLL_EXPORT_QX_SINGLETON_HPP(x)
Definition QxMacro.h:190
Concrete class to define a thread-safe singleton of QxOrm library.
qx::IxClass : common interface for all classes registered into QxOrm context
Definition IxClass.h:69
qx::IxDataMember : common interface for all class properties registered into QxOrm context
qx::IxDataMemberX : common interface for a list of IxDataMember class properties registered into QxOr...
qx::IxFunction : common interface for all functions registered into QxOrm context (used by introspect...
Definition IxFunction.h:64
std::vector< qx::any > type_any_params
Definition IxFunction.h:74
qx_bool : boolean type with code and description message when an error occured
Definition QxBool.h:71
qx::QxClassX : list of all classes registered into QxOrm context (this container is a singleton)
Definition QxClassX.h:64
static IxDataMember * getDataMember(const QString &sClassKey, const QString &sDataKey, bool bRecursive=true)
static qx_bool invokeVoidPtr(const QString &sClassKey, const QString &sFctKey, void *pOwner, const QString &params=QString(), qx::any *ret=NULL)
const std::type_info & typeInfo(const QString &sKey) const
void initValidatorMessage()
bool exist(const QString &sKey) const
static QString getSqlTypeByClassName(const QString &sClassName)
Definition QxClassX.h:120
static void setFctLoadQVariantUserType(type_fct_load_qvariant_usertype fct)
Definition QxClassX.h:129
static QHash< QString, QString > * getAllSqlTypeByClassName()
Definition QxClassX.h:119
QHash< QString, QString > m_lstValidatorMessage
List of validator message when an invalid value is detected.
Definition QxClassX.h:79
static qx_bool invokeVoidPtr(const QString &sClassKey, const QString &sFctKey, void *pOwner, const type_any_params &params, qx::any *ret=NULL)
static IxFunctionX * getFctStaticX(const QString &sKey)
std::function< QString(const QVariant &, int, const unsigned int)> type_fct_save_qvariant_usertype
Definition QxClassX.h:72
QxCollection< QString, IxClass * > m_lstClass
Collection of classes registered into QxOrm context.
Definition QxClassX.h:77
static bool isValid_DataMember(IxDataMember *p)
QxCollection< QString, IxClass * > * getAll()
static type_fct_save_qvariant_usertype getFctSaveQVariantUserType()
Definition QxClassX.h:126
void initSqlTypeByClassName()
static qx_bool invokeStatic(const QString &sClassKey, const QString &sFctKey, const QString &params=QString(), qx::any *ret=NULL)
static QxCollection< QString, IxClass * > * getAllClasses()
static QString dumpSqlSchema()
static IxFunction * getFctStatic(const QString &sClassKey, const QString &sFctKey, bool bRecursive=true)
type_fct_save_qvariant_usertype m_fctSaveQVariantUserType
Serialization of QVariant UserType => function to save a QVariant UserType (cf. QxSerialize_QVariant....
Definition QxClassX.h:80
IxFunction::type_any_params type_any_params
Definition QxClassX.h:71
static const std::type_info & getTypeInfo(const QString &sClassName)
Definition QxClassX.h:123
IxClass * get(const QString &sKey) const
static IxFunctionX * getFctMemberX(const QString &sKey)
static QHash< QString, QString > * getAllValidatorMessage()
Definition QxClassX.h:118
static qx::any create(const QString &sKey)
static qx_bool invokeStatic(const QString &sClassKey, const QString &sFctKey, const type_any_params &params, qx::any *ret=NULL)
virtual ~QxClassX()
static void registerAllClasses(bool bInitAllRelations=true, bool bInitValidator=true)
static IxFunction * getFctMember(const QString &sClassKey, const QString &sFctKey, bool bRecursive=true)
static qx_bool invoke(const QString &sClassKey, const QString &sFctKey, U &pOwner, const QString &params=QString(), qx::any *ret=NULL)
Definition QxClassX.h:132
static QString dumpAllClasses()
static void setFctSaveQVariantUserType(type_fct_save_qvariant_usertype fct)
Definition QxClassX.h:128
std::function< QVariant(const QString &, int, const unsigned int)> type_fct_load_qvariant_usertype
Definition QxClassX.h:73
bool insert(const QString &sKey, IxClass *pClass)
static qx_bool invoke(const QString &sClassKey, const QString &sFctKey, U &pOwner, const type_any_params &params, qx::any *ret=NULL)
Definition QxClassX.h:140
static IxClass * getClass(const QString &sKey)
QHash< QString, QString > m_lstSqlTypeByClassName
List of SQL types by class name.
Definition QxClassX.h:78
static IxDataMemberX * getDataMemberX(const QString &sKey)
bool remove(const QString &sKey)
static bool isValid_SqlRelation(IxDataMember *p)
static bool implementIxPersistable(const QString &sKey, bool bTraceIfFalse=true)
type_fct_load_qvariant_usertype m_fctLoadQVariantUserType
Serialization of QVariant UserType => function to load a QVariant UserType (cf. QxSerialize_QVariant....
Definition QxClassX.h:81
static type_fct_load_qvariant_usertype getFctLoadQVariantUserType()
Definition QxClassX.h:127
qx::QxCollection<Key, Value> : QxOrm thread-safe container (keep insertion order + quick access by in...
qx::QxSingleton<T> : concrete class to define a thread-safe singleton of type T
Definition QxSingleton.h:59
qx::trait::get_sql_type<T>::get() : return type name under const char * format used by database engin...
qx::trait::is_smart_ptr<T>::value : return true if T is a smart-pointer of boost, Qt or QxOrm librari...
Root namespace for all QxOrm library features.
static qx_bool invoke(const QString &sClassKey, const QString &sFctKey, U &pOwner, const QString &params=QString(), qx::any *ret=NULL)
Definition QxClassX.h:164
static qx_bool invoke(const QString &sClassKey, const QString &sFctKey, U &pOwner, const type_any_params &params, qx::any *ret=NULL)
Definition QxClassX.h:166
static qx_bool invoke(const QString &sClassKey, const QString &sFctKey, U &pOwner, const QString &params=QString(), qx::any *ret=NULL)
Definition QxClassX.h:155
static qx_bool invoke(const QString &sClassKey, const QString &sFctKey, U &pOwner, const type_any_params &params, qx::any *ret=NULL)
Definition QxClassX.h:157