Seamly2D
Code documentation
qmuparserdef.h
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 #ifndef QMUPDEF_H
23 #define QMUPDEF_H
24 
25 #include <QMap>
26 #include <QString>
27 #include <locale>
28 
29 #include "qmuparserfixes.h"
30 
31 /** @file
32  @brief This file contains standard definitions used by the parser.
33 */
34 
35 #define QMUP_VERSION "2.5.0"
36 #define QMUP_VERSION_DATE "20170101; GC"
37 
38 #define QMUP_CHARS "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
39 
40 // Detect whether the compiler supports C++11 noexcept exception specifications.
41 # if defined(__clang__)
42 # if __has_feature(cxx_noexcept)
43 # define QMUP_NOEXCEPT_EXPR(x) noexcept(x) // Clang 3.0 and above have noexcept
44 # endif
45 # elif defined(__GNUC__)
46 # if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && defined(__GXX_EXPERIMENTAL_CXX0X__)
47 # define QMUP_NOEXCEPT_EXPR(x) noexcept(x) // GCC 4.7 and following have noexcept
48 # endif
49 # elif defined(_MSC_FULL_VER) && _MSC_FULL_VER >= 190023026
50 # define QMUP_NOEXCEPT_EXPR(x) noexcept(x) // Visual Studio 2015 and following have noexcept
51 # else
52 # define QMUP_NOEXCEPT_EXPR(x)
53 # endif
54 
55 #ifndef __has_cpp_attribute
56 # define __has_cpp_attribute(x) 0
57 #endif
58 
59 #if __cplusplus > 201402L && __has_cpp_attribute(fallthrough)
60 # define QMUP_FALLTHROUGH [[fallthrough]];
61 #elif defined(Q_CC_CLANG) && __cplusplus >= 201103L
62  /* clang's fallthrough annotations are only available starting in C++11. */
63 # define QMUP_FALLTHROUGH [[clang::fallthrough]];
64 #elif defined(Q_CC_MSVC)
65  /*
66  * MSVC's __fallthrough annotations are checked by /analyze (Code Analysis):
67  * https://msdn.microsoft.com/en-us/library/ms235402%28VS.80%29.aspx
68  */
69 # include <sal.h>
70 # define QMUP_FALLTHROUGH __fallthrough;
71 #elif defined(Q_CC_GNU) && (__GNUC__ >= 7)
72 # define QMUP_FALLTHROUGH [[gnu::fallthrough]];
73 #else
74 # define QMUP_FALLTHROUGH
75 #endif
76 
77 /** @brief If this macro is defined mathematical exceptions (div by zero) will be thrown as exceptions. */
78 //#define QMUP_MATH_EXCEPTIONS
79 
80 /** @brief Activate this option in order to compile with OpenMP support.
81 
82  OpenMP is used only in the bulk mode it may increase the performance a bit.
83 */
84 //#define QMUP_USE_OPENMP
85 
86 /** @brief Definition of the basic parser string type. */
87 #define QMUP_STRING_TYPE std::wstring
88 
89 class QLocale;
90 
91 namespace qmu
92 {
93 //------------------------------------------------------------------------------
94 /** @brief Bytecode values.
95 
96  \attention The order of the operator entries must match the order in ParserBase::c_DefaultOprt!
97 */
99 {
100  // The following are codes for built in binary operators
101  // apart from built in operators the user has the opportunity to
102  // add user defined operators.
103  cmLE = 0, ///< Operator item: less or equal
104  cmGE = 1, ///< Operator item: greater or equal
105  cmNEQ = 2, ///< Operator item: not equal
106  cmEQ = 3, ///< Operator item: equals
107  cmLT = 4, ///< Operator item: less than
108  cmGT = 5, ///< Operator item: greater than
109  cmADD = 6, ///< Operator item: add
110  cmSUB = 7, ///< Operator item: subtract
111  cmMUL = 8, ///< Operator item: multiply
112  cmDIV = 9, ///< Operator item: division
113  cmPOW = 10, ///< Operator item: y to the power of ...
114  cmLAND = 11,
115  cmLOR = 12,
116  cmASSIGN = 13, ///< Operator item: Assignment operator
117  cmBO = 14, ///< Operator item: opening bracket
118  cmBC = 15, ///< Operator item: closing bracket
119  cmIF = 16, ///< For use in the ternary if-then-else operator
120  cmELSE = 17, ///< For use in the ternary if-then-else operator
121  cmENDIF = 18, ///< For use in the ternary if-then-else operator
122  cmARG_SEP = 19, ///< function argument separator
123  cmVAR = 20, ///< variable item
124  cmVAL = 21, ///< value item
125 
126  // For optimization purposes
132 
133  // operators and functions
134  cmFUNC, ///< Code for a generic function item
135  cmFUNC_STR, ///< Code for a function with a string parameter
136  cmFUNC_BULK, ///< Special callbacks for Bulk mode with an additional parameter for the bulk index
137  cmSTRING, ///< Code for a string token
138  cmOPRT_BIN, ///< user defined binary operator
139  cmOPRT_POSTFIX, ///< code for postfix operators
140  cmOPRT_INFIX, ///< code for infix operators
141  cmEND, ///< end of formula
142  cmUNKNOWN ///< uninitialized item
143 };
144 
145 //------------------------------------------------------------------------------
146 /** @brief Types internally used by the parser.
147 */
149 {
150  tpSTR = 0, ///< String type (Function arguments and constants only, no string variables)
151  tpDBL = 1, ///< Floating point variables
152  tpVOID = 2 ///< Undefined type.
153 };
154 
155 //------------------------------------------------------------------------------
157 {
159  pviFULL
160 };
161 
162 //------------------------------------------------------------------------------
163 /** @brief Parser operator precedence values. */
165 {
166  oaLEFT = 0,
167  oaRIGHT = 1,
168  oaNONE = 2
169 };
170 
171 //------------------------------------------------------------------------------
172 /** @brief Parser operator precedence values. */
174 {
175  // binary operators
176  prLOR = 1,
177  prLAND = 2,
178  prLOGIC = 3, ///< logic operators
179  prCMP = 4, ///< comparsion operators
180  prADD_SUB = 5, ///< addition
181  prMUL_DIV = 6, ///< multiplication/division
182  prPOW = 7, ///< power operator priority (highest)
183 
184  // infix operators
185  prINFIX = 6, ///< Signs have a higher priority than ADD_SUB, but lower than power operator
186  prPOSTFIX = 6 ///< Postfix operator priority (currently unused)
187 };
188 
189 //------------------------------------------------------------------------------
190 // basic types
191 
192 /** @brief The stringtype used by the parser.
193 
194  Depends on wether UNICODE is used or not.
195 */
197 
198 /** @brief The character type used by the parser.
199 
200  Depends on wether UNICODE is used or not.
201 */
202 typedef string_type::value_type char_type;
203 
204 /** @brief Typedef for easily using stringstream that respect the parser stringtype. */
205 typedef std::basic_stringstream < char_type, std::char_traits<char_type>, std::allocator<char_type> > stringstream_type;
206 
207 // Data container types
208 
209 /** @brief Type used for storing variables. */
210 typedef std::map<QString, qreal*> varmap_type;
211 
212 /** @brief Type used for storing constants. */
213 typedef std::map<QString, qreal> valmap_type;
214 
215 /** @brief Type for assigning a string name to an index in the internal string table. */
216 typedef std::map<QString, int> strmap_type;
217 
218 // Parser callbacks
219 
220 /** @brief Callback type used for functions without arguments. */
221 typedef qreal ( *generic_fun_type ) ();
222 
223 /** @brief Callback type used for functions without arguments. */
224 typedef qreal ( *fun_type0 ) ();
225 
226 /** @brief Callback type used for functions with a single arguments. */
227 typedef qreal ( *fun_type1 ) ( qreal );
228 
229 /** @brief Callback type used for functions with two arguments. */
230 typedef qreal ( *fun_type2 ) ( qreal, qreal );
231 
232 /** @brief Callback type used for functions with three arguments. */
233 typedef qreal ( *fun_type3 ) ( qreal, qreal, qreal );
234 
235 /** @brief Callback type used for functions with four arguments. */
236 typedef qreal ( *fun_type4 ) ( qreal, qreal, qreal, qreal );
237 
238 /** @brief Callback type used for functions with five arguments. */
239 typedef qreal ( *fun_type5 ) ( qreal, qreal, qreal, qreal, qreal );
240 
241 /** @brief Callback type used for functions with five arguments. */
242 typedef qreal ( *fun_type6 ) ( qreal, qreal, qreal, qreal, qreal, qreal );
243 
244 /** @brief Callback type used for functions with five arguments. */
245 typedef qreal ( *fun_type7 ) ( qreal, qreal, qreal, qreal, qreal, qreal, qreal );
246 
247 /** @brief Callback type used for functions with five arguments. */
248 typedef qreal ( *fun_type8 ) ( qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal );
249 
250 /** @brief Callback type used for functions with five arguments. */
251 typedef qreal ( *fun_type9 ) ( qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal );
252 
253 /** @brief Callback type used for functions with five arguments. */
254 typedef qreal ( *fun_type10 ) ( qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal );
255 
256 /** @brief Callback type used for functions without arguments. */
257 typedef qreal ( *bulkfun_type0 ) ( int, int );
258 
259 /** @brief Callback type used for functions with a single arguments. */
260 typedef qreal ( *bulkfun_type1 ) ( int, int, qreal );
261 
262 /** @brief Callback type used for functions with two arguments. */
263 typedef qreal ( *bulkfun_type2 ) ( int, int, qreal, qreal );
264 
265 /** @brief Callback type used for functions with three arguments. */
266 typedef qreal ( *bulkfun_type3 ) ( int, int, qreal, qreal, qreal );
267 
268 /** @brief Callback type used for functions with four arguments. */
269 typedef qreal ( *bulkfun_type4 ) ( int, int, qreal, qreal, qreal, qreal );
270 
271 /** @brief Callback type used for functions with five arguments. */
272 typedef qreal ( *bulkfun_type5 ) ( int, int, qreal, qreal, qreal, qreal, qreal );
273 
274 /** @brief Callback type used for functions with five arguments. */
275 typedef qreal ( *bulkfun_type6 ) ( int, int, qreal, qreal, qreal, qreal, qreal, qreal );
276 
277 /** @brief Callback type used for functions with five arguments. */
278 typedef qreal ( *bulkfun_type7 ) ( int, int, qreal, qreal, qreal, qreal, qreal, qreal, qreal );
279 
280 /** @brief Callback type used for functions with five arguments. */
281 typedef qreal ( *bulkfun_type8 ) ( int, int, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal );
282 
283 /** @brief Callback type used for functions with five arguments. */
284 typedef qreal ( *bulkfun_type9 ) ( int, int, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal );
285 
286 /** @brief Callback type used for functions with five arguments. */
287 typedef qreal ( *bulkfun_type10 ) ( int, int, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal, qreal );
288 
289 /** @brief Callback type used for functions with a variable argument list. */
290 typedef qreal ( *multfun_type ) ( const qreal*, int );
291 
292 /** @brief Callback type used for functions taking a string as an argument. */
293 typedef qreal ( *strfun_type1 ) ( const QString & );
294 
295 /** @brief Callback type used for functions taking a string and a value as arguments. */
296 typedef qreal ( *strfun_type2 ) ( const QString &, qreal );
297 
298 /** @brief Callback type used for functions taking a string and two values as arguments. */
299 typedef qreal ( *strfun_type3 ) ( const QString &, qreal, qreal );
300 
301 /** @brief Callback used for functions that identify values in a string. */
302 typedef int ( *identfun_type ) ( const QString &sExpr, int *nPos, qreal *fVal, const QLocale &locale,
303  const QChar &decimal, const QChar &thousand );
304 
305 /** @brief Callback used for variable creation factory functions. */
306 typedef qreal* ( *facfun_type ) ( const QString &, void* );
307 } // end of namespace
308 
309 #endif
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
std::map< QString, int > strmap_type
Type for assigning a string name to an index in the internal string table.
Definition: qmuparserdef.h:216
string_type::value_type char_type
The character type used by the parser.
Definition: qmuparserdef.h:202
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
int(* identfun_type)(const QString &sExpr, int *nPos, qreal *fVal, const QLocale &locale, const QChar &decimal, const QChar &thousand)
Callback used for functions that identify values in a string.
Definition: qmuparserdef.h:302
ECmdCode
Bytecode values.
Definition: qmuparserdef.h:99
@ cmVARPOW4
Definition: qmuparserdef.h:129
@ cmOPRT_INFIX
code for infix operators
Definition: qmuparserdef.h:140
@ cmBC
Operator item: closing bracket.
Definition: qmuparserdef.h:118
@ cmLE
Operator item: less or equal.
Definition: qmuparserdef.h:103
@ cmUNKNOWN
uninitialized item
Definition: qmuparserdef.h:142
@ cmSUB
Operator item: subtract.
Definition: qmuparserdef.h:110
@ cmLAND
Definition: qmuparserdef.h:114
@ cmGT
Operator item: greater than.
Definition: qmuparserdef.h:108
@ cmSTRING
Code for a string token.
Definition: qmuparserdef.h:137
@ cmFUNC
Code for a generic function item.
Definition: qmuparserdef.h:134
@ cmVARMUL
Definition: qmuparserdef.h:130
@ cmEND
end of formula
Definition: qmuparserdef.h:141
@ cmFUNC_STR
Code for a function with a string parameter.
Definition: qmuparserdef.h:135
@ cmLT
Operator item: less than.
Definition: qmuparserdef.h:107
@ cmMUL
Operator item: multiply.
Definition: qmuparserdef.h:111
@ cmVARPOW3
Definition: qmuparserdef.h:128
@ cmGE
Operator item: greater or equal.
Definition: qmuparserdef.h:104
@ cmADD
Operator item: add.
Definition: qmuparserdef.h:109
@ cmASSIGN
Operator item: Assignment operator.
Definition: qmuparserdef.h:116
@ cmENDIF
For use in the ternary if-then-else operator.
Definition: qmuparserdef.h:121
@ cmELSE
For use in the ternary if-then-else operator.
Definition: qmuparserdef.h:120
@ cmEQ
Operator item: equals.
Definition: qmuparserdef.h:106
@ cmFUNC_BULK
Special callbacks for Bulk mode with an additional parameter for the bulk index.
Definition: qmuparserdef.h:136
@ cmPOW2
Definition: qmuparserdef.h:131
@ cmARG_SEP
function argument separator
Definition: qmuparserdef.h:122
@ cmPOW
Operator item: y to the power of ...
Definition: qmuparserdef.h:113
@ cmLOR
Definition: qmuparserdef.h:115
@ cmNEQ
Operator item: not equal.
Definition: qmuparserdef.h:105
@ cmVARPOW2
Definition: qmuparserdef.h:127
@ cmOPRT_BIN
user defined binary operator
Definition: qmuparserdef.h:138
@ cmIF
For use in the ternary if-then-else operator.
Definition: qmuparserdef.h:119
@ cmVAL
value item
Definition: qmuparserdef.h:124
@ cmOPRT_POSTFIX
code for postfix operators
Definition: qmuparserdef.h:139
@ cmDIV
Operator item: division.
Definition: qmuparserdef.h:112
@ cmVAR
variable item
Definition: qmuparserdef.h:123
@ cmBO
Operator item: opening bracket.
Definition: qmuparserdef.h:117
std::map< QString, qreal > valmap_type
Type used for storing constants.
Definition: qmuparserdef.h:213
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(* generic_fun_type)()
Callback type used for functions without arguments.
Definition: qmuparserdef.h:221
EParserVersionInfo
Definition: qmuparserdef.h:157
@ pviFULL
Definition: qmuparserdef.h:159
@ pviBRIEF
Definition: qmuparserdef.h:158
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
@ oaLEFT
Definition: qmuparserdef.h:166
@ oaRIGHT
Definition: qmuparserdef.h:167
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
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: qmuparserdef.h:205
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
EOprtPrecedence
Parser operator precedence values.
Definition: qmuparserdef.h:174
@ prPOW
power operator priority (highest)
Definition: qmuparserdef.h:182
@ prLAND
Definition: qmuparserdef.h:177
@ prLOGIC
logic operators
Definition: qmuparserdef.h:178
@ prLOR
Definition: qmuparserdef.h:176
@ prADD_SUB
addition
Definition: qmuparserdef.h:180
@ prPOSTFIX
Postfix operator priority (currently unused)
Definition: qmuparserdef.h:186
@ prCMP
comparsion operators
Definition: qmuparserdef.h:179
@ prINFIX
Signs have a higher priority than ADD_SUB, but lower than power operator.
Definition: qmuparserdef.h:185
@ prMUL_DIV
multiplication/division
Definition: qmuparserdef.h:181
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
std::wstring string_type
The stringtype used by the parser.
Definition: qmuparserdef.h:196
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
ETypeCode
Types internally used by the parser.
Definition: qmuparserdef.h:149
@ 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
std::map< QString, qreal * > varmap_type
Type used for storing variables.
Definition: qmuparserdef.h:210
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
#define QMUP_STRING_TYPE
If this macro is defined mathematical exceptions (div by zero) will be thrown as exceptions.
Definition: qmuparserdef.h:87
This file contains compatibility fixes for some platforms.