itom  3.0.0
pythonItomMetaObject.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, 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  class MethodDescription;
34  typedef QList<MethodDescription> MethodDescriptionList;
35 
37  {
38  PythonQObjectMarshal() : m_objectID(0), m_object(NULL) {}
39  PythonQObjectMarshal(QByteArray objName, const char* className, void *object) : m_objName(objName), m_objectID(0), m_object(object) { m_className = QByteArray(className); }
40  QByteArray m_objName;
41  QByteArray m_className;
42  unsigned int m_objectID;
43  void *m_object; //casted from QObject
44  };
45 
46 
47 
48 // MethodDescription
50 {
51 public:
53  MethodDescription(QByteArray &name, QByteArray &signature, QMetaMethod::MethodType type, QMetaMethod::Access access, int methodIndex, int retType, int nrOfArgs, int *argTypes);
54  MethodDescription(QMetaMethod &method);
57 
58  MethodDescription &operator=(const MethodDescription &other);
59 
60  inline bool isValid() const { return (m_methodIndex >= 0); }
61  inline QMetaMethod::MethodType type() const { return m_type; }
62  inline QMetaMethod::Access access() const { return m_access; }
63  inline int methodIndex() const { return m_methodIndex; }
64  inline QByteArray name() const { return m_name; }
65  inline int retType() const { return m_retType; }
66  inline int nrOfArgs() const { return m_nrOfArgs; }
67  inline int* argTypes() const { return m_argTypes; }
68  inline QByteArray signature() const { return m_signature; }
70  inline bool checkMethod(QByteArray &name, int nrOfArgs) const { return (name == m_name && nrOfArgs == m_nrOfArgs); }
71 
72 private:
73  QByteArray m_name;
75  QByteArray m_signature;
76  QMetaMethod::MethodType m_type;
77  QMetaMethod::Access m_access;
78  int m_retType;
79  int m_nrOfArgs;
80  int *m_argTypes;
82 };
83 
97 {
98 public:
100 
106  FctCallParamContainer(int nrOfParams) :
107  m_nrOfParams(nrOfParams),
108  m_sizeArgs(nrOfParams+1)
109  {
110  m_args = new void*[m_sizeArgs];
111  m_argTypes = new int[m_sizeArgs];
112  for(int i=0;i<m_sizeArgs;i++)
113  {
114  m_args[i] = NULL;
115  m_argTypes[i] = -1;
116  }
117  };
118 
120 
125  {
126  for(int i=0;i<m_sizeArgs;i++)
127  {
128  QMetaType::destroy(m_argTypes[i], m_args[i]);
129  }
130  DELETE_AND_SET_NULL_ARRAY(m_argTypes);
131  DELETE_AND_SET_NULL_ARRAY(m_args);
132  }
133 
134  inline void** args() { return m_args; };
135  inline int* argTypes() { return m_argTypes; };
136  inline int getRetType() const { return m_argTypes[0]; };
138 
145  inline void initRetArg(int type) //reference of ptr is stolen and will be deleted by this class
146  {
147  if(m_args[0]) QMetaType::destroy(m_argTypes[0], m_args[0]);
148  m_argTypes[0] = type;
149 #if (QT_VERSION >= 0x050000)
150  m_args[0] = QMetaType::create(type, NULL);
151 #else
152  m_args[0] = QMetaType::construct(type, NULL);
153 #endif
154  };
155 
157 
167  inline void setParamArg(unsigned int index, void* ptr, int type) //reference of ptr is stolen and will be deleted by this class
168  {
169  if((int)index < 0 || (int)index >= m_nrOfParams) return;
170  if(m_args[index+1]) QMetaType::destroy(m_argTypes[index+1], m_args[index+1]);
171  m_args[index+1] = ptr;
172  m_argTypes[index+1] = type;
173  };
174 
175 private:
177  FctCallParamContainer( const FctCallParamContainer & /*copy*/ ) { /* forbidden */ };
178  int m_nrOfParams;
180  void** m_args;
181  int* m_argTypes;
182 };
183 
184 } //end namespace ito
185 
186 #endif // PYTHONITOMMETAOBJECT_H
bool isValid() const
Definition: pythonItomMetaObject.h:60
int m_nrOfArgs
Definition: pythonItomMetaObject.h:79
int retType() const
Definition: pythonItomMetaObject.h:65
QMetaMethod::Access access() const
Definition: pythonItomMetaObject.h:62
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:167
int * argTypes() const
Definition: pythonItomMetaObject.h:67
int m_nrOfParams
Definition: pythonItomMetaObject.h:177
int * m_argTypes
Definition: pythonItomMetaObject.h:181
FctCallParamContainer(int nrOfParams)
constructor
Definition: pythonItomMetaObject.h:106
void ** m_args
Definition: pythonItomMetaObject.h:180
QMetaMethod::MethodType type() const
Definition: pythonItomMetaObject.h:61
Definition: apiFunctionsGraph.cpp:39
int * argTypes()
Definition: pythonItomMetaObject.h:135
Small wrapper class with all necessary information for any method, signal or slot of class which shou...
Definition: pythonItomMetaObject.h:49
QByteArray signature() const
Definition: pythonItomMetaObject.h:68
QByteArray m_name
Definition: pythonItomMetaObject.h:73
void initRetArg(int type)
initializes the return value
Definition: pythonItomMetaObject.h:145
int m_methodIndex
Definition: pythonItomMetaObject.h:74
each instance of this class contains the parameters (including return parameter) for any function cal...
Definition: pythonItomMetaObject.h:96
int m_retType
Definition: pythonItomMetaObject.h:78
~FctCallParamContainer()
destructor
Definition: pythonItomMetaObject.h:124
QMetaMethod::Access m_access
Definition: pythonItomMetaObject.h:77
int getRetType() const
Definition: pythonItomMetaObject.h:136
int m_sizeArgs
Definition: pythonItomMetaObject.h:179
int nrOfArgs() const
Definition: pythonItomMetaObject.h:66
int * m_argTypes
Definition: pythonItomMetaObject.h:80
int methodIndex() const
Definition: pythonItomMetaObject.h:63
QByteArray m_signature
Definition: pythonItomMetaObject.h:75
QMetaMethod::MethodType m_type
Definition: pythonItomMetaObject.h:76
QByteArray name() const
Definition: pythonItomMetaObject.h:64
Definition: pythonItomMetaObject.h:36