OpcUaCanOpen
CANopen OPC-UA server
muParserInt.h
Go to the documentation of this file.
1 /*
2  __________
3  _____ __ __\______ \_____ _______ ______ ____ _______
4  / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5  | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6  |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7  \/ \/ \/ \/
8  Copyright (C) 2004-2013 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 
38 namespace mu
39 {
40 
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);
54  // !! The unary Minus is a MUST, otherwise you can't 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);
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);
78  static value_type Equal(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 
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  // fix for issue 4: https://code.google.com/p/muparser/issues/detail?id=4
114  // courtesy of Jens Bartsch
115  // original code:
116  // return std::string(1, (char)m_nGroup);
117  // new code:
118  return std::string(1, (char)(m_cThousandsSep > 0 ? m_nGroup : CHAR_MAX));
119  }
120 
121  private:
122 
123  int m_nGroup;
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 } // namespace mu
138 
139 #endif
140