itom  4.1.0
pythonItomMetaObject.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2020, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 #ifndef PYTHONITOMMETAOBJECT_H
24 #define PYTHONITOMMETAOBJECT_H
25 
26 #include "../global.h"
27 
28 #include <qbytearray.h>
29 #include <qmetaobject.h>
30 
31 namespace ito
32 {
33 
35  {
36  PythonQObjectMarshal() : m_objectID(0), m_object(NULL) {}
37 
38  PythonQObjectMarshal(QByteArray objName, const char* className, QObject *object) :
39  m_objName(objName),
40  m_objectID(0),
41  m_object(object)
42  {
43  m_className = QByteArray(className);
44  }
45 
46  PythonQObjectMarshal(QObject *obj) :
47  m_objName(obj->objectName().toLatin1()),
48  m_objectID(0),
49  m_object(obj)
50  {
51  m_className = QByteArray(obj->metaObject()->className());
52  }
53 
54  QByteArray m_objName;
55  QByteArray m_className;
56  unsigned int m_objectID;
57  QObject *m_object; //casted from QObject
58  };
59 
60 
61 
62 // MethodDescription
64 {
65 public:
68  QByteArray &name,
69  QByteArray &signature,
70  QMetaMethod::MethodType type,
71  QMetaMethod::Access access,
72  int methodIndex,
73  int retType,
74  int nrOfArgs,
75  int *argTypes
76  );
77  MethodDescription(QMetaMethod &method);
80 
81  MethodDescription &operator=(const MethodDescription &other);
82 
83  inline bool isValid() const { return (m_methodIndex >= 0); }
84  inline QMetaMethod::MethodType type() const { return m_type; }
85  inline QMetaMethod::Access access() const { return m_access; }
86  inline int methodIndex() const { return m_methodIndex; }
87  inline QByteArray name() const { return m_name; }
88  inline int retType() const { return m_retType; }
89  inline int nrOfArgs() const { return m_nrOfArgs; }
90  inline int* argTypes() const { return m_argTypes; }
91  inline QByteArray signature() const { return m_signature; }
93  inline bool checkMethod(QByteArray &name, int nrOfArgs) const { return (name == m_name && nrOfArgs == m_nrOfArgs); }
94 
95 private:
96  QByteArray m_name;
98  QByteArray m_signature;
99  QMetaMethod::MethodType m_type;
100  QMetaMethod::Access m_access;
101  int m_retType;
103  int *m_argTypes;
105 };
106 
107 typedef QList<MethodDescription> MethodDescriptionList;
108 
122 {
123 public:
125 
131  FctCallParamContainer(int nrOfParams) :
132  m_nrOfParams(nrOfParams),
133  m_sizeArgs(nrOfParams+1)
134  {
135  m_args = new void*[m_sizeArgs];
136  m_argTypes = new int[m_sizeArgs];
137  for(int i=0;i<m_sizeArgs;i++)
138  {
139  m_args[i] = NULL;
140  m_argTypes[i] = -1;
141  }
142  };
143 
145 
150  {
151  for(int i=0;i<m_sizeArgs;i++)
152  {
153  QMetaType::destroy(m_argTypes[i], m_args[i]);
154  }
155  DELETE_AND_SET_NULL_ARRAY(m_argTypes);
156  DELETE_AND_SET_NULL_ARRAY(m_args);
157  }
158 
159  inline void** args() { return m_args; };
160  inline int* argTypes() { return m_argTypes; };
161  inline int getRetType() const { return m_argTypes[0]; };
163 
170  inline void initRetArg(int type) //reference of ptr is stolen and will be deleted by this class
171  {
172  if(m_args[0]) QMetaType::destroy(m_argTypes[0], m_args[0]);
173  m_argTypes[0] = type;
174  m_args[0] = QMetaType::create(type, NULL);
175  };
176 
178 
188  inline void setParamArg(unsigned int index, void* ptr, int type) //reference of ptr is stolen and will be deleted by this class
189  {
190  if((int)index < 0 || (int)index >= m_nrOfParams) return;
191  if(m_args[index+1]) QMetaType::destroy(m_argTypes[index+1], m_args[index+1]);
192  m_args[index+1] = ptr;
193  m_argTypes[index+1] = type;
194  };
195 
196 private:
198  FctCallParamContainer( const FctCallParamContainer & /*copy*/ ) = delete;
201  void** m_args;
202  int* m_argTypes;
203 };
204 
205 } //end namespace ito
206 
207 #endif // PYTHONITOMMETAOBJECT_H
bool isValid() const
Definition: pythonItomMetaObject.h:83
int m_nrOfArgs
Definition: pythonItomMetaObject.h:102
int retType() const
Definition: pythonItomMetaObject.h:88
QMetaMethod::Access access() const
Definition: pythonItomMetaObject.h:85
void setParamArg(unsigned int index, void *ptr, int type)
stores a pair of variable-type and corresponding void-pointer as parameter with given index number ...
Definition: pythonItomMetaObject.h:188
int * argTypes() const
Definition: pythonItomMetaObject.h:90
int m_nrOfParams
Definition: pythonItomMetaObject.h:199
int * m_argTypes
Definition: pythonItomMetaObject.h:202
FctCallParamContainer(int nrOfParams)
constructor
Definition: pythonItomMetaObject.h:131
void ** m_args
Definition: pythonItomMetaObject.h:201
QMetaMethod::MethodType type() const
Definition: pythonItomMetaObject.h:84
Definition: apiFunctionsGraph.cpp:39
int * argTypes()
Definition: pythonItomMetaObject.h:160
Small wrapper class with all necessary information for any method, signal or slot of class which shou...
Definition: pythonItomMetaObject.h:63
QByteArray signature() const
Definition: pythonItomMetaObject.h:91
QByteArray m_name
Definition: pythonItomMetaObject.h:96
void initRetArg(int type)
initializes the return value
Definition: pythonItomMetaObject.h:170
int m_methodIndex
Definition: pythonItomMetaObject.h:97
each instance of this class contains the parameters (including return parameter) for any function cal...
Definition: pythonItomMetaObject.h:121
int m_retType
Definition: pythonItomMetaObject.h:101
~FctCallParamContainer()
destructor
Definition: pythonItomMetaObject.h:149
QMetaMethod::Access m_access
Definition: pythonItomMetaObject.h:100
int getRetType() const
Definition: pythonItomMetaObject.h:161
int m_sizeArgs
Definition: pythonItomMetaObject.h:200
int nrOfArgs() const
Definition: pythonItomMetaObject.h:89
int * m_argTypes
Definition: pythonItomMetaObject.h:103
int methodIndex() const
Definition: pythonItomMetaObject.h:86
QByteArray m_signature
Definition: pythonItomMetaObject.h:98
QMetaMethod::MethodType m_type
Definition: pythonItomMetaObject.h:99
QByteArray name() const
Definition: pythonItomMetaObject.h:87
Definition: pythonItomMetaObject.h:34