PythonQt
PythonQtMisc.h
Go to the documentation of this file.
1 #ifndef _PYTHONQTMISC_H
2 #define _PYTHONQTMISC_H
3 
4 /*
5  *
6  * Copyright (C) 2010 MeVis Medical Solutions AG All Rights Reserved.
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * Further, this software is distributed without any warranty that it is
19  * free of the rightful claim of any third person regarding infringement
20  * or the like. Any license provided herein, whether implied or
21  * otherwise, applies only to this software file. Patent licenses, if
22  * any, provided herein do not apply to combinations of this program with
23  * other software, or any other product whatsoever.
24  *
25  * You should have received a copy of the GNU Lesser General Public
26  * License along with this library; if not, write to the Free Software
27  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28  *
29  * Contact information: MeVis Medical Solutions AG, Universitaetsallee 29,
30  * 28359 Bremen, Germany or:
31  *
32  * http://www.mevis.de
33  *
34  */
35 
36 //----------------------------------------------------------------------------------
43 //----------------------------------------------------------------------------------
44 
45 #include "PythonQtPythonInclude.h"
46 #include <vector>
47 #include <QVariant>
48 
49 #define PYTHONQT_MAX_ARGS 32
50 
51 #define PythonQtArgumentFrame_ADD_VALUE(store, type, value, ptr) \
52 { type* item = (type*)store->nextPODPtr(); \
53  *item = value; \
54  ptr = (void*)item; \
55 }
56 
57 #define PythonQtArgumentFrame_ADD_VALUE_IF_NEEDED(alreadyAllocatedPtr,store, type, value, ptr) \
58 { \
59  type* item = (type*)(alreadyAllocatedPtr?alreadyAllocatedPtr:store->nextPODPtr()); \
60  *item = value; \
61  ptr = (void*)item; \
62 }
63 
64 #define PythonQtArgumentFrame_ADD_VARIANT_VALUE(store, value, ptr) \
65 { QVariant* item = store->nextVariantPtr(); \
66  *item = value; \
67  ptr = (void*)item; \
68 }
69 
70 #if QT_VERSION >= 0x060000
71 
72 #define PythonQtArgumentFrame_ADD_VARIANT_VALUE_BY_ID(store, id, ptr) \
73  PythonQtArgumentFrame_ADD_VARIANT_VALUE(store, QVariant(QMetaType(id)), ptr)
74 
75 #else
76 
77 #define PythonQtArgumentFrame_ADD_VARIANT_VALUE_BY_ID(store, id, ptr) \
78  PythonQtArgumentFrame_ADD_VARIANT_VALUE(store, QVariant::Type(id), ptr)
79 
80 #endif
81 
82 #define PythonQtArgumentFrame_ADD_VARIANT_VALUE_IF_NEEDED(alreadyAllocatedPtr,store, value, ptr) \
83 { \
84  QVariant* item = (QVariant*)(alreadyAllocatedPtr?alreadyAllocatedPtr:store->nextVariantPtr()); \
85  *item = value; \
86  ptr = (void*)item; \
87 }
88 
89 #if QT_VERSION >= 0x060000
90 
91 #define PythonQtArgumentFrame_ADD_VARIANT_VALUE_BY_ID_IF_NEEDED(alreadyAllocatedPtr,store, id, ptr) \
92  PythonQtArgumentFrame_ADD_VARIANT_VALUE_IF_NEEDED(alreadyAllocatedPtr,store, QVariant(QMetaType(id)), ptr)
93 
94 #else
95 
96 #define PythonQtArgumentFrame_ADD_VARIANT_VALUE_BY_ID_IF_NEEDED(alreadyAllocatedPtr,store, id, ptr) \
97  PythonQtArgumentFrame_ADD_VARIANT_VALUE_IF_NEEDED(alreadyAllocatedPtr,store, QVariant::Type(id), ptr)
98 
99 #endif
100 
103 
104 public:
108  static void deleteFrame(PythonQtArgumentFrame* frame);
109 
111  static void cleanupFreeList();
112 
114  void reset();
115 
117  QVariant* nextVariantPtr();
119  quint64* nextPODPtr();
120 
121 private:
124 
125  std::vector<quint64> _podArgs;
126  std::vector<QVariant> _variantArgs;
127 
128  PythonQtArgumentFrame* _freeListNext;
129 
130  static PythonQtArgumentFrame* _freeListHead;
131 };
132 
133 #endif
Stores C++ arguments for a qt_metacall (which are created when converting data from Python to C++)
Definition: PythonQtMisc.h:102
static void deleteFrame(PythonQtArgumentFrame *frame)
Frees the frame (resetting it and putting it back to the freelist)
QVariant * nextVariantPtr()
Get next pointer to a variant.
static void cleanupFreeList()
Frees all PythonQtArgumentFrame frames that are stored.
void reset()
Resets the pod and variant argument lists to empty lists.
quint64 * nextPODPtr()
Get next pointer to a POD.
static PythonQtArgumentFrame * newFrame()
Create a new (empty) frame (which is typically reused from a freelist)