itom 1.3.0
D:/git-itom/sources/itom/Qitom/python/pythonItomMetaObject.h
00001 /* ********************************************************************
00002     itom software
00003     URL: http://www.uni-stuttgart.de/ito
00004     Copyright (C) 2013, Institut für Technische Optik (ITO),
00005     Universität Stuttgart, Germany
00006 
00007     This file is part of itom.
00008   
00009     itom is free software; you can redistribute it and/or modify it
00010     under the terms of the GNU Library General Public Licence as published by
00011     the Free Software Foundation; either version 2 of the Licence, or (at
00012     your option) any later version.
00013 
00014     itom is distributed in the hope that it will be useful, but
00015     WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library
00017     General Public Licence for more details.
00018 
00019     You should have received a copy of the GNU Library General Public License
00020     along with itom. If not, see <http://www.gnu.org/licenses/>.
00021 *********************************************************************** */
00022 
00023 #ifndef PYTHONITOMMETAOBJECT_H
00024 #define PYTHONITOMMETAOBJECT_H
00025 
00026 #include "../global.h"
00027 
00028 #include <qbytearray.h>
00029 #include <qmetaobject.h>
00030 
00031 namespace ito 
00032 {
00033     class MethodDescription;
00034     typedef QList<MethodDescription> MethodDescriptionList;
00035 
00036     struct PythonQObjectMarshal
00037     {
00038         PythonQObjectMarshal() : m_objectID(0), m_object(NULL) {}
00039         PythonQObjectMarshal(QByteArray objName, const char* className, void *object) : m_objName(objName), m_objectID(0), m_object(object) { m_className = QByteArray(className); }
00040         QByteArray m_objName;
00041         QByteArray m_className;
00042         unsigned int m_objectID;
00043         void *m_object; //casted from QObject
00044     };
00045 
00046 
00047 
00048 // MethodDescription
00049 class MethodDescription
00050 {
00051 public:
00052     MethodDescription();
00053     MethodDescription(QByteArray &name, QByteArray &signature, QMetaMethod::MethodType type, QMetaMethod::Access access, int methodIndex, int retType, int nrOfArgs, int *argTypes);
00054     MethodDescription(QMetaMethod &method);
00055     MethodDescription(const MethodDescription &copy);
00056     ~MethodDescription();
00057 
00058     MethodDescription &operator=(const MethodDescription &other);
00059 
00060     inline bool isValid() const { return (m_methodIndex >= 0); }    
00061     inline QMetaMethod::MethodType type() const { return m_type; }  
00062     inline QMetaMethod::Access access() const { return m_access; }  
00063     inline int methodIndex() const { return m_methodIndex; }        
00064     inline QByteArray name() const { return m_name; }               
00065     inline int retType() const { return m_retType; }                
00066     inline int nrOfArgs() const { return m_nrOfArgs; }              
00067     inline int* argTypes() const { return m_argTypes; }             
00068     inline QByteArray signature() const { return m_signature; }     
00070     inline bool checkMethod(QByteArray &name, int nrOfArgs) const { return (name == m_name && nrOfArgs == m_nrOfArgs); }
00071 
00072 private:
00073     QByteArray m_name;               
00074     int m_methodIndex;               
00075     QByteArray m_signature;          
00076     QMetaMethod::MethodType m_type;  
00077     QMetaMethod::Access m_access;    
00078     int m_retType;                   
00079     int m_nrOfArgs;                  
00080     int *m_argTypes;                 
00082 };
00083 
00096 class FctCallParamContainer
00097 {
00098 public:
00100 
00106     FctCallParamContainer(int nrOfParams) :
00107       m_nrOfParams(nrOfParams),
00108       m_sizeArgs(nrOfParams+1)
00109     {
00110         m_args = new void*[m_sizeArgs];
00111         m_argTypes = new int[m_sizeArgs];
00112         for(int i=0;i<m_sizeArgs;i++) 
00113         {
00114             m_args[i] = NULL;
00115             m_argTypes[i] = -1;
00116         }
00117     };
00118     
00120 
00124     ~FctCallParamContainer()
00125     {
00126         for(int i=0;i<m_sizeArgs;i++) 
00127         {
00128             QMetaType::destroy(m_argTypes[i], m_args[i]);
00129         }
00130         DELETE_AND_SET_NULL_ARRAY(m_argTypes);
00131         DELETE_AND_SET_NULL_ARRAY(m_args);
00132     }
00133 
00134     inline void** args() { return m_args; };                 
00135     inline int* argTypes() { return m_argTypes; };           
00136     inline int getRetType() const { return m_argTypes[0]; }; 
00138 
00139 
00145     inline void initRetArg(int type)  //reference of ptr is stolen and will be deleted by this class
00146     { 
00147         if(m_args[0]) QMetaType::destroy(m_argTypes[0], m_args[0]);
00148         m_argTypes[0] = type; 
00149 #if (QT_VERSION >= 0x050000)
00150         m_args[0] = QMetaType::create(type, NULL);
00151 #else
00152         m_args[0] = QMetaType::construct(type, NULL);
00153 #endif
00154     };
00155 
00157 
00167     inline void setParamArg(unsigned int index, void* ptr, int type)  //reference of ptr is stolen and will be deleted by this class
00168     { 
00169         if((int)index < 0 || (int)index >= m_nrOfParams) return;
00170         if(m_args[index+1]) QMetaType::destroy(m_argTypes[index+1], m_args[index+1]);
00171         m_args[index+1] = ptr; 
00172         m_argTypes[index+1] = type; 
00173     };
00174 
00175 private:
00177     FctCallParamContainer( const FctCallParamContainer & /*copy*/ ) { /* forbidden */ };
00178     int m_nrOfParams;  
00179     int m_sizeArgs;  
00180     void** m_args;   
00181     int* m_argTypes; 
00182 };
00183 
00184 } //end namespace ito
00185 
00186 #endif // PYTHONITOMMETAOBJECT_H
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends