QSkinny 0.8.0
C++/Qt UI toolkit
Loading...
Searching...
No Matches
QskMetaFunction.hpp
1/******************************************************************************
2 * QSkinny - Copyright (C) The authors
3 * SPDX-License-Identifier: BSD-3-Clause
4 *****************************************************************************/
5
6#ifndef QSK_META_FUNCTION_HPP
7#define QSK_META_FUNCTION_HPP
8
9#include "QskGlobal.h"
10#include <qobject.h>
11
12class QskMetaFunction::FunctionCall : public QtPrivate::QSlotObjectBase
13{
14 public:
15 typedef void (* InvokeFunction)(
16 int which, QtPrivate::QSlotObjectBase*, QObject*, void**, bool* );
17
18 enum
19 {
20 TypeInfo = NumOperations + 1
21 };
22
23 int typeInfo() const;
24 int refCount() const;
25
26 inline const int* parameterTypes() const
27 {
28 return m_parameterTypes;
29 }
30
31 inline void setParameterTypes( const int* types )
32 {
33 m_parameterTypes = types;
34 }
35
36 protected:
37 explicit inline FunctionCall( InvokeFunction f,
38 const int* parameterTypes = nullptr ):
39 QSlotObjectBase( f ),
40 m_parameterTypes( parameterTypes )
41 {
42 }
43
44 private:
45 const int* m_parameterTypes; // static array, only needed for Qt::QueuedConnection
46};
47
48namespace QskMetaFunctionCall
49{
50 template< typename Function, typename Args, typename R >
52 {
54
55 public:
56 explicit inline StaticFunctionCall( Function function ):
57 FunctionCall( &invoke ),
58 m_function( function )
59 {
60 }
61
62 static void invoke(int which, QSlotObjectBase* functionCall,
63 QObject* object, void** args, bool* ret )
64 {
65 switch ( which )
66 {
67 case Destroy:
68 {
69 delete static_cast< MetaCall* >( functionCall );
70 break;
71 }
72 case Call:
73 {
74 using FuncType = QtPrivate::FunctionPointer< Function >;
75
76 FuncType::template call< Args, R >(
77 static_cast< MetaCall* >( functionCall )->m_function, object, args );
78 break;
79 }
80 case Compare:
81 {
82 *ret = reinterpret_cast< MetaCall* >( args )->m_function
83 == static_cast< MetaCall* >( functionCall )->m_function;
84
85 break;
86 }
87 case TypeInfo:
88 {
89 *reinterpret_cast< int* >( args ) = QskMetaFunction::StaticFunction;
90 break;
91 }
92 }
93 }
94
95 private:
96 Function m_function;
97 };
98
99 template< typename Function, typename Args, typename R >
101 {
103
104 public:
105 explicit inline MemberFunctionCall( Function function ):
106 FunctionCall( &invoke ),
107 m_function( function )
108 {
109 }
110
111 static void invoke( int which, QSlotObjectBase* functionCall,
112 QObject* object, void** args, bool* )
113 {
114 switch (which)
115 {
116 case Destroy:
117 {
118 delete static_cast< MetaCall* >( functionCall );
119 break;
120 }
121 case Call:
122 {
123 using FuncType = QtPrivate::FunctionPointer< Function >;
124
125 FuncType::template call< Args, R >(
126 static_cast< MetaCall* >( functionCall )->m_function,
127 static_cast< typename FuncType::Object* >( object ), args );
128
129 break;
130 }
131 case TypeInfo:
132 {
133 *reinterpret_cast< int* >( args ) = QskMetaFunction::MemberFunction;
134 break;
135 }
136 }
137 }
138
139 private:
140 Function m_function;
141 };
142
143 template< typename Function, int N, typename Args, typename R >
145 {
147
148 public:
149 explicit inline FunctorFunctionCall( Function function ):
150 FunctionCall( &invoke ),
151 m_function( function )
152 {
153 }
154
155 static void invoke( int which, QSlotObjectBase* functionCall,
156 QObject* object, void** args, bool* )
157 {
158 switch (which)
159 {
160 case Destroy:
161 {
162 delete static_cast< MetaCall* >( functionCall );
163 break;
164 }
165 case Call:
166 {
167#if QT_VERSION < QT_VERSION_CHECK( 6, 7, 0 )
168 using FuncType = QtPrivate::Functor< Function, N >;
169#else
170 using FuncType = QtPrivate::Callable< Function, Args >;
171#endif
172
173 FuncType::template call< Args, R >(
174 static_cast< MetaCall* >( functionCall )->m_function, object, args );
175
176 break;
177 }
178 case TypeInfo:
179 {
180 *reinterpret_cast< int* >( args ) = QskMetaFunction::Functor;
181 break;
182 }
183 }
184 }
185
186 private:
187 Function m_function;
188 };
189}
190
191#endif