Nuria Framework - Core
Core module of the NuriaProject Framework
 All Classes Functions Typedefs Enumerations Enumerator Groups
runtimemetaobject.hpp
1 /* Copyright (c) 2014, The Nuria Project
2  * This software is provided 'as-is', without any express or implied
3  * warranty. In no event will the authors be held liable for any damages
4  * arising from the use of this software.
5  * Permission is granted to anyone to use this software for any purpose,
6  * including commercial applications, and to alter it and redistribute it
7  * freely, subject to the following restrictions:
8  * 1. The origin of this software must not be misrepresented; you must not
9  * claim that you wrote the original software. If you use this software
10  * in a product, an acknowledgment in the product documentation would be
11  * appreciated but is not required.
12  * 2. Altered source versions must be plainly marked as such, and must not be
13  * misrepresented as being the original software.
14  * 3. This notice may not be removed or altered from any source
15  * distribution.
16  */
17 
18 #ifndef NURIA_RUNTIMEMETAOBJECT_HPP
19 #define NURIA_RUNTIMEMETAOBJECT_HPP
20 
21 #include "metaobject.hpp"
22 #include <functional>
23 
24 namespace Nuria {
25 
26 class RuntimeMetaObjectPrivate;
27 
57 class NURIA_CORE_EXPORT RuntimeMetaObject : public MetaObject {
58 public:
59 
63  enum class InvokeAction {
64 
66  Invoke,
67 
69  UnsafeInvoke,
70 
72  ArgumentTest
73  };
74 
76  typedef QMultiMap< QByteArray, QVariant > AnnotationMap;
77 
87  typedef std::function< Callback(void *, InvokeAction) > InvokeCreator;
88 
90  typedef std::function< QVariant(void *) > FieldGetter;
91 
93  typedef std::function< bool(void *, const QVariant &) > FieldSetter;
94 
100  typedef std::function< void(void *) > InstanceDeleter;
101 
103  RuntimeMetaObject (const QByteArray &name);
104 
106  ~RuntimeMetaObject ();
107 
115  void setQtMetaTypeId (int valueTypeId);
116 
124  void setQtMetaTypePointerId (int pointerTypeId);
125 
127  void setAnnotations (const AnnotationMap &annotations);
128 
130  void setBaseClasses (const QVector< QByteArray > &bases);
131 
139  void setInstanceDeleter (InstanceDeleter deleter);
140 
152  void addMethod (MetaMethod::Type type, const QByteArray &name, const QByteArray &returnType,
153  const QVector< QByteArray > &argumentNames, const QVector< QByteArray > &argumentTypes,
154  const AnnotationMap &annotations, InvokeCreator invokeCreator);
155 
159  void addEnum (const QByteArray &name, const AnnotationMap &annotations,
160  const QMap< QByteArray, int > &keyValueMap);
161 
167  void addField (const QByteArray &name, const QByteArray &valueType, const AnnotationMap &annotations,
168  FieldGetter getter, FieldSetter setter);
169 
174  void addField (const QByteArray &name, const QByteArray &valueType, const AnnotationMap &annotations,
175  FieldGetter getter);
176 
182  void finalize ();
183 
184 protected:
185  void gateCall (GateMethod method, int category, int index, int nth, void *result, void *additional) override;
186 
187 private:
188  int runtimeAnnotationCount (int category, int index);
189  QByteArray runtimeAnnotationName (int category, int index, int nth);
190  QVariant runtimeAnnotationValue (int category, int index, int nth);
191 
192  QByteArray runtimeMethodName (int index);
193  MetaMethod::Type runtimeMethodType (int index);
194  QByteArray runtimeMethodReturnType (int index);
195  QVector< QByteArray > runtimeMethodArgumentNames (int index);
196  QVector< QByteArray > runtimeMethodArgumentTypes (int index);
197  Callback runtimeMethodCallback (void *instance, int index);
198  Callback runtimeMethodUnsafeCallback (void *instance, int index);
199  Callback runtimeMethodArgumentTest (void *instance, int index);
200 
201  QByteArray runtimeFieldName (int index);
202  QByteArray runtimeFieldType (int index);
203  QVariant runtimeFieldRead (int index, void *instance);
204  bool runtimeFieldWrite (int index, void *instance, const QVariant &value);
205  MetaField::Access runtimeFieldAccess (int index);
206 
207  QByteArray runtimeEnumName (int index);
208  int runtimeEnumElementCount (int index);
209  QByteArray runtimeEnumElementKey (int index, int nth);
210  int runtimeEnumElementValue (int index, int nth);
211 
212  RuntimeMetaObjectPrivate *d;
213 
214 };
215 
216 }
217 
218 #endif // RUNTIMEMETAOBJECT_HPP
A modern style callback mechanism which can be bound to various method types including slots...
Definition: callback.hpp:141
std::function< bool(void *, const QVariant &) > FieldSetter
Definition: runtimemetaobject.hpp:93
InvokeAction
Definition: runtimemetaobject.hpp:63
Access
Definition: metaobject.hpp:300
Type
Definition: metaobject.hpp:141
GateMethod
Definition: metaobject.hpp:570
std::function< void(void *) > InstanceDeleter
Definition: runtimemetaobject.hpp:100
QMultiMap< QByteArray, QVariant > AnnotationMap
Definition: runtimemetaobject.hpp:76
std::function< Callback(void *, InvokeAction) > InvokeCreator
Definition: runtimemetaobject.hpp:87
The MetaObject class provides access to meta-data of types at run-time.
Definition: metaobject.hpp:563
RuntimeMetaObject lets you easily define types at run-time.
Definition: runtimemetaobject.hpp:57
std::function< QVariant(void *) > FieldGetter
Definition: runtimemetaobject.hpp:90