NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
muParserCallback.cpp
Go to the documentation of this file.
1/*
2 __________
3 _____ __ __\______ \_____ _______ ______ ____ _______
4 / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5 | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6 |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7 \/ \/ \/ \/
8 Copyright (C) 2004-2011 Ingo Berg
9
10 Permission is hereby granted, free of charge, to any person obtaining a copy of this
11 software and associated documentation files (the "Software"), to deal in the Software
12 without restriction, including without limitation the rights to use, copy, modify,
13 merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to the following conditions:
15
16 The above copyright notice and this permission notice shall be included in all copies or
17 substantial portions of the Software.
18
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
20 NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
22 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24*/
25
26#include "muParserCallback.h"
27
33namespace mu
34{
35 //---------------------------------------------------------------------------
36 ParserCallback::ParserCallback(fun_type0 a_pFun, bool optimizeAway)
37 :m_pFun((void*)a_pFun)
38 ,m_iArgc(0)
39 ,m_iPri(-1)
40 ,m_eOprtAsct(oaNONE)
41 ,m_iCode(cmFUNC)
42 ,m_iType(tpDBL)
43 ,m_bAllowOpti(optimizeAway)
44 {}
45
46 //---------------------------------------------------------------------------
47 ParserCallback::ParserCallback(fun_type1 a_pFun, bool optimizeAway, int a_iPrec, ECmdCode a_iCode)
48 :m_pFun((void*)a_pFun)
49 ,m_iArgc(1)
50 ,m_iPri(a_iPrec)
51 ,m_eOprtAsct(oaNONE)
52 ,m_iCode(a_iCode)
53 ,m_iType(tpDBL)
54 ,m_bAllowOpti(optimizeAway)
55 {}
56
57
58 //---------------------------------------------------------------------------
62 ParserCallback::ParserCallback(fun_type2 a_pFun, bool optimizeAway)
63 :m_pFun((void*)a_pFun)
64 ,m_iArgc(2)
65 ,m_iPri(-1)
66 ,m_eOprtAsct(oaNONE)
67 ,m_iCode(cmFUNC)
68 ,m_iType(tpDBL)
69 ,m_bAllowOpti(optimizeAway)
70 {}
71
72 //---------------------------------------------------------------------------
81 bool optimizeAway,
82 int a_iPrec,
83 EOprtAssociativity a_eOprtAsct)
84 :m_pFun((void*)a_pFun)
85 ,m_iArgc(2)
86 ,m_iPri(a_iPrec)
87 ,m_eOprtAsct(a_eOprtAsct)
88 ,m_iCode(cmOPRT_BIN)
89 ,m_iType(tpDBL)
90 ,m_bAllowOpti(optimizeAway)
91 {}
92
93 //---------------------------------------------------------------------------
94 ParserCallback::ParserCallback(fun_type3 a_pFun, bool optimizeAway)
95 :m_pFun((void*)a_pFun)
96 ,m_iArgc(3)
97 ,m_iPri(-1)
98 ,m_eOprtAsct(oaNONE)
99 ,m_iCode(cmFUNC)
100 ,m_iType(tpDBL)
101 ,m_bAllowOpti(optimizeAway)
102 {}
103
104
105 //---------------------------------------------------------------------------
106 ParserCallback::ParserCallback(fun_type4 a_pFun, bool optimizeAway)
107 :m_pFun((void*)a_pFun)
108 ,m_iArgc(4)
109 ,m_iPri(-1)
110 ,m_eOprtAsct(oaNONE)
111 ,m_iCode(cmFUNC)
112 ,m_iType(tpDBL)
113 ,m_bAllowOpti(optimizeAway)
114 {}
115
116
117 //---------------------------------------------------------------------------
118 ParserCallback::ParserCallback(fun_type5 a_pFun, bool optimizeAway)
119 :m_pFun((void*)a_pFun)
120 ,m_iArgc(5)
121 ,m_iPri(-1)
122 ,m_eOprtAsct(oaNONE)
123 ,m_iCode(cmFUNC)
124 ,m_iType(tpDBL)
125 ,m_bAllowOpti(optimizeAway)
126 {}
127
128 //---------------------------------------------------------------------------
129 ParserCallback::ParserCallback(fun_type6 a_pFun, bool optimizeAway)
130 :m_pFun((void*)a_pFun)
131 ,m_iArgc(6)
132 ,m_iPri(-1)
133 ,m_eOprtAsct(oaNONE)
134 ,m_iCode(cmFUNC)
135 ,m_iType(tpDBL)
136 ,m_bAllowOpti(optimizeAway)
137 {}
138
139 //---------------------------------------------------------------------------
140 ParserCallback::ParserCallback(fun_type7 a_pFun, bool optimizeAway)
141 :m_pFun((void*)a_pFun)
142 ,m_iArgc(7)
143 ,m_iPri(-1)
144 ,m_eOprtAsct(oaNONE)
145 ,m_iCode(cmFUNC)
146 ,m_iType(tpDBL)
147 ,m_bAllowOpti(optimizeAway)
148 {}
149
150 //---------------------------------------------------------------------------
151 ParserCallback::ParserCallback(fun_type8 a_pFun, bool optimizeAway)
152 :m_pFun((void*)a_pFun)
153 ,m_iArgc(8)
154 ,m_iPri(-1)
155 ,m_eOprtAsct(oaNONE)
156 ,m_iCode(cmFUNC)
157 ,m_iType(tpDBL)
158 ,m_bAllowOpti(optimizeAway)
159 {}
160
161 //---------------------------------------------------------------------------
162 ParserCallback::ParserCallback(fun_type9 a_pFun, bool optimizeAway)
163 :m_pFun((void*)a_pFun)
164 ,m_iArgc(9)
165 ,m_iPri(-1)
166 ,m_eOprtAsct(oaNONE)
167 ,m_iCode(cmFUNC)
168 ,m_iType(tpDBL)
169 ,m_bAllowOpti(optimizeAway)
170 {}
171
172 //---------------------------------------------------------------------------
174 :m_pFun((void*)a_pFun)
175 ,m_iArgc(10)
176 ,m_iPri(-1)
177 ,m_eOprtAsct(oaNONE)
178 ,m_iCode(cmFUNC)
179 ,m_iType(tpDBL)
180 ,m_bAllowOpti(optimizeAway)
181 {}
182
183 //---------------------------------------------------------------------------
185 :m_pFun((void*)a_pFun)
186 ,m_iArgc(0)
187 ,m_iPri(-1)
188 ,m_eOprtAsct(oaNONE)
189 ,m_iCode(cmFUNC_BULK)
190 ,m_iType(tpDBL)
191 ,m_bAllowOpti(optimizeAway)
192 {}
193
194 //---------------------------------------------------------------------------
196 :m_pFun((void*)a_pFun)
197 ,m_iArgc(1)
198 ,m_iPri(-1)
199 ,m_eOprtAsct(oaNONE)
200 ,m_iCode(cmFUNC_BULK)
201 ,m_iType(tpDBL)
202 ,m_bAllowOpti(optimizeAway)
203 {}
204
205
206 //---------------------------------------------------------------------------
211 :m_pFun((void*)a_pFun)
212 ,m_iArgc(2)
213 ,m_iPri(-1)
214 ,m_eOprtAsct(oaNONE)
215 ,m_iCode(cmFUNC_BULK)
216 ,m_iType(tpDBL)
217 ,m_bAllowOpti(optimizeAway)
218 {}
219
220 //---------------------------------------------------------------------------
222 :m_pFun((void*)a_pFun)
223 ,m_iArgc(3)
224 ,m_iPri(-1)
225 ,m_eOprtAsct(oaNONE)
226 ,m_iCode(cmFUNC_BULK)
227 ,m_iType(tpDBL)
228 ,m_bAllowOpti(optimizeAway)
229 {}
230
231
232 //---------------------------------------------------------------------------
234 :m_pFun((void*)a_pFun)
235 ,m_iArgc(4)
236 ,m_iPri(-1)
237 ,m_eOprtAsct(oaNONE)
238 ,m_iCode(cmFUNC_BULK)
239 ,m_iType(tpDBL)
240 ,m_bAllowOpti(optimizeAway)
241 {}
242
243
244 //---------------------------------------------------------------------------
246 :m_pFun((void*)a_pFun)
247 ,m_iArgc(5)
248 ,m_iPri(-1)
249 ,m_eOprtAsct(oaNONE)
250 ,m_iCode(cmFUNC_BULK)
251 ,m_iType(tpDBL)
252 ,m_bAllowOpti(optimizeAway)
253 {}
254
255 //---------------------------------------------------------------------------
257 :m_pFun((void*)a_pFun)
258 ,m_iArgc(6)
259 ,m_iPri(-1)
260 ,m_eOprtAsct(oaNONE)
261 ,m_iCode(cmFUNC_BULK)
262 ,m_iType(tpDBL)
263 ,m_bAllowOpti(optimizeAway)
264 {}
265
266 //---------------------------------------------------------------------------
268 :m_pFun((void*)a_pFun)
269 ,m_iArgc(7)
270 ,m_iPri(-1)
271 ,m_eOprtAsct(oaNONE)
272 ,m_iCode(cmFUNC_BULK)
273 ,m_iType(tpDBL)
274 ,m_bAllowOpti(optimizeAway)
275 {}
276
277 //---------------------------------------------------------------------------
279 :m_pFun((void*)a_pFun)
280 ,m_iArgc(8)
281 ,m_iPri(-1)
282 ,m_eOprtAsct(oaNONE)
283 ,m_iCode(cmFUNC_BULK)
284 ,m_iType(tpDBL)
285 ,m_bAllowOpti(optimizeAway)
286 {}
287
288 //---------------------------------------------------------------------------
290 :m_pFun((void*)a_pFun)
291 ,m_iArgc(9)
292 ,m_iPri(-1)
293 ,m_eOprtAsct(oaNONE)
294 ,m_iCode(cmFUNC_BULK)
295 ,m_iType(tpDBL)
296 ,m_bAllowOpti(optimizeAway)
297 {}
298
299 //---------------------------------------------------------------------------
301 :m_pFun((void*)a_pFun)
302 ,m_iArgc(10)
303 ,m_iPri(-1)
304 ,m_eOprtAsct(oaNONE)
305 ,m_iCode(cmFUNC_BULK)
306 ,m_iType(tpDBL)
307 ,m_bAllowOpti(optimizeAway)
308 {}
309
310
311 //---------------------------------------------------------------------------
313 :m_pFun((void*)a_pFun)
314 ,m_iArgc(-1)
315 ,m_iPri(-1)
316 ,m_eOprtAsct(oaNONE)
317 ,m_iCode(cmFUNC)
318 ,m_iType(tpDBL)
319 ,m_bAllowOpti(optimizeAway)
320 {}
321
322
323 //---------------------------------------------------------------------------
325 :m_pFun((void*)a_pFun)
326 ,m_iArgc(0)
327 ,m_iPri(-1)
328 ,m_eOprtAsct(oaNONE)
329 ,m_iCode(cmFUNC_STR)
330 ,m_iType(tpSTR)
331 ,m_bAllowOpti(optimizeAway)
332 {}
333
334
335 //---------------------------------------------------------------------------
337 :m_pFun((void*)a_pFun)
338 ,m_iArgc(1)
339 ,m_iPri(-1)
340 ,m_eOprtAsct(oaNONE)
341 ,m_iCode(cmFUNC_STR)
342 ,m_iType(tpSTR)
343 ,m_bAllowOpti(optimizeAway)
344 {}
345
346
347 //---------------------------------------------------------------------------
349 :m_pFun((void*)a_pFun)
350 ,m_iArgc(2)
351 ,m_iPri(-1)
352 ,m_eOprtAsct(oaNONE)
353 ,m_iCode(cmFUNC_STR)
354 ,m_iType(tpSTR)
355 ,m_bAllowOpti(optimizeAway)
356 {}
357
358
359 //---------------------------------------------------------------------------
364 :m_pFun(0)
365 ,m_iArgc(0)
366 ,m_iPri(-1)
367 ,m_eOprtAsct(oaNONE)
368 ,m_iCode(cmUNKNOWN)
369 ,m_iType(tpVOID)
370 ,m_bAllowOpti(0)
371 {}
372
373
374 //---------------------------------------------------------------------------
379 {
380 m_pFun = ref.m_pFun;
381 m_iArgc = ref.m_iArgc;
383 m_iCode = ref.m_iCode;
384 m_iType = ref.m_iType;
385 m_iPri = ref.m_iPri;
387 }
388
389 //---------------------------------------------------------------------------
392 {
393 return new ParserCallback(*this);
394 }
395
396 //---------------------------------------------------------------------------
403 {
404 return m_bAllowOpti;
405 }
406
407 //---------------------------------------------------------------------------
417 {
418 return m_pFun;
419 }
420
421 //---------------------------------------------------------------------------
424 {
425 return m_iCode;
426 }
427
428 //---------------------------------------------------------------------------
430 {
431 return m_iType;
432 }
433
434
435 //---------------------------------------------------------------------------
442 {
443 return m_iPri;
444 }
445
446 //---------------------------------------------------------------------------
453 {
454 return m_eOprtAsct;
455 }
456
457 //---------------------------------------------------------------------------
460 {
461 return m_iArgc;
462 }
463} // namespace mu
Encapsulation of prototypes for a numerical parser function.
void * m_pFun
Pointer to the callback function, casted to void.
EOprtAssociativity GetAssociativity() const
Return the operators associativity.
ParserCallback * Clone() const
Clone this instance and return a pointer to the new instance.
ParserCallback()
Default constructor.
int m_iPri
Valid only for binary and infix operators; Operator precedence.
int GetArgc() const
Returns the number of function Arguments.
ETypeCode GetType() const
bool m_bAllowOpti
Flag indication optimizeability.
EOprtAssociativity m_eOprtAsct
Operator associativity; Valid only for binary operators.
int GetPri() const
Return the operator precedence.
int m_iArgc
Number of numeric function arguments.
bool IsOptimizable() const
Return tru if the function is conservative.
void * GetAddr() const
Get the callback address for the parser function.
ECmdCode GetCode() const
Return the callback code.
Definition of the parser callback class.
Namespace for mathematical applications.
Definition: muParser.cpp:53
value_type(* multfun_type)(const value_type *, int)
Callback type used for functions with a variable argument list.
Definition: muParserDef.h:356
value_type(* fun_type9)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
Definition: muParserDef.h:317
value_type(* fun_type6)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
Definition: muParserDef.h:308
value_type(* bulkfun_type6)(int, int, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with five arguments.
Definition: muParserDef.h:341
value_type(* strfun_type2)(const char_type *, value_type)
Callback type used for functions taking a string and a value as arguments.
Definition: muParserDef.h:362
value_type(* strfun_type3)(const char_type *, value_type, value_type)
Callback type used for functions taking a string and two values as arguments.
Definition: muParserDef.h:365
value_type(* bulkfun_type1)(int, int, value_type)
Callback type used for functions with a single arguments.
Definition: muParserDef.h:326
value_type(* bulkfun_type3)(int, int, value_type, value_type, value_type)
Callback type used for functions with three arguments.
Definition: muParserDef.h:332
value_type(* fun_type10)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
Definition: muParserDef.h:320
value_type(* bulkfun_type9)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with five arguments.
Definition: muParserDef.h:350
value_type(* strfun_type1)(const char_type *)
Callback type used for functions taking a string as an argument.
Definition: muParserDef.h:359
value_type(* bulkfun_type4)(int, int, value_type, value_type, value_type, value_type)
Callback type used for functions with four arguments.
Definition: muParserDef.h:335
value_type(* fun_type2)(const value_type &, const value_type &)
Callback type used for functions with two arguments.
Definition: muParserDef.h:296
value_type(* fun_type7)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
Definition: muParserDef.h:311
value_type(* bulkfun_type5)(int, int, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with five arguments.
Definition: muParserDef.h:338
value_type(* fun_type5)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
Definition: muParserDef.h:305
value_type(* bulkfun_type7)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with five arguments.
Definition: muParserDef.h:344
value_type(* bulkfun_type2)(int, int, value_type, value_type)
Callback type used for functions with two arguments.
Definition: muParserDef.h:329
value_type(* bulkfun_type8)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with five arguments.
Definition: muParserDef.h:347
value_type(* fun_type1)(const value_type &)
Callback type used for functions with a single arguments.
Definition: muParserDef.h:293
ECmdCode
Bytecode values.
Definition: muParserDef.h:153
@ cmFUNC_BULK
Special callbacks for Bulk mode with an additional parameter for the bulk index.
Definition: muParserDef.h:191
@ cmOPRT_BIN
user defined binary operator
Definition: muParserDef.h:193
@ cmUNKNOWN
uninitialized item
Definition: muParserDef.h:197
@ cmFUNC_STR
Code for a function with a string parameter.
Definition: muParserDef.h:190
@ cmFUNC
Code for a generic function item.
Definition: muParserDef.h:189
ETypeCode
Types internally used by the parser.
Definition: muParserDef.h:204
@ tpVOID
Undefined type.
Definition: muParserDef.h:207
@ tpDBL
Floating point variables.
Definition: muParserDef.h:206
@ tpSTR
String type (Function arguments and constants only, no string variables)
Definition: muParserDef.h:205
value_type(* fun_type8)(const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with five arguments.
Definition: muParserDef.h:314
value_type(* bulkfun_type10)(int, int, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with five arguments.
Definition: muParserDef.h:353
value_type(* fun_type4)(const value_type &, const value_type &, const value_type &, const value_type &)
Callback type used for functions with four arguments.
Definition: muParserDef.h:302
value_type(* fun_type0)()
Callback type used for functions without arguments.
Definition: muParserDef.h:290
value_type(* fun_type3)(const value_type &, const value_type &, const value_type &)
Callback type used for functions with three arguments.
Definition: muParserDef.h:299
EOprtAssociativity
Parser operator precedence values.
Definition: muParserDef.h:220
@ oaNONE
Definition: muParserDef.h:223
value_type(* bulkfun_type0)(int, int)
Callback type used for functions without arguments.
Definition: muParserDef.h:323