/src/muparser/include/muParserError.h
Line | Count | Source |
1 | | /* |
2 | | |
3 | | _____ __ _____________ _______ ______ ___________ |
4 | | / \| | \____ \__ \\_ __ \/ ___// __ \_ __ \ |
5 | | | Y Y \ | / |_> > __ \| | \/\___ \\ ___/| | \/ |
6 | | |__|_| /____/| __(____ /__| /____ >\___ >__| |
7 | | \/ |__| \/ \/ \/ |
8 | | Copyright (C) 2004 - 2022 Ingo Berg |
9 | | |
10 | | Redistribution and use in source and binary forms, with or without modification, are permitted |
11 | | provided that the following conditions are met: |
12 | | |
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. |
18 | | |
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. |
27 | | */ |
28 | | |
29 | | #ifndef MU_PARSER_ERROR_H |
30 | | #define MU_PARSER_ERROR_H |
31 | | |
32 | | #include <stdexcept> |
33 | | #include <string> |
34 | | #include <sstream> |
35 | | #include <vector> |
36 | | #include <memory> |
37 | | |
38 | | #include "muParserDef.h" |
39 | | |
40 | | #if defined(_MSC_VER) |
41 | | #pragma warning(push) |
42 | | #pragma warning(disable : 4251) // ...needs to have dll-interface to be used by clients of class ... |
43 | | #endif |
44 | | |
45 | | |
46 | | /** \file |
47 | | \brief This file defines the error class used by the parser. |
48 | | */ |
49 | | |
50 | | namespace mu |
51 | | { |
52 | | /** \brief A class that handles the error messages. */ |
53 | | class ParserErrorMsg final |
54 | | { |
55 | | public: |
56 | | static const ParserErrorMsg& Instance(); |
57 | | string_type operator[](unsigned a_iIdx) const; |
58 | | |
59 | | private: |
60 | | ParserErrorMsg& operator=(const ParserErrorMsg&) = delete; |
61 | | ParserErrorMsg(const ParserErrorMsg&) = delete; |
62 | | ParserErrorMsg(); |
63 | | |
64 | 1 | ~ParserErrorMsg() = default; |
65 | | |
66 | | std::vector<string_type> m_vErrMsg; ///< A vector with the predefined error messages |
67 | | }; |
68 | | |
69 | | |
70 | | /** \brief Error class of the parser. |
71 | | |
72 | | Part of the math parser package. |
73 | | */ |
74 | | class API_EXPORT_CXX ParserError |
75 | | { |
76 | | private: |
77 | | |
78 | | /** \brief Replace all ocuurences of a substring with another string. */ |
79 | | void ReplaceSubString(string_type& strSource, const string_type& strFind, const string_type& strReplaceWith); |
80 | | void Reset(); |
81 | | |
82 | | public: |
83 | | |
84 | | ParserError(); |
85 | | explicit ParserError(EErrorCodes a_iErrc); |
86 | | explicit ParserError(const string_type& sMsg); |
87 | | ParserError(EErrorCodes a_iErrc, const string_type& sTok, const string_type& sFormula = string_type(), int a_iPos = -1); |
88 | | ParserError(EErrorCodes a_iErrc, int a_iPos, const string_type& sTok); |
89 | | ParserError(const char_type* a_szMsg, int a_iPos = -1, const string_type& sTok = string_type()); |
90 | | ParserError(const ParserError& a_Obj); |
91 | | |
92 | | ParserError& operator=(const ParserError& a_Obj); |
93 | | ~ParserError(); |
94 | | |
95 | | void SetFormula(const string_type& a_strFormula); |
96 | | const string_type& GetExpr() const; |
97 | | const string_type& GetMsg() const; |
98 | | int GetPos() const; |
99 | | const string_type& GetToken() const; |
100 | | EErrorCodes GetCode() const; |
101 | | |
102 | | private: |
103 | | string_type m_strMsg; ///< The message string |
104 | | string_type m_strFormula; ///< Formula string |
105 | | string_type m_strTok; ///< Token related with the error |
106 | | int m_iPos; ///< Formula position related to the error |
107 | | EErrorCodes m_iErrc; ///< Error code |
108 | | const ParserErrorMsg& m_ErrMsg; |
109 | | }; |
110 | | } // namespace mu |
111 | | |
112 | | #if defined(_MSC_VER) |
113 | | #pragma warning(pop) |
114 | | #endif |
115 | | |
116 | | #endif |
117 | | |