| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
#ifndef MU_PARSER_INT_H |
| 27 |
#define MU_PARSER_INT_H |
| 28 |
|
| 29 |
#include "muParserBase.h" |
| 30 |
#include <vector> |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
namespace mu |
| 39 |
{ |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
class ParserInt : public ParserBase |
| 47 |
{ |
| 48 |
private: |
| 49 |
static int Round(value_type v) { return (int)(v + ((v>=0) ? 0.5 : -0.5) ); }; |
| 50 |
|
| 51 |
static value_type Abs(value_type); |
| 52 |
static value_type Sign(value_type); |
| 53 |
static value_type Ite(value_type, value_type, value_type); |
| 54 |
|
| 55 |
static value_type UnaryMinus(value_type); |
| 56 |
|
| 57 |
static value_type Sum(const value_type* a_afArg, int a_iArgc); |
| 58 |
static value_type Min(const value_type* a_afArg, int a_iArgc); |
| 59 |
static value_type Max(const value_type* a_afArg, int a_iArgc); |
| 60 |
|
| 61 |
static value_type Add(value_type v1, value_type v2); |
| 62 |
static value_type Sub(value_type v1, value_type v2); |
| 63 |
static value_type Mul(value_type v1, value_type v2); |
| 64 |
static value_type Div(value_type v1, value_type v2); |
| 65 |
static value_type Mod(value_type v1, value_type v2); |
| 66 |
static value_type Pow(value_type v1, value_type v2); |
| 67 |
static value_type Shr(value_type v1, value_type v2); |
| 68 |
static value_type Shl(value_type v1, value_type v2); |
| 69 |
static value_type LogAnd(value_type v1, value_type v2); |
| 70 |
static value_type LogOr(value_type v1, value_type v2); |
| 71 |
static value_type And(value_type v1, value_type v2); |
| 72 |
static value_type Or(value_type v1, value_type v2); |
| 73 |
static value_type Xor(value_type v1, value_type v2); |
| 74 |
static value_type Less(value_type v1, value_type v2); |
| 75 |
static value_type Greater(value_type v1, value_type v2); |
| 76 |
static value_type LessEq(value_type v1, value_type v2); |
| 77 |
static value_type GreaterEq(value_type v1, value_type v2); |
| 78 |
static value_type Equal(value_type v1, value_type v2); |
| 79 |
static value_type NotEqual(value_type v1, value_type v2); |
| 80 |
static value_type Not(value_type v1); |
| 81 |
|
| 82 |
static int IsHexVal(const char_type* a_szExpr, int *a_iPos, value_type *a_iVal); |
| 83 |
static int IsBinVal(const char_type* a_szExpr, int *a_iPos, value_type *a_iVal); |
| 84 |
static int IsVal (const char_type* a_szExpr, int *a_iPos, value_type *a_iVal); |
| 85 |
|
| 86 |
|
| 87 |
template<class TChar> |
| 88 |
class change_dec_sep : public std::numpunct<TChar> |
| 89 |
{ |
| 90 |
public: |
| 91 |
|
| 92 |
explicit change_dec_sep(char_type cDecSep, char_type cThousandsSep = 0, int nGroup = 3) |
| 93 |
:std::numpunct<TChar>() |
| 94 |
,m_cDecPoint(cDecSep) |
| 95 |
,m_cThousandsSep(cThousandsSep) |
| 96 |
,m_nGroup(nGroup) |
| 97 |
{} |
| 98 |
|
| 99 |
protected: |
| 100 |
|
| 101 |
virtual char_type do_decimal_point() const |
| 102 |
{ |
| 103 |
return m_cDecPoint; |
| 104 |
} |
| 105 |
|
| 106 |
virtual char_type do_thousands_sep() const |
| 107 |
{ |
| 108 |
return m_cThousandsSep; |
| 109 |
} |
| 110 |
|
| 111 |
virtual std::string do_grouping() const |
| 112 |
{ |
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
return std::string(1, (char)(m_cThousandsSep > 0 ? m_nGroup : CHAR_MAX)); |
| 119 |
} |
| 120 |
|
| 121 |
private: |
| 122 |
|
| 123 |
int m_nGroup; |
| 124 |
char_type m_cDecPoint; |
| 125 |
char_type m_cThousandsSep; |
| 126 |
}; |
| 127 |
|
| 128 |
public: |
| 129 |
ParserInt(); |
| 130 |
|
| 131 |
virtual void InitFun(); |
| 132 |
virtual void InitOprt(); |
| 133 |
virtual void InitConst(); |
| 134 |
virtual void InitCharSets(); |
| 135 |
}; |
| 136 |
|
| 137 |
} |
| 138 |
|
| 139 |
#endif |
| 140 |
|