3 _____ __ _____________ _______ ______ ___________
4 / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \
5 | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/
6 |__|_| /____/| __(____ /__| /____ >\___ >__|
8 Copyright (C) 2004 - 2020 Ingo Berg
10 Redistribution and use in source and binary forms, with or without modification, are permitted
11 provided that the following conditions are met:
13 * Redistributions of source code must retain the above copyright notice, this list of
14 conditions and the following disclaimer.
15 * Redistributions in binary form must reproduce the above copyright notice, this list of
16 conditions and the following disclaimer in the documentation and/or other materials provided
17 with the distribution.
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
22 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
25 IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
26 OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #ifndef MU_PARSER_INT_H
30 #define MU_PARSER_INT_H
32 #include "muParserBase.h"
37 \brief Definition of a parser using integer value.
44 /** \brief Mathematical expressions parser.
46 This version of the parser handles only integer numbers. It disables the built in operators thus it is
47 slower than muParser. Integer values are stored in the double value_type and converted if needed.
49 class ParserInt
: public ParserBase
52 static int Round(value_type v
) { return (int)(v
+ ((v
>= 0) ? 0.5 : -0.5)); };
54 static value_type
Abs(value_type
);
55 static value_type
Sign(value_type
);
56 static value_type
Ite(value_type
, value_type
, value_type
);
57 // !! The unary Minus is a MUST, otherwise you can't use negative signs !!
58 static value_type
UnaryMinus(value_type
);
59 // Functions with variable number of arguments
60 static value_type
Sum(const value_type
* a_afArg
, int a_iArgc
); // sum
61 static value_type
Min(const value_type
* a_afArg
, int a_iArgc
); // minimum
62 static value_type
Max(const value_type
* a_afArg
, int a_iArgc
); // maximum
63 // binary operator callbacks
64 static value_type
Add(value_type v1
, value_type v2
);
65 static value_type
Sub(value_type v1
, value_type v2
);
66 static value_type
Mul(value_type v1
, value_type v2
);
67 static value_type
Div(value_type v1
, value_type v2
);
68 static value_type
Mod(value_type v1
, value_type v2
);
69 static value_type
Pow(value_type v1
, value_type v2
);
70 static value_type
Shr(value_type v1
, value_type v2
);
71 static value_type
Shl(value_type v1
, value_type v2
);
72 static value_type
LogAnd(value_type v1
, value_type v2
);
73 static value_type
LogOr(value_type v1
, value_type v2
);
74 static value_type
And(value_type v1
, value_type v2
);
75 static value_type
Or(value_type v1
, value_type v2
);
76 static value_type
Xor(value_type v1
, value_type v2
);
77 static value_type
Less(value_type v1
, value_type v2
);
78 static value_type
Greater(value_type v1
, value_type v2
);
79 static value_type
LessEq(value_type v1
, value_type v2
);
80 static value_type
GreaterEq(value_type v1
, value_type v2
);
81 static value_type
Equal(value_type v1
, value_type v2
);
82 static value_type
NotEqual(value_type v1
, value_type v2
);
83 static value_type
Not(value_type v1
);
85 static int IsHexVal(const char_type
* a_szExpr
, int* a_iPos
, value_type
* a_iVal
);
86 static int IsBinVal(const char_type
* a_szExpr
, int* a_iPos
, value_type
* a_iVal
);
87 static int IsVal(const char_type
* a_szExpr
, int* a_iPos
, value_type
* a_iVal
);
89 /** \brief A facet class used to change decimal and thousands separator. */
91 class change_dec_sep
: public std::numpunct
<TChar
>
95 explicit change_dec_sep(char_type cDecSep
, char_type cThousandsSep
= 0, int nGroup
= 3)
96 :std::numpunct
<TChar
>()
97 , m_cDecPoint(cDecSep
)
98 , m_cThousandsSep(cThousandsSep
)
104 virtual char_type
do_decimal_point() const
109 virtual char_type
do_thousands_sep() const
111 return m_cThousandsSep
;
114 virtual std::string
do_grouping() const
116 // fix for issue 4: https://code.google.com/p/muparser/issues/detail?id=4
117 // courtesy of Jens Bartsch
119 // return std::string(1, (char)m_nGroup);
121 return std::string(1, (char)(m_cThousandsSep
> 0 ? m_nGroup
: CHAR_MAX
));
127 char_type m_cDecPoint
;
128 char_type m_cThousandsSep
;
134 virtual void InitFun();
135 virtual void InitOprt();
136 virtual void InitConst();
137 virtual void InitCharSets();