~ubuntu-branches/ubuntu/karmic/kst/karmic

« back to all changes in this revision

Viewing changes to kst/plugins/fits_nonlinear/general_levenberg_marquardt/muParserError.h

  • Committer: Bazaar Package Importer
  • Author(s): Daniel T Chen
  • Date: 2006-06-30 19:11:30 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060630191130-acumuar75bz4puty
Tags: 1.2.1-1ubuntu1
Merge from debian unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
  Copyright (C) 2004, 2005 Ingo Berg
 
3
 
 
4
  Permission is hereby granted, free of charge, to any person obtaining a copy of this 
 
5
  software and associated documentation files (the "Software"), to deal in the Software
 
6
  without restriction, including without limitation the rights to use, copy, modify, 
 
7
  merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 
 
8
  permit persons to whom the Software is furnished to do so, subject to the following conditions:
 
9
 
 
10
  The above copyright notice and this permission notice shall be included in all copies or 
 
11
  substantial portions of the Software.
 
12
 
 
13
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
 
14
  NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 
 
15
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, 
 
16
  DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 
 
17
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 
 
18
*/
 
19
#ifndef MU_PARSER_ERROR_H
 
20
#define MU_PARSER_ERROR_H
 
21
 
 
22
#include <cassert>
 
23
#include <stdexcept>
 
24
#include <string>
 
25
#include <sstream>
 
26
#include <vector>
 
27
#include <memory>
 
28
 
 
29
#include "muParserDef.h"
 
30
 
 
31
 
 
32
namespace mu
 
33
{
 
34
 
 
35
/** \brief Error codes. */
 
36
enum EErrorCodes
 
37
{
 
38
  // Formula syntax errors
 
39
  ecUNEXPECTED_OPERATOR =  0, ///< Unexpected binary operator found
 
40
  ecUNASSIGNABLE_TOKEN,       ///< Token cant be identified.
 
41
  ecUNEXPECTED_EOF,           ///< Unexpected end of formula. (Example: "2+sin(")
 
42
  ecUNEXPECTED_COMMA,         ///< An unexpected comma has been found. (Example: "1,23")
 
43
  ecUNEXPECTED_ARG,           ///< An unexpected argument has been found
 
44
  ecUNEXPECTED_VAL,           ///< An unexpected value token has been found
 
45
  ecUNEXPECTED_VAR,           ///< An unexpected variable token has been found
 
46
  ecUNEXPECTED_PARENS,        ///< Unexpected Parenthesis, opening or closing
 
47
  ecUNEXPECTED_STR,           ///< A string has been found at an inapropriate position
 
48
  ecSTRING_EXPECTED,          ///< A string function has been called with a different type of argument
 
49
  ecVAL_EXPECTED,             ///< A numerical function has been called with a non value type of argument
 
50
  ecMISSING_PARENS,           ///< Missing parens. (Example: "3*sin(3")
 
51
  ecUNEXPECTED_FUN,           ///< Unexpected function found. (Example: "sin(8)cos(9)")
 
52
  ecUNTERMINATED_STRING,      ///< unterminated string constant. (Example: "3*valueof("hello)")
 
53
  ecTOO_MANY_PARAMS,          ///< Too many function parameters
 
54
  ecTOO_FEW_PARAMS,           ///< Too few function parameters. (Example: "ite(1<2,2)")
 
55
  ecOPRT_TYPE_CONFLICT,       ///< binary operators may only be applied to value items of the same type
 
56
  ecSTR_RESULT,               ///< result is a string
 
57
 
 
58
  // Invalid Parser input Parameters
 
59
  ecINVALID_NAME,             ///< Invalid function, variable or constant name.
 
60
  ecBUILTIN_OVERLOAD,         ///< Trying to overload builtin operator
 
61
  ecINVALID_FUN_PTR,          ///< Invalid callback function pointer 
 
62
  ecINVALID_VAR_PTR,          ///< Invalid variable pointer 
 
63
 
 
64
  ecNAME_CONFLICT,            ///< Name conflict
 
65
  ecOPT_PRI,                  ///< Invalid operator priority
 
66
  // 
 
67
  ecDOMAIN_ERROR,             ///< catch division by zero, sqrt(-1), log(0) (currently unused)
 
68
  ecDIV_BY_ZERO,              ///< Division by zero (currently unused)
 
69
  ecGENERIC,                  ///< Generic error
 
70
 
 
71
  // internal errors
 
72
  ecINTERNAL_ERROR,           ///< Internal error of any kind.
 
73
 
 
74
  // The last two are special entries 
 
75
  ecCOUNT,                    ///< This is no error code, It just stores just the total number of error codes
 
76
  ecUNDEFINED           = -1, ///< Undefined message, placeholder to detect unassigned error messages
 
77
};
 
78
 
 
79
//---------------------------------------------------------------------------
 
80
class ParserErrorMsg
 
81
{
 
82
public:
 
83
    typedef ParserErrorMsg self_type;
 
84
 
 
85
   ~ParserErrorMsg();
 
86
 
 
87
    static const ParserErrorMsg& Instance();
 
88
    string_type operator[](unsigned a_iIdx) const;
 
89
 
 
90
private:
 
91
    std::vector<string_type>  m_vErrMsg;
 
92
    static const self_type m_Instance;
 
93
 
 
94
    ParserErrorMsg& operator=(const ParserErrorMsg &);
 
95
    ParserErrorMsg(const ParserErrorMsg&);
 
96
    ParserErrorMsg();
 
97
};
 
98
 
 
99
//---------------------------------------------------------------------------
 
100
/** \brief Error class of the parser. 
 
101
 
 
102
  Part of the math parser package.
 
103
 
 
104
  \author Ingo Berg
 
105
*/
 
106
/* final */ class ParserError
 
107
{
 
108
private:
 
109
    //------------------------------------------------------------------------------
 
110
    /** \brief Replace all ocuurences of a substring with another string. */
 
111
    void ReplaceSubString( string_type &strSource, 
 
112
                           const string_type &strFind,
 
113
                           const string_type &strReplaceWith);
 
114
    void Reset();
 
115
 
 
116
public:
 
117
    ParserError();
 
118
    explicit ParserError(EErrorCodes a_iErrc);
 
119
    explicit ParserError(const string_type &sMsg);
 
120
    ParserError( EErrorCodes a_iErrc,
 
121
                 const string_type &sTok,
 
122
                 const string_type &sFormula = string_type("(formula is not available)"),
 
123
                 int a_iPos = -1);
 
124
    ParserError( EErrorCodes a_iErrc, 
 
125
                 int a_iPos, 
 
126
                 const string_type &sTok);
 
127
    ParserError( const char_type *a_szMsg, 
 
128
                 int a_iPos = -1, 
 
129
                 const string_type &sTok = string_type());
 
130
    ParserError(const ParserError &a_Obj);
 
131
    ParserError& operator=(const ParserError &a_Obj);
 
132
   ~ParserError();
 
133
 
 
134
    void SetFormula(const string_type &a_strFormula);
 
135
    const string_type& GetExpr() const;
 
136
    const string_type& GetMsg() const;
 
137
    std::size_t GetPos() const;
 
138
    const string_type& GetToken() const;
 
139
    EErrorCodes GetCode() const;
 
140
 
 
141
private:
 
142
    string_type m_strMsg;     ///< The message string
 
143
    string_type m_strFormula; ///< Formula string
 
144
    string_type m_strTok;     ///< Token related with the error
 
145
    int m_iPos;               ///< Formula position related to the error 
 
146
    EErrorCodes m_iErrc;      ///< Error code
 
147
    const ParserErrorMsg &m_ErrMsg;
 
148
};              
 
149
 
 
150
} // namespace mu
 
151
 
 
152
#endif
 
153