Seamly2D
Code documentation
qmuparsercallback.cpp
Go to the documentation of this file.
1 /***************************************************************************************************
2  **
3  ** Copyright (C) 2013 Ingo Berg
4  **
5  ** Permission is hereby granted, free of charge, to any person obtaining a copy of this
6  ** software and associated documentation files (the "Software"), to deal in the Software
7  ** without restriction, including without limitation the rights to use, copy, modify,
8  ** merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
9  ** permit persons to whom the Software is furnished to do so, subject to the following conditions:
10  **
11  ** The above copyright notice and this permission notice shall be included in all copies or
12  ** substantial portions of the Software.
13  **
14  ** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
15  ** NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16  ** NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17  ** DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18  ** OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  **
20  ******************************************************************************************************/
21 
22 #include "qmuparsercallback.h"
23 
24 /**
25  * @file
26  * @brief Implementation of the parser callback class.
27  */
28 
29 namespace qmu
30 {
31 //---------------------------------------------------------------------------------------------------------------------
32 //Supressing specific warnings on gcc/g++ http://www.mr-edd.co.uk/blog/supressing_gcc_warnings
33 #ifdef __GNUC__
34 __extension__
35 #endif
36 QmuParserCallback::QmuParserCallback ( fun_type0 a_pFun, bool a_bAllowOpti )
37  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 0 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
38  m_iCode ( cmFUNC ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
39 {}
40 
41 //---------------------------------------------------------------------------------------------------------------------
42 #ifdef __GNUC__
43 __extension__
44 #endif
45 QmuParserCallback::QmuParserCallback ( fun_type1 a_pFun, bool a_bAllowOpti, int a_iPrec, ECmdCode a_iCode )
46  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 1 ), m_iPri ( a_iPrec ), m_eOprtAsct ( oaNONE ),
47  m_iCode ( a_iCode ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
48 {}
49 
50 //---------------------------------------------------------------------------------------------------------------------
51 /**
52  * @brief Constructor for constructing funcstion callbacks taking two arguments.
53  * @throw nothrow
54  */
55 #ifdef __GNUC__
56 __extension__
57 #endif
58 QmuParserCallback::QmuParserCallback ( fun_type2 a_pFun, bool a_bAllowOpti )
59  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 2 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
60  m_iCode ( cmFUNC ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
61 {}
62 
63 //---------------------------------------------------------------------------------------------------------------------
64 /**
65  * @brief Constructor for constructing binary operator callbacks.
66  * @param a_pFun Pointer to a static function taking two arguments
67  * @param a_bAllowOpti A flag indicating this funcation can be optimized
68  * @param a_iPrec The operator precedence
69  * @param a_eOprtAsct The operators associativity
70  * @throw nothrow
71  */
72 #ifdef __GNUC__
73 __extension__
74 #endif
75 QmuParserCallback::QmuParserCallback (fun_type2 a_pFun, bool a_bAllowOpti, int a_iPrec, EOprtAssociativity a_eOprtAsct)
76  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 2 ), m_iPri ( a_iPrec ), m_eOprtAsct ( a_eOprtAsct ),
77  m_iCode ( cmOPRT_BIN ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
78 {}
79 
80 //---------------------------------------------------------------------------------------------------------------------
81 #ifdef __GNUC__
82 __extension__
83 #endif
84 QmuParserCallback::QmuParserCallback ( fun_type3 a_pFun, bool a_bAllowOpti )
85  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 3 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
86  m_iCode ( cmFUNC ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
87 {}
88 
89 
90 //---------------------------------------------------------------------------------------------------------------------
91 #ifdef __GNUC__
92 __extension__
93 #endif
94 QmuParserCallback::QmuParserCallback ( fun_type4 a_pFun, bool a_bAllowOpti )
95  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 4 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
96  m_iCode ( cmFUNC ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
97 {}
98 
99 
100 //---------------------------------------------------------------------------------------------------------------------
101 #ifdef __GNUC__
102 __extension__
103 #endif
104 QmuParserCallback::QmuParserCallback ( fun_type5 a_pFun, bool a_bAllowOpti )
105  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 5 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
106  m_iCode ( cmFUNC ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
107 {}
108 
109 //---------------------------------------------------------------------------------------------------------------------
110 #ifdef __GNUC__
111 __extension__
112 #endif
113 QmuParserCallback::QmuParserCallback ( fun_type6 a_pFun, bool a_bAllowOpti )
114  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 6 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
115  m_iCode ( cmFUNC ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
116 {}
117 
118 //---------------------------------------------------------------------------------------------------------------------
119 #ifdef __GNUC__
120 __extension__
121 #endif
122 QmuParserCallback::QmuParserCallback ( fun_type7 a_pFun, bool a_bAllowOpti )
123  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 7 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
124  m_iCode ( cmFUNC ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
125 {}
126 
127 //---------------------------------------------------------------------------------------------------------------------
128 #ifdef __GNUC__
129 __extension__
130 #endif
131 QmuParserCallback::QmuParserCallback ( fun_type8 a_pFun, bool a_bAllowOpti )
132  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 8 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
133  m_iCode ( cmFUNC ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
134 {}
135 
136 //---------------------------------------------------------------------------------------------------------------------
137 #ifdef __GNUC__
138 __extension__
139 #endif
140 QmuParserCallback::QmuParserCallback ( fun_type9 a_pFun, bool a_bAllowOpti )
141  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 9 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
142  m_iCode ( cmFUNC ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
143 {}
144 
145 //---------------------------------------------------------------------------------------------------------------------
146 #ifdef __GNUC__
147 __extension__
148 #endif
150  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 10 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
151  m_iCode ( cmFUNC ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
152 {}
153 
154 //---------------------------------------------------------------------------------------------------------------------
155 #ifdef __GNUC__
156 __extension__
157 #endif
159  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 0 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
160  m_iCode ( cmFUNC_BULK ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
161 {}
162 
163 //---------------------------------------------------------------------------------------------------------------------
164 #ifdef __GNUC__
165 __extension__
166 #endif
168  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 1 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
169  m_iCode ( cmFUNC_BULK ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
170 {}
171 
172 //---------------------------------------------------------------------------------------------------------------------
173 /**
174  * @brief Constructor for constructing funcstion callbacks taking two arguments.
175  * @throw nothrow
176  */
177 #ifdef __GNUC__
178 __extension__
179 #endif
181  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 2 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
182  m_iCode ( cmFUNC_BULK ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
183 {}
184 
185 //---------------------------------------------------------------------------------------------------------------------
186 #ifdef __GNUC__
187 __extension__
188 #endif
190  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 3 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
191  m_iCode ( cmFUNC_BULK ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
192 {}
193 
194 //---------------------------------------------------------------------------------------------------------------------
195 #ifdef __GNUC__
196 __extension__
197 #endif
199  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 4 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
200  m_iCode ( cmFUNC_BULK ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
201 {}
202 
203 //---------------------------------------------------------------------------------------------------------------------
204 #ifdef __GNUC__
205 __extension__
206 #endif
208  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 5 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
209  m_iCode ( cmFUNC_BULK ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
210 {}
211 
212 //---------------------------------------------------------------------------------------------------------------------
213 #ifdef __GNUC__
214 __extension__
215 #endif
217  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 6 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
218  m_iCode ( cmFUNC_BULK ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
219 {}
220 
221 //---------------------------------------------------------------------------------------------------------------------
222 #ifdef __GNUC__
223 __extension__
224 #endif
226  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 7 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
227  m_iCode ( cmFUNC_BULK ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
228 {}
229 
230 //---------------------------------------------------------------------------------------------------------------------
231 #ifdef __GNUC__
232 __extension__
233 #endif
235  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 8 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
236  m_iCode ( cmFUNC_BULK ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
237 {}
238 
239 //---------------------------------------------------------------------------------------------------------------------
240 #ifdef __GNUC__
241 __extension__
242 #endif
244  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 9 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
245  m_iCode ( cmFUNC_BULK ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
246 {}
247 
248 //---------------------------------------------------------------------------------------------------------------------
249 #ifdef __GNUC__
250 __extension__
251 #endif
253  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 10 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
254  m_iCode ( cmFUNC_BULK ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
255 {}
256 
257 //---------------------------------------------------------------------------------------------------------------------
258 #ifdef __GNUC__
259 __extension__
260 #endif
262  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( -1 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
263  m_iCode ( cmFUNC ), m_iType ( tpDBL ), m_bAllowOpti ( a_bAllowOpti )
264 {}
265 
266 //---------------------------------------------------------------------------------------------------------------------
267 #ifdef __GNUC__
268 __extension__
269 #endif
271  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 0 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
272  m_iCode ( cmFUNC_STR ), m_iType ( tpSTR ), m_bAllowOpti ( a_bAllowOpti )
273 {}
274 
275 //---------------------------------------------------------------------------------------------------------------------
276 #ifdef __GNUC__
277 __extension__
278 #endif
280  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 1 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
281  m_iCode ( cmFUNC_STR ), m_iType ( tpSTR ), m_bAllowOpti ( a_bAllowOpti )
282 {}
283 
284 //---------------------------------------------------------------------------------------------------------------------
285 #ifdef __GNUC__
286 __extension__
287 #endif
289  : m_pFun ( reinterpret_cast<void*> ( a_pFun ) ), m_iArgc ( 2 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ),
290  m_iCode ( cmFUNC_STR ), m_iType ( tpSTR ), m_bAllowOpti ( a_bAllowOpti )
291 {}
292 
293 //---------------------------------------------------------------------------------------------------------------------
294 /**
295  * @brief Default constructor.
296  * @throw nothrow
297  */
299  : m_pFun ( nullptr ), m_iArgc ( 0 ), m_iPri ( -1 ), m_eOprtAsct ( oaNONE ), m_iCode ( cmUNKNOWN ),
300  m_iType ( tpVOID ), m_bAllowOpti ( 0 )
301 {}
302 
303 //---------------------------------------------------------------------------------------------------------------------
304 /**
305  * @brief Copy constructor.
306  * @throw nothrow
307  */
309  : m_pFun ( a_Fun.m_pFun ), m_iArgc ( a_Fun.m_iArgc ), m_iPri ( a_Fun.m_iPri ), m_eOprtAsct ( a_Fun.m_eOprtAsct ),
310  m_iCode ( a_Fun.m_iCode ), m_iType ( a_Fun.m_iType ), m_bAllowOpti ( a_Fun.m_bAllowOpti )
311 {}
312 
313 //---------------------------------------------------------------------------------------------------------------------
315 {
316  if (this != &a_Fun)
317  {
318  m_pFun = a_Fun.m_pFun;
319  m_iArgc = a_Fun.m_iArgc;
320  m_bAllowOpti = a_Fun.m_bAllowOpti;
321  m_iCode = a_Fun.m_iCode;
322  m_iType = a_Fun.m_iType;
323  m_iPri = a_Fun.m_iPri;
324  m_eOprtAsct = a_Fun.m_eOprtAsct;
325  }
326  return *this;
327 }
328 
329 } // namespace qmu
Encapsulation of prototypes for a numerical parser function.
EOprtAssociativity m_eOprtAsct
Operator associativity; Valid only for binary operators.
int m_iPri
Valid only for binary and infix operators; Operator precedence.
QmuParserCallback()
Default constructor.
void * m_pFun
Pointer to the callback function, casted to void.
bool m_bAllowOpti
Flag indication optimizeability.
int m_iArgc
Number of numeric function arguments.
QmuParserCallback & operator=(const QmuParserCallback &a_Fun)
Namespace for mathematical applications.
qreal(* bulkfun_type10)(int, int, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal)
Callback type used for functions with five arguments.
Definition: qmuparserdef.h:287
qreal(* bulkfun_type4)(int, int, qreal, qreal, qreal, qreal)
Callback type used for functions with four arguments.
Definition: qmuparserdef.h:269
qreal(* fun_type7)(qreal, qreal, qreal, qreal, qreal, qreal, qreal)
Callback type used for functions with five arguments.
Definition: qmuparserdef.h:245
qreal(* fun_type10)(qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal)
Callback type used for functions with five arguments.
Definition: qmuparserdef.h:254
qreal(* fun_type3)(qreal, qreal, qreal)
Callback type used for functions with three arguments.
Definition: qmuparserdef.h:233
qreal(* fun_type8)(qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal)
Callback type used for functions with five arguments.
Definition: qmuparserdef.h:248
qreal(* bulkfun_type5)(int, int, qreal, qreal, qreal, qreal, qreal)
Callback type used for functions with five arguments.
Definition: qmuparserdef.h:272
ECmdCode
Bytecode values.
Definition: qmuparserdef.h:99
@ cmUNKNOWN
uninitialized item
Definition: qmuparserdef.h:142
@ cmFUNC
Code for a generic function item.
Definition: qmuparserdef.h:134
@ cmFUNC_STR
Code for a function with a string parameter.
Definition: qmuparserdef.h:135
@ cmFUNC_BULK
Special callbacks for Bulk mode with an additional parameter for the bulk index.
Definition: qmuparserdef.h:136
@ cmOPRT_BIN
user defined binary operator
Definition: qmuparserdef.h:138
qreal(* fun_type6)(qreal, qreal, qreal, qreal, qreal, qreal)
Callback type used for functions with five arguments.
Definition: qmuparserdef.h:242
qreal(* fun_type4)(qreal, qreal, qreal, qreal)
Callback type used for functions with four arguments.
Definition: qmuparserdef.h:236
qreal(* fun_type9)(qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal)
Callback type used for functions with five arguments.
Definition: qmuparserdef.h:251
qreal(* bulkfun_type1)(int, int, qreal)
Callback type used for functions with a single arguments.
Definition: qmuparserdef.h:260
qreal(* fun_type2)(qreal, qreal)
Callback type used for functions with two arguments.
Definition: qmuparserdef.h:230
qreal(* bulkfun_type2)(int, int, qreal, qreal)
Callback type used for functions with two arguments.
Definition: qmuparserdef.h:263
qreal(* bulkfun_type0)(int, int)
Callback type used for functions without arguments.
Definition: qmuparserdef.h:257
qreal(* strfun_type3)(const QString &, qreal, qreal)
Callback type used for functions taking a string and two values as arguments.
Definition: qmuparserdef.h:299
EOprtAssociativity
Parser operator precedence values.
Definition: qmuparserdef.h:165
@ oaNONE
Definition: qmuparserdef.h:168
qreal(* fun_type1)(qreal)
Callback type used for functions with a single arguments.
Definition: qmuparserdef.h:227
qreal(* bulkfun_type7)(int, int, qreal, qreal, qreal, qreal, qreal, qreal, qreal)
Callback type used for functions with five arguments.
Definition: qmuparserdef.h:278
qreal(* multfun_type)(const qreal *, int)
Callback type used for functions with a variable argument list.
Definition: qmuparserdef.h:290
qreal(* strfun_type2)(const QString &, qreal)
Callback type used for functions taking a string and a value as arguments.
Definition: qmuparserdef.h:296
qreal(* fun_type0)()
Callback type used for functions without arguments.
Definition: qmuparserdef.h:224
qreal(* bulkfun_type6)(int, int, qreal, qreal, qreal, qreal, qreal, qreal)
Callback type used for functions with five arguments.
Definition: qmuparserdef.h:275
qreal(* bulkfun_type8)(int, int, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal)
Callback type used for functions with five arguments.
Definition: qmuparserdef.h:281
qreal(* bulkfun_type3)(int, int, qreal, qreal, qreal)
Callback type used for functions with three arguments.
Definition: qmuparserdef.h:266
qreal(* bulkfun_type9)(int, int, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal)
Callback type used for functions with five arguments.
Definition: qmuparserdef.h:284
@ tpVOID
Undefined type.
Definition: qmuparserdef.h:152
@ tpDBL
Floating point variables.
Definition: qmuparserdef.h:151
@ tpSTR
String type (Function arguments and constants only, no string variables)
Definition: qmuparserdef.h:150
qreal(* fun_type5)(qreal, qreal, qreal, qreal, qreal)
Callback type used for functions with five arguments.
Definition: qmuparserdef.h:239
qreal(* strfun_type1)(const QString &)
Callback type used for functions taking a string as an argument.
Definition: qmuparserdef.h:293
Definition of the parser callback class.