muParser API -  1.35
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
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 
28 /** \file
29  \brief Implementation of the parser callback class.
30 */
31 
32 
33 namespace mu
34 {
35  //---------------------------------------------------------------------------
36  ParserCallback::ParserCallback(fun_type0 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
44  {}
45 
46  //---------------------------------------------------------------------------
47  ParserCallback::ParserCallback(fun_type1 a_pFun, bool a_bAllowOpti, 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(a_bAllowOpti)
55  {}
56 
57 
58  //---------------------------------------------------------------------------
59  /** \brief Constructor for constructing function callbacks taking two arguments.
60  \throw nothrow
61  */
62  ParserCallback::ParserCallback(fun_type2 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
70  {}
71 
72  //---------------------------------------------------------------------------
73  /** \brief Constructor for constructing binary operator callbacks.
74  \param a_pFun Pointer to a static function taking two arguments
75  \param a_bAllowOpti A flag indicating this function can be optimized
76  \param a_iPrec The operator precedence
77  \param a_eOprtAsct The operators associativity
78  \throw nothrow
79  */
81  bool a_bAllowOpti,
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(a_bAllowOpti)
91  {}
92 
93  //---------------------------------------------------------------------------
94  ParserCallback::ParserCallback(fun_type3 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
102  {}
103 
104 
105  //---------------------------------------------------------------------------
106  ParserCallback::ParserCallback(fun_type4 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
114  {}
115 
116 
117  //---------------------------------------------------------------------------
118  ParserCallback::ParserCallback(fun_type5 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
126  {}
127 
128  //---------------------------------------------------------------------------
129  ParserCallback::ParserCallback(fun_type6 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
137  {}
138 
139  //---------------------------------------------------------------------------
140  ParserCallback::ParserCallback(fun_type7 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
148  {}
149 
150  //---------------------------------------------------------------------------
151  ParserCallback::ParserCallback(fun_type8 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
159  {}
160 
161  //---------------------------------------------------------------------------
162  ParserCallback::ParserCallback(fun_type9 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
170  {}
171 
172  //---------------------------------------------------------------------------
173  ParserCallback::ParserCallback(fun_type10 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
181  {}
182 
183  //---------------------------------------------------------------------------
184  ParserCallback::ParserCallback(bulkfun_type0 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
192  {}
193 
194  //---------------------------------------------------------------------------
195  ParserCallback::ParserCallback(bulkfun_type1 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
203  {}
204 
205 
206  //---------------------------------------------------------------------------
207  /** \brief Constructor for constructing function callbacks taking two arguments.
208  \throw nothrow
209  */
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(a_bAllowOpti)
218  {}
219 
220  //---------------------------------------------------------------------------
221  ParserCallback::ParserCallback(bulkfun_type3 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
229  {}
230 
231 
232  //---------------------------------------------------------------------------
233  ParserCallback::ParserCallback(bulkfun_type4 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
241  {}
242 
243 
244  //---------------------------------------------------------------------------
245  ParserCallback::ParserCallback(bulkfun_type5 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
253  {}
254 
255  //---------------------------------------------------------------------------
256  ParserCallback::ParserCallback(bulkfun_type6 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
264  {}
265 
266  //---------------------------------------------------------------------------
267  ParserCallback::ParserCallback(bulkfun_type7 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
275  {}
276 
277  //---------------------------------------------------------------------------
278  ParserCallback::ParserCallback(bulkfun_type8 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
286  {}
287 
288  //---------------------------------------------------------------------------
289  ParserCallback::ParserCallback(bulkfun_type9 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
297  {}
298 
299  //---------------------------------------------------------------------------
300  ParserCallback::ParserCallback(bulkfun_type10 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
308  {}
309 
310 
311  //---------------------------------------------------------------------------
312  ParserCallback::ParserCallback(multfun_type a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
320  {}
321 
322 
323  //---------------------------------------------------------------------------
324  ParserCallback::ParserCallback(strfun_type1 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
332  {}
333 
334 
335  //---------------------------------------------------------------------------
336  ParserCallback::ParserCallback(strfun_type2 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
344  {}
345 
346 
347  //---------------------------------------------------------------------------
348  ParserCallback::ParserCallback(strfun_type3 a_pFun, bool a_bAllowOpti)
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(a_bAllowOpti)
356  {}
357 
358 
359  //---------------------------------------------------------------------------
360  /** \brief Default constructor.
361  \throw nothrow
362  */
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  //---------------------------------------------------------------------------
375  /** \brief Copy constructor.
376  \throw nothrow
377  */
379  {
380  m_pFun = ref.m_pFun;
381  m_iArgc = ref.m_iArgc;
382  m_bAllowOpti = ref.m_bAllowOpti;
383  m_iCode = ref.m_iCode;
384  m_iType = ref.m_iType;
385  m_iPri = ref.m_iPri;
386  m_eOprtAsct = ref.m_eOprtAsct;
387  }
388 
389  //---------------------------------------------------------------------------
390  /** \brief Clone this instance and return a pointer to the new instance. */
392  {
393  return new ParserCallback(*this);
394  }
395 
396  //---------------------------------------------------------------------------
397  /** \brief Return tru if the function is conservative.
398 
399  Conservative functions return always the same result for the same argument.
400  \throw nothrow
401  */
403  {
404  return m_bAllowOpti;
405  }
406 
407  //---------------------------------------------------------------------------
408  /** \brief Get the callback address for the parser function.
409 
410  The type of the address is void. It needs to be recasted according to the
411  argument number to the right type.
412 
413  \throw nothrow
414  \return #pFun
415  */
416  void* ParserCallback::GetAddr() const
417  {
418  return m_pFun;
419  }
420 
421  //---------------------------------------------------------------------------
422  /** \brief Return the callback code. */
424  {
425  return m_iCode;
426  }
427 
428  //---------------------------------------------------------------------------
429  ETypeCode ParserCallback::GetType() const
430  {
431  return m_iType;
432  }
433 
434 
435  //---------------------------------------------------------------------------
436  /** \brief Return the operator precedence.
437  \throw nothrown
438 
439  Only valid if the callback token is an operator token (binary or infix).
440  */
442  {
443  return m_iPri;
444  }
445 
446  //---------------------------------------------------------------------------
447  /** \brief Return the operators associativity.
448  \throw nothrown
449 
450  Only valid if the callback token is a binary operator token.
451  */
453  {
454  return m_eOprtAsct;
455  }
456 
457  //---------------------------------------------------------------------------
458  /** \brief Returns the number of function Arguments. */
460  {
461  return m_iArgc;
462  }
463 } // namespace mu
ParserCallback()
Default constructor.
user defined binary operator
Definition: muParserDef.h:189
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:334
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:358
value_type(* fun_type3)(value_type, value_type, value_type)
Callback type used for functions with three arguments.
Definition: muParserDef.h:292
value_type(* bulkfun_type2)(int, int, value_type, value_type)
Callback type used for functions with two arguments.
Definition: muParserDef.h:322
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:343
value_type(* bulkfun_type0)(int, int)
Callback type used for functions without arguments.
Definition: muParserDef.h:316
value_type(* fun_type6)(value_type, value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with five arguments.
Definition: muParserDef.h:301
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:337
ECmdCode GetCode() const
Return the callback code.
bool IsOptimizable() const
Return tru if the function is conservative.
Code for a generic function item.
Definition: muParserDef.h:185
EOprtAssociativity
Parser operator precedence values.
Definition: muParserDef.h:215
ParserCallback * Clone() const
Clone this instance and return a pointer to the new instance.
value_type(* strfun_type1)(const char_type *)
Callback type used for functions taking a string as an argument.
Definition: muParserDef.h:352
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:355
EOprtAssociativity GetAssociativity() const
Return the operators associativity.
ETypeCode
Types internally used by the parser.
Definition: muParserDef.h:199
value_type(* bulkfun_type1)(int, int, value_type)
Callback type used for functions with a single arguments.
Definition: muParserDef.h:319
ECmdCode
Bytecode values.
Definition: muParserDef.h:149
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:328
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:346
String type (Function arguments and constants only, no string variables)
Definition: muParserDef.h:201
Namespace for mathematical applications.
Definition: muParser.cpp:49
Undefined type.
Definition: muParserDef.h:203
Special callbacks for Bulk mode with an additional parameter for the bulk index.
Definition: muParserDef.h:187
value_type(* fun_type8)(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:307
Definition of the parser callback class.
value_type(* fun_type7)(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:304
value_type(* fun_type0)()
Callback type used for functions without arguments.
Definition: muParserDef.h:283
Code for a function with a string parameter.
Definition: muParserDef.h:186
void * GetAddr() const
Get the callback address for the parser function.
value_type(* fun_type4)(value_type, value_type, value_type, value_type)
Callback type used for functions with four arguments.
Definition: muParserDef.h:295
uninitialized item
Definition: muParserDef.h:193
value_type(* fun_type1)(value_type)
Callback type used for functions with a single arguments.
Definition: muParserDef.h:286
value_type(* bulkfun_type3)(int, int, value_type, value_type, value_type)
Callback type used for functions with three arguments.
Definition: muParserDef.h:325
int GetArgc() const
Returns the number of function Arguments.
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:340
value_type(* fun_type5)(value_type, value_type, value_type, value_type, value_type)
Callback type used for functions with five arguments.
Definition: muParserDef.h:298
Floating point variables.
Definition: muParserDef.h:202
value_type(* fun_type2)(value_type, value_type)
Callback type used for functions with two arguments.
Definition: muParserDef.h:289
value_type(* fun_type10)(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:313
Encapsulation of prototypes for a numerical parser function.
int GetPri() const
Return the operator precedence.
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:331
value_type(* fun_type9)(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:310
value_type(* multfun_type)(const value_type *, int)
Callback type used for functions with a variable argument list.
Definition: muParserDef.h:349