NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
muParserDef.h
Go to the documentation of this file.
1/*
2 __________
3 _____ __ __\______ \_____ _______ ______ ____ _______
4 / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5 | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6 |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7 \/ \/ \/ \/
8 Copyright (C) 2012 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#ifndef MUP_DEF_H
26#define MUP_DEF_H
27
28#include <iostream>
29#include <string>
30#include <sstream>
31#include <map>
32#include <complex>
33#include <vector>
34
35#include "muParserFixes.h"
36
41#define MUP_VERSION _nrT("2.2.2")
42#define MUP_VERSION_DATE _nrT("20120218; SF")
43
44#define MUP_CHARS _nrT("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ")
45
47//#define MUP_MATH_EXCEPTIONS
48
54#define MUP_BASETYPE std::complex<double>
55
60//#define MUP_USE_OPENMP
61
62#define _nrT(x) x
63#if defined(_UNICODE)
65#define MUP_STRING_TYPE std::string //std::wstring
66
67#if !defined(_T)
68#define _T(x) x//L##x
69#endif // not defined _T
70#else
71#ifndef _T
72#define _T(x) x
73#endif
74
76#define MUP_STRING_TYPE std::string
77#endif
78
79#if defined(_DEBUG)
82#define MUP_FAIL(MSG) \
83 { \
84 bool MSG=false; \
85 assert(MSG); \
86 }
87
93#define MUP_ASSERT(COND) \
94 if (!(COND)) \
95 { \
96 stringstream_type ss; \
97 ss << _T("Assertion \"") _T(#COND) _T("\" failed: ") \
98 << __FILE__ << _T(" line ") \
99 << __LINE__ << _T("."); \
100 throw ParserError( ss.str() ); \
101 }
102#else
103#define MUP_FAIL(MSG)
104#define MUP_ASSERT(COND)
105#endif
106
107
108namespace mu
109{
110#if defined(_UNICODE)
111
112 //------------------------------------------------------------------------------
114 inline std::wostream& console()
115 {
116 return std::wcout;
117 }
118
120 inline std::wistream& console_in()
121 {
122 return std::wcin;
123 }
124
125#else
126
131 inline std::ostream& console()
132 {
133 return std::cout;
134 }
135
140 inline std::istream& console_in()
141 {
142 return std::cin;
143 }
144
145#endif
146
147 //------------------------------------------------------------------------------
153 {
154 // The following are codes for built in binary operators
155 // apart from built in operators the user has the opportunity to
156 // add user defined operators.
178
179 // Variable and optimization block
187
188 // operators and functions
197 cmUNKNOWN
198 };
199
200 //------------------------------------------------------------------------------
204 {
205 tpSTR = 0,
206 tpDBL = 1,
207 tpVOID = 2
208 };
209
210 //------------------------------------------------------------------------------
212 {
214 pviFULL
215 };
216
217 //------------------------------------------------------------------------------
220 {
223 oaNONE = 2
224 };
225
226 //------------------------------------------------------------------------------
229 {
230 // binary operators
231 prLOR = 1,
234 prCMP = 4,
237 prPOW = 7,
238
239 // infix operators
241 prPOSTFIX = 6
242 };
243
244 //------------------------------------------------------------------------------
245 // basic types
246
252
257 typedef std::string string_type;
258
264
266 typedef std::basic_stringstream<char_type,
267 std::char_traits<char_type>,
268 std::allocator<char_type> > stringstream_type;
269
270 // Data container types
271
273 typedef std::map<string_type, value_type*> varmap_type;
274
276 typedef std::map<string_type, value_type> valmap_type;
277
279 typedef std::map<string_type, std::size_t> strmap_type;
280
282 typedef std::vector<value_type> valbuf_type;
283
284 // Parser callbacks
285
288
290 typedef value_type (*fun_type0)();
291
293 typedef value_type (*fun_type1)(const value_type&);
294
296 typedef value_type (*fun_type2)(const value_type&, const value_type&);
297
299 typedef value_type (*fun_type3)(const value_type&, const value_type&, const value_type&);
300
302 typedef value_type (*fun_type4)(const value_type&, const value_type&, const value_type&, const value_type&);
303
305 typedef value_type (*fun_type5)(const value_type&, const value_type&, const value_type&, const value_type&, const value_type&);
306
308 typedef value_type (*fun_type6)(const value_type&, const value_type&, const value_type&, const value_type&, const value_type&, const value_type&);
309
311 typedef 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&);
312
314 typedef 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&);
315
317 typedef 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&);
318
320 typedef 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&);
321
323 typedef value_type (*bulkfun_type0)(int, int);
324
326 typedef value_type (*bulkfun_type1)(int, int, value_type);
327
330
333
336
339
342
345
348
351
354
356 typedef value_type (*multfun_type)(const value_type*, int);
357
360
363
366
368 typedef int (*identfun_type)(const char_type* sExpr, int* nPos, value_type* fVal);
369
371 typedef value_type* (*facfun_type)(const char_type*, void*);
372
373 // Forward declarations
374 inline bool isinf(const value_type& v)
375 {
376 return std::isinf(v.real()) || std::isinf(v.imag());
377 }
378
379 inline bool isnan(const value_type& v)
380 {
381 return v != v;
382 }
383
384 inline bool isreal(value_type* v, int nElem)
385 {
386 for (int i = 0; i < nElem; i++)
387 {
388 if (v[i].imag())
389 return false;
390 }
391
392 return true;
393 }
394
395 std::vector<double> real(const std::vector<value_type>& vVec);
396 std::vector<double> imag(const std::vector<value_type>& vVec);
398
399} // end of namespace
400
401#endif
402
403
404
#define MUP_BASETYPE
If this macro is defined mathematical exceptions (div by zero) will be thrown as exceptions.
Definition: muParserDef.h:54
This file contains compatibility fixes for some platforms.
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
std::istream & console_in()
Encapsulate cin.
Definition: muParserDef.h:140
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
int(* identfun_type)(const char_type *sExpr, int *nPos, value_type *fVal)
Callback used for functions that identify values in a string.
Definition: muParserDef.h:368
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
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
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
bool isnan(const value_type &v)
Definition: muParserDef.h:379
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
std::map< string_type, value_type > valmap_type
Type used for storing constants.
Definition: muParserDef.h:276
std::vector< double > real(const std::vector< value_type > &vVec)
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
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:263
std::vector< double > imag(const std::vector< value_type > &vVec)
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
std::vector< value_type > valbuf_type
Type used for storing an array of values.
Definition: muParserDef.h:282
bool isinf(const value_type &v)
Definition: muParserDef.h:374
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
std::basic_stringstream< char_type, std::char_traits< char_type >, std::allocator< char_type > > stringstream_type
Typedef for easily using stringstream that respect the parser stringtype.
Definition: muParserDef.h:268
std::map< string_type, value_type * > varmap_type
Type used for storing variables.
Definition: muParserDef.h:273
ECmdCode
Bytecode values.
Definition: muParserDef.h:153
@ cmVARMUL
Definition: muParserDef.h:185
@ cmVARPOW2
Definition: muParserDef.h:181
@ cmFUNC_BULK
Special callbacks for Bulk mode with an additional parameter for the bulk index.
Definition: muParserDef.h:191
@ cmADD
Operator item: add.
Definition: muParserDef.h:163
@ cmGE
Operator item: greater or equal.
Definition: muParserDef.h:158
@ cmLT
Operator item: less than.
Definition: muParserDef.h:161
@ cmPOW
Operator item: y to the power of ...
Definition: muParserDef.h:167
@ cmASSIGN
Operator item: Assignment operator.
Definition: muParserDef.h:170
@ cmLAND
Definition: muParserDef.h:168
@ cmARG_SEP
function argument separator
Definition: muParserDef.h:176
@ cmLE
Operator item: less or equal.
Definition: muParserDef.h:157
@ cmBO
Operator item: opening bracket.
Definition: muParserDef.h:171
@ cmMUL
Operator item: multiply.
Definition: muParserDef.h:165
@ cmEND
end of formula
Definition: muParserDef.h:196
@ cmSTRING
Code for a string token.
Definition: muParserDef.h:192
@ cmDIV
Operator item: division.
Definition: muParserDef.h:166
@ cmLOR
Definition: muParserDef.h:169
@ cmENDIF
For use in the ternary if-then-else operator.
Definition: muParserDef.h:175
@ cmVAR_END
Only for identifying the end of the variable block.
Definition: muParserDef.h:186
@ cmOPRT_INFIX
code for infix operators
Definition: muParserDef.h:195
@ cmBC
Operator item: closing bracket.
Definition: muParserDef.h:172
@ cmOPRT_BIN
user defined binary operator
Definition: muParserDef.h:193
@ cmVAL
value item
Definition: muParserDef.h:177
@ cmIF
For use in the ternary if-then-else operator.
Definition: muParserDef.h:173
@ cmUNKNOWN
uninitialized item
Definition: muParserDef.h:197
@ cmNEQ
Operator item: not equal.
Definition: muParserDef.h:159
@ cmGT
Operator item: greater than.
Definition: muParserDef.h:162
@ cmEQ
Operator item: equals.
Definition: muParserDef.h:160
@ cmVARPOWN
Definition: muParserDef.h:184
@ cmSUB
Operator item: subtract.
Definition: muParserDef.h:164
@ cmVARPOW3
Definition: muParserDef.h:182
@ 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
@ cmVARPOW4
Definition: muParserDef.h:183
@ cmOPRT_POSTFIX
code for postfix operators
Definition: muParserDef.h:194
@ cmELSE
For use in the ternary if-then-else operator.
Definition: muParserDef.h:174
@ cmVAR
variable item
Definition: muParserDef.h:180
EParserVersionInfo
Definition: muParserDef.h:212
@ pviFULL
Definition: muParserDef.h:214
@ pviBRIEF
Definition: muParserDef.h:213
std::ostream & console()
Encapsulate cout.
Definition: muParserDef.h:131
value_type rint(value_type v)
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(* generic_fun_type)()
Callback type used for functions without arguments.
Definition: muParserDef.h:287
std::string string_type
The stringtype used by the parser.
Definition: muParserDef.h:257
std::map< string_type, std::size_t > strmap_type
Type for assigning a string name to an index in the internal string table.
Definition: muParserDef.h:279
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
EOprtPrecedence
Parser operator precedence values.
Definition: muParserDef.h:229
@ prPOSTFIX
Postfix operator priority (currently unused)
Definition: muParserDef.h:241
@ prLOR
Definition: muParserDef.h:231
@ prINFIX
Signs have a higher priority than ADD_SUB, but lower than power operator.
Definition: muParserDef.h:240
@ prCMP
comparsion operators
Definition: muParserDef.h:234
@ prLOGIC
logic operators
Definition: muParserDef.h:233
@ prPOW
power operator priority (highest)
Definition: muParserDef.h:237
@ prADD_SUB
addition
Definition: muParserDef.h:235
@ prMUL_DIV
multiplication/division
Definition: muParserDef.h:236
@ prLAND
Definition: muParserDef.h:232
bool isreal(value_type *v, int nElem)
Definition: muParserDef.h:384
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
@ oaLEFT
Definition: muParserDef.h:221
@ oaNONE
Definition: muParserDef.h:223
@ oaRIGHT
Definition: muParserDef.h:222
value_type(* bulkfun_type0)(int, int)
Callback type used for functions without arguments.
Definition: muParserDef.h:323