NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
muParserInt.h
Go to the documentation of this file.
1/*
2 __________
3 _____ __ __\______ \_____ _______ ______ ____ _______
4 / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5 | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6 |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7 \/ \/ \/ \/
8 Copyright (C) 2004-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
26#ifndef MU_PARSER_INT_H
27#define MU_PARSER_INT_H
28
29#include "muParserBase.h"
30#include <vector>
31
32
38namespace mu
39{
40
46class ParserInt : public ParserBase
47{
48private:
49 static int Round(value_type v) { return (int)(v + ((v>=0) ? 0.5 : -0.5) ); };
50
54 // !! The unary Minus is a MUST, otherwise you cant use negative signs !!
56 // Functions with variable number of arguments
57 static value_type Sum(const value_type* a_afArg, int a_iArgc); // sum
58 static value_type Min(const value_type* a_afArg, int a_iArgc); // minimum
59 static value_type Max(const value_type* a_afArg, int a_iArgc); // maximum
60 // binary operator callbacks
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);
71 static value_type And(value_type v1, value_type v2);
72 static value_type Or(value_type v1, value_type v2);
74 static value_type Less(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
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
102 {
103 return m_cDecPoint;
104 }
105
107 {
108 return m_cThousandsSep;
109 }
110
111 virtual std::string do_grouping() const
112 {
113 return std::string(1, m_nGroup);
114 }
115
116 private:
117
121 };
122
123public:
124 ParserInt();
125
126 virtual void InitFun();
127 virtual void InitOprt();
128 virtual void InitConst();
129 virtual void InitCharSets();
130};
131
132} // namespace mu
133
134#endif
135
Mathematical expressions parser (base parser engine).
Definition: muParserBase.h:69
A facet class used to change decimal and thousands separator.
Definition: muParserInt.h:89
virtual char_type do_decimal_point() const
Definition: muParserInt.h:101
virtual char_type do_thousands_sep() const
Definition: muParserInt.h:106
change_dec_sep(char_type cDecSep, char_type cThousandsSep=0, int nGroup=3)
Definition: muParserInt.h:92
virtual std::string do_grouping() const
Definition: muParserInt.h:111
Mathematical expressions parser.
Definition: muParserInt.h:47
static int IsHexVal(const char_type *a_szExpr, int *a_iPos, value_type *a_iVal)
Check a given position in the expression for the presence of a hex value.
static value_type Abs(value_type)
Definition: muParserInt.cpp:41
static value_type Xor(value_type v1, value_type v2)
static value_type LessEq(value_type v1, value_type v2)
Definition: muParserInt.cpp:59
static value_type GreaterEq(value_type v1, value_type v2)
Definition: muParserInt.cpp:60
ParserInt()
Constructor.
static value_type Shl(value_type v1, value_type v2)
Definition: muParserInt.cpp:52
static value_type Not(value_type v1)
Definition: muParserInt.cpp:63
static value_type Div(value_type v1, value_type v2)
Definition: muParserInt.cpp:49
static value_type Mul(value_type v1, value_type v2)
Definition: muParserInt.cpp:48
static value_type NotEqual(value_type v1, value_type v2)
Definition: muParserInt.cpp:62
virtual void InitConst()
static value_type Shr(value_type v1, value_type v2)
Definition: muParserInt.cpp:51
static value_type UnaryMinus(value_type)
Definition: muParserInt.cpp:72
static value_type Or(value_type v1, value_type v2)
Definition: muParserInt.cpp:56
static value_type Greater(value_type v1, value_type v2)
Definition: muParserInt.cpp:58
static value_type And(value_type v1, value_type v2)
Definition: muParserInt.cpp:55
static value_type Add(value_type v1, value_type v2)
Definition: muParserInt.cpp:46
static value_type Mod(value_type v1, value_type v2)
Definition: muParserInt.cpp:50
static value_type Max(const value_type *a_afArg, int a_iArgc)
virtual void InitOprt()
Initialize operators.
virtual void InitCharSets()
static value_type Sub(value_type v1, value_type v2)
Definition: muParserInt.cpp:47
static value_type LogOr(value_type v1, value_type v2)
Definition: muParserInt.cpp:54
static value_type Ite(value_type, value_type, value_type)
Definition: muParserInt.cpp:43
static value_type Pow(value_type v1, value_type v2)
Definition: muParserInt.cpp:65
static value_type Min(const value_type *a_afArg, int a_iArgc)
Definition: muParserInt.cpp:91
static value_type Equal(value_type v1, value_type v2)
Definition: muParserInt.cpp:61
static value_type Sign(value_type)
Definition: muParserInt.cpp:42
static value_type Sum(const value_type *a_afArg, int a_iArgc)
Definition: muParserInt.cpp:78
static value_type Less(value_type v1, value_type v2)
Definition: muParserInt.cpp:57
static value_type LogAnd(value_type v1, value_type v2)
Definition: muParserInt.cpp:53
static int IsBinVal(const char_type *a_szExpr, int *a_iPos, value_type *a_iVal)
static int IsVal(const char_type *a_szExpr, int *a_iPos, value_type *a_iVal)
virtual void InitFun()
Initialize the default functions.
static int Round(value_type v)
Definition: muParserInt.h:49
This file contains the class definition of the muparser engine.
Namespace for mathematical applications.
Definition: muParser.cpp:53
MUP_BASETYPE value_type
The numeric datatype used by the parser.
Definition: muParserDef.h:251
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:263