QxOrm 1.4.9
C++ Object Relational Mapping library
Loading...
Searching...
No Matches
QxFactoryX.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_FACTORY_X_H_
33#define _QX_FACTORY_X_H_
34
35#ifdef _MSC_VER
36#pragma once
37#endif
38
46#include <QtCore/qhash.h>
47#include <QtCore/qmutex.h>
48
49#include <QxFactory/IxFactory.h>
50
52
53namespace qx {
54
55inline qx::any create(const QString & sKey, bool bRawPointer = false);
56template <typename T> inline T * create_nude_ptr(const QString & sKey);
57inline void * create_void_ptr(const QString & sKey);
58
59class QxClassX;
60
65class QX_DLL_EXPORT QxFactoryX : public QxSingleton<QxFactoryX>
66{
67
68 friend class QxClassX;
69 friend class IxFactory;
70 friend class QxSingleton<QxFactoryX>;
71 friend inline qx::any create(const QString & sKey, bool bRawPointer);
72 template <typename T> friend inline T * create_nude_ptr(const QString & sKey);
73 friend inline void * create_void_ptr(const QString & sKey);
74
75protected:
76
77 QHash<QString, IxFactory *> m_mapFactoryX;
79
80private:
81
82 QxFactoryX() : QxSingleton<QxFactoryX>("qx::QxFactoryX") { ; }
83 virtual ~QxFactoryX() { ; }
84
85 QHash<QString, IxFactory *> * getAllFactory() { return (& m_mapFactoryX); }
86
87 void registerFactory(const QString & sKey, IxFactory * pFactory);
88 void unregisterFactory(const QString & sKey);
89
90 qx::any createObject(const QString & sKey, bool bRawPointer = false) const;
91 void * createObjectNudePtr(const QString & sKey) const;
92
93#ifndef _QX_NO_RTTI
94 const std::type_info & typeInfo(const QString & sKey) const;
95#endif // _QX_NO_RTTI
96
97 static inline qx::any createInstance(const QString & sKey, bool bRawPointer = false) { return QxFactoryX::getSingleton()->createObject(sKey, bRawPointer); }
98 static inline void * createInstanceNudePtr(const QString & sKey) { return QxFactoryX::getSingleton()->createObjectNudePtr(sKey); }
99
100#ifndef _QX_NO_RTTI
101 static inline const std::type_info & getTypeInfo(const QString & sKey) { return QxFactoryX::getSingleton()->typeInfo(sKey); }
102#endif // _QX_NO_RTTI
103
104};
105
110inline qx::any create(const QString & sKey, bool bRawPointer /* = false */)
111{ return qx::QxFactoryX::createInstance(sKey, bRawPointer); }
112
117template <typename T>
118inline T * create_nude_ptr(const QString & sKey)
119#ifdef _QX_NO_RTTI
120{ return static_cast<T *>(qx::QxFactoryX::createInstanceNudePtr(sKey)); }
121#else // _QX_NO_RTTI
122{ return dynamic_cast<T *>(static_cast<T *>(qx::QxFactoryX::createInstanceNudePtr(sKey))); }
123#endif // _QX_NO_RTTI
124
129inline void * create_void_ptr(const QString & sKey)
131
132} // namespace qx
133
135
136#endif // _QX_FACTORY_X_H_
Common interface for all classes that can be created dynamically using the class name.
#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::IxFactory : common interface for all classes that can be created dynamically using the class name
Definition IxFactory.h:59
qx::QxClassX : list of all classes registered into QxOrm context (this container is a singleton)
Definition QxClassX.h:64
qx::QxFactoryX : list of all classes registered with QxOrm library factory pattern to create object i...
Definition QxFactoryX.h:66
void * createObjectNudePtr(const QString &sKey) const
qx::any createObject(const QString &sKey, bool bRawPointer=false) const
QMutex m_oMutexFactoryX
Mutex -> 'QxFactoryX' is thread-safe.
Definition QxFactoryX.h:78
void unregisterFactory(const QString &sKey)
void registerFactory(const QString &sKey, IxFactory *pFactory)
static const std::type_info & getTypeInfo(const QString &sKey)
Definition QxFactoryX.h:101
virtual ~QxFactoryX()
Definition QxFactoryX.h:83
static void * createInstanceNudePtr(const QString &sKey)
Definition QxFactoryX.h:98
static qx::any createInstance(const QString &sKey, bool bRawPointer=false)
Definition QxFactoryX.h:97
const std::type_info & typeInfo(const QString &sKey) const
QHash< QString, IxFactory * > m_mapFactoryX
Collection of all 'IxFactory' pointer.
Definition QxFactoryX.h:77
QHash< QString, IxFactory * > * getAllFactory()
Definition QxFactoryX.h:85
qx::QxSingleton<T> : concrete class to define a thread-safe singleton of type T
Definition QxSingleton.h:59
T * create_nude_ptr(const QString &sKey)
Return a nude pointer (be careful with memory leak) of type T associated by key sKey,...
Definition QxFactoryX.h:118
qx::any create(const QString &sKey, bool bRawPointer=false)
Return a smart-pointer new instance of object (std::shared_ptr<T>) associated by key sKey using qx::a...
Definition QxFactoryX.h:110
void * create_void_ptr(const QString &sKey)
Return a void * pointer (be careful with memory leak) associated by key sKey, or return NULL if sKey ...
Definition QxFactoryX.h:129
Root namespace for all QxOrm library features.