NCBI C++ ToolKit
muParserError.h
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /*
2  __________
3  _____ __ __\______ \_____ _______ ______ ____ _______
4  / \ | | \| ___/\__ \ \_ __ \/ ___/_/ __ \\_ __ \
5  | Y Y \| | /| | / __ \_| | \/\___ \ \ ___/ | | \/
6  |__|_| /|____/ |____| (____ /|__| /____ > \___ >|__|
7  \/ \/ \/ \/
8  Copyright (C) 2004-2008 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_ERROR_H
27 #define MU_PARSER_ERROR_H
28 
29 #include <cassert>
30 #include <stdexcept>
31 #include <string>
32 #include <sstream>
33 #include <vector>
34 #include <memory>
35 
36 #include "muParserDef.h"
37 
38 /** \file
39  \brief This file defines the error class used by the parser.
40 */
41 
42 namespace mu
43 {
44 
45 /** \brief Error codes. */
47 {
48  // Formula syntax errors
49  ecUNEXPECTED_OPERATOR = 0, ///< Unexpected binary operator found
50  ecUNASSIGNABLE_TOKEN = 1, ///< Token cant be identified.
51  ecUNEXPECTED_EOF = 2, ///< Unexpected end of formula. (Example: "2+sin(")
52  ecUNEXPECTED_ARG_SEP = 3, ///< An unexpected comma has been found. (Example: "1,23")
53  ecUNEXPECTED_ARG = 4, ///< An unexpected argument has been found
54  ecUNEXPECTED_VAL = 5, ///< An unexpected value token has been found
55  ecUNEXPECTED_VAR = 6, ///< An unexpected variable token has been found
56  ecUNEXPECTED_PARENS = 7, ///< Unexpected Parenthesis, opening or closing
57  ecUNEXPECTED_STR = 8, ///< A string has been found at an inapropriate position
58  ecSTRING_EXPECTED = 9, ///< A string function has been called with a different type of argument
59  ecVAL_EXPECTED = 10, ///< A numerical function has been called with a non value type of argument
60  ecMISSING_PARENS = 11, ///< Missing parens. (Example: "3*sin(3")
61  ecUNEXPECTED_FUN = 12, ///< Unexpected function found. (Example: "sin(8)cos(9)")
62  ecUNTERMINATED_STRING = 13, ///< unterminated string constant. (Example: "3*valueof("hello)")
63  ecTOO_MANY_PARAMS = 14, ///< Too many function parameters
64  ecTOO_FEW_PARAMS = 15, ///< Too few function parameters. (Example: "ite(1<2,2)")
65  ecOPRT_TYPE_CONFLICT = 16, ///< binary operators may only be applied to value items of the same type
66  ecSTR_RESULT = 17, ///< result is a string
67 
68  // Invalid Parser input Parameters
69  ecINVALID_NAME = 18, ///< Invalid function, variable or constant name.
70  ecBUILTIN_OVERLOAD = 19, ///< Trying to overload builtin operator
71  ecINVALID_FUN_PTR = 20, ///< Invalid callback function pointer
72  ecINVALID_VAR_PTR = 21, ///< Invalid variable pointer
73  ecEMPTY_EXPRESSION = 22, ///< The Expression is empty
74  ecNAME_CONFLICT = 23, ///< Name conflict
75  ecOPT_PRI = 24, ///< Invalid operator priority
76  //
77  ecDOMAIN_ERROR = 25, ///< catch division by zero, sqrt(-1), log(0) (currently unused)
78  ecDIV_BY_ZERO = 26, ///< Division by zero (currently unused)
79  ecGENERIC = 27, ///< Generic error
80  ecLOCALE = 28, ///< Conflict with current locale
81 
82  // internal errors
83  ecINTERNAL_ERROR = 29, ///< Internal error of any kind.
84 
85  // The last two are special entries
86  ecCOUNT, ///< This is no error code, It just stores just the total number of error codes
87  ecUNDEFINED = -1 ///< Undefined message, placeholder to detect unassigned error messages
88 };
89 
90 //---------------------------------------------------------------------------
91 /** \brief A class that handles the error messages.
92 */
94 {
95 public:
97 
100  ParserErrorMsg();
101 
102  ~ParserErrorMsg();
103 
104  static const ParserErrorMsg& Instance();
105  string_type operator[](unsigned a_iIdx) const;
106 
107 private:
108  std::vector<string_type> m_vErrMsg; ///< A vector with the predefined error messages
109  static const self_type m_Instance; ///< The instance pointer
110 };
111 
112 //---------------------------------------------------------------------------
113 /** \brief Error class of the parser.
114 
115  Part of the math parser package.
116 
117  \author Ingo Berg
118 */
119 /* final */ class ParserError
120 {
121 private:
122  //------------------------------------------------------------------------------
123  /** \brief Replace all ocuurences of a substring with another string. */
124  void ReplaceSubString( string_type &strSource,
125  const string_type &strFind,
126  const string_type &strReplaceWith);
127  void Reset();
128 
129 public:
130  ParserError();
131  explicit ParserError(EErrorCodes a_iErrc);
132  explicit ParserError(const string_type &sMsg);
133  ParserError( EErrorCodes a_iErrc,
134  const string_type &sTok,
135  const string_type &sFormula = string_type(MUP_T("(formula is not available)")),
136  int a_iPos = -1);
137  ParserError( EErrorCodes a_iErrc,
138  int a_iPos,
139  const string_type &sTok);
140  ParserError( const char_type *a_szMsg,
141  int a_iPos = -1,
142  const string_type &sTok = string_type());
143  ParserError(const ParserError &a_Obj);
144  ParserError& operator=(const ParserError &a_Obj);
145  ~ParserError();
146 
147  void SetFormula(const string_type &a_strFormula);
148  const string_type& GetExpr() const;
149  const string_type& GetMsg() const;
150  std::size_t GetPos() const;
151  const string_type& GetToken() const;
152  EErrorCodes GetCode() const;
153 
154 private:
155  string_type m_strMsg; ///< The message string
156  string_type m_strFormula; ///< Formula string
157  string_type m_strTok; ///< Token related with the error
158  int m_iPos; ///< Formula position related to the error
159  EErrorCodes m_iErrc; ///< Error code
161 };
162 
163 } // namespace mu
164 
165 #endif
166 
A class that handles the error messages.
Definition: muParserError.h:94
ParserErrorMsg self_type
Definition: muParserError.h:96
ParserErrorMsg & operator=(const ParserErrorMsg &)
Assignement operator is deactivated.
static const self_type m_Instance
The instance pointer.
string_type operator[](unsigned a_iIdx) const
static const ParserErrorMsg & Instance()
std::vector< string_type > m_vErrMsg
A vector with the predefined error messages.
Error class of the parser.
EErrorCodes GetCode() const
Return the error code.
void SetFormula(const string_type &a_strFormula)
Set the expression related to this error.
std::size_t GetPos() const
Return the formula position related to the error.
string_type m_strMsg
The message string.
void ReplaceSubString(string_type &strSource, const string_type &strFind, const string_type &strReplaceWith)
Replace all ocuurences of a substring with another string.
const ParserErrorMsg & m_ErrMsg
string_type m_strTok
Token related with the error.
int m_iPos
Formula position related to the error.
string_type m_strFormula
Formula string.
EErrorCodes m_iErrc
Error code.
const string_type & GetMsg() const
Returns the message string for this error.
const string_type & GetExpr() const
gets the expression related tp this error.
const string_type & GetToken() const
Return string related with this token (if available).
ParserError()
Default constructor.
void Reset()
Reset the erro object.
ParserError & operator=(const ParserError &a_Obj)
Assignment operator.
This file contains standard definitions used by the parser.
#define MUP_T
Definition: muParserDef.h:62
Namespace for mathematical applications.
Definition: muParser.h:41
string_type::value_type char_type
The character type used by the parser.
Definition: muParserDef.h:246
EErrorCodes
Error codes.
Definition: muParserError.h:47
@ ecINVALID_NAME
Invalid function, variable or constant name.
Definition: muParserError.h:69
@ ecUNASSIGNABLE_TOKEN
Token cant be identified.
Definition: muParserError.h:50
@ ecMISSING_PARENS
Missing parens. (Example: "3*sin(3")
Definition: muParserError.h:60
@ ecBUILTIN_OVERLOAD
Trying to overload builtin operator.
Definition: muParserError.h:70
@ ecUNEXPECTED_EOF
Unexpected end of formula. (Example: "2+sin(")
Definition: muParserError.h:51
@ ecUNEXPECTED_VAR
An unexpected variable token has been found.
Definition: muParserError.h:55
@ ecNAME_CONFLICT
Name conflict.
Definition: muParserError.h:74
@ ecSTRING_EXPECTED
A string function has been called with a different type of argument.
Definition: muParserError.h:58
@ ecTOO_MANY_PARAMS
Too many function parameters.
Definition: muParserError.h:63
@ ecUNDEFINED
Undefined message, placeholder to detect unassigned error messages.
Definition: muParserError.h:87
@ ecVAL_EXPECTED
A numerical function has been called with a non value type of argument.
Definition: muParserError.h:59
@ ecUNEXPECTED_FUN
Unexpected function found. (Example: "sin(8)cos(9)")
Definition: muParserError.h:61
@ ecSTR_RESULT
result is a string
Definition: muParserError.h:66
@ ecUNEXPECTED_ARG
An unexpected argument has been found.
Definition: muParserError.h:53
@ ecUNEXPECTED_OPERATOR
Unexpected binary operator found.
Definition: muParserError.h:49
@ ecOPRT_TYPE_CONFLICT
binary operators may only be applied to value items of the same type
Definition: muParserError.h:65
@ ecLOCALE
Conflict with current locale.
Definition: muParserError.h:80
@ ecUNEXPECTED_STR
A string has been found at an inapropriate position.
Definition: muParserError.h:57
@ ecUNEXPECTED_PARENS
Unexpected Parenthesis, opening or closing.
Definition: muParserError.h:56
@ ecINTERNAL_ERROR
Internal error of any kind.
Definition: muParserError.h:83
@ ecDOMAIN_ERROR
catch division by zero, sqrt(-1), log(0) (currently unused)
Definition: muParserError.h:77
@ ecINVALID_VAR_PTR
Invalid variable pointer.
Definition: muParserError.h:72
@ ecUNEXPECTED_ARG_SEP
An unexpected comma has been found. (Example: "1,23")
Definition: muParserError.h:52
@ ecOPT_PRI
Invalid operator priority.
Definition: muParserError.h:75
@ ecUNTERMINATED_STRING
unterminated string constant. (Example: "3*valueof("hello)")
Definition: muParserError.h:62
@ ecINVALID_FUN_PTR
Invalid callback function pointer.
Definition: muParserError.h:71
@ ecTOO_FEW_PARAMS
Too few function parameters. (Example: "ite(1<2,2)")
Definition: muParserError.h:64
@ ecCOUNT
This is no error code, It just stores just the total number of error codes.
Definition: muParserError.h:86
@ ecEMPTY_EXPRESSION
The Expression is empty.
Definition: muParserError.h:73
@ ecGENERIC
Generic error.
Definition: muParserError.h:79
@ ecUNEXPECTED_VAL
An unexpected value token has been found.
Definition: muParserError.h:54
@ ecDIV_BY_ZERO
Division by zero (currently unused)
Definition: muParserError.h:78
std::string string_type
The stringtype used by the parser.
Definition: muParserDef.h:234
Modified on Fri Sep 20 14:58:03 2024 by modify_doxy.py rev. 669887