muParser: muParserError.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Examples

# muParserError.h

Go to the documentation of this file.

    00001 /*
    00002                  __________
    00003     _____   __ __\______   \_____  _______  ______  ____ _______
    00004    /     \ |  |  \|     ___/\__  \ \_  __ \/  ___/_/ __ \\_  __ \
    00005   |  Y Y  \|  |  /|    |     / __ \_|  | \/\___ \ \  ___/ |  | \/
    00006   |__|_|  /|____/ |____|    (____  /|__|  /____  > \___  >|__|
    00007         \/                       \/            \/      \/
    00008   Copyright (C) 2004-2008 Ingo Berg
    00009
    00010   Permission is hereby granted, free of charge, to any person obtaining a copy of this
    00011   software and associated documentation files (the "Software"), to deal in the Software
    00012   without restriction, including without limitation the rights to use, copy, modify,
    00013   merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
    00014   permit persons to whom the Software is furnished to do so, subject to the following conditions:
    00015
    00016   The above copyright notice and this permission notice shall be included in all copies or
    00017   substantial portions of the Software.
    00018
    00019   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
    00020   NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
    00021   NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
    00022   DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    00023   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    00024 */
    00025
    00026 #ifndef MU_PARSER_ERROR_H
    00027 #define MU_PARSER_ERROR_H
    00028
    00029 #include <cassert>
    00030 #include <stdexcept>
    00031 #include <string>
    00032 #include <sstream>
    00033 #include <vector>
    00034 #include <memory>
    00035
    00036 #include "muParserDef.h"
    00037
    00042 namespace mu
    00043 {
    00044
    00046 enum EErrorCodes
    00047 {
    00048   // Formula syntax errors
    00049   ecUNEXPECTED_OPERATOR = 0,
    00050   ecUNASSIGNABLE_TOKEN  = 1,
    00051   ecUNEXPECTED_EOF      = 2,
    00052   ecUNEXPECTED_ARG_SEP  = 3,
    00053   ecUNEXPECTED_ARG      = 4,
    00054   ecUNEXPECTED_VAL      = 5,
    00055   ecUNEXPECTED_VAR      = 6,
    00056   ecUNEXPECTED_PARENS   = 7,
    00057   ecUNEXPECTED_STR      = 8,
    00058   ecSTRING_EXPECTED     = 9,
    00059   ecVAL_EXPECTED        = 10,
    00060   ecMISSING_PARENS      = 11,
    00061   ecUNEXPECTED_FUN      = 12,
    00062   ecUNTERMINATED_STRING = 13,
    00063   ecTOO_MANY_PARAMS     = 14,
    00064   ecTOO_FEW_PARAMS      = 15,
    00065   ecOPRT_TYPE_CONFLICT  = 16,
    00066   ecSTR_RESULT          = 17,
    00067
    00068   // Invalid Parser input Parameters
    00069   ecINVALID_NAME        = 18,
    00070   ecBUILTIN_OVERLOAD    = 19,
    00071   ecINVALID_FUN_PTR     = 20,
    00072   ecINVALID_VAR_PTR     = 21,
    00073   ecEMPTY_EXPRESSION    = 22,
    00074   ecNAME_CONFLICT       = 23,
    00075   ecOPT_PRI             = 24,
    00076   //
    00077   ecDOMAIN_ERROR        = 25,
    00078   ecDIV_BY_ZERO         = 26,
    00079   ecGENERIC             = 27,
    00080   ecLOCALE              = 28,
    00081
    00082   // internal errors
    00083   ecINTERNAL_ERROR      = 29,
    00084
    00085   // The last two are special entries
    00086   ecCOUNT,
    00087   ecUNDEFINED           = -1
    00088 };
    00089
    00090 //---------------------------------------------------------------------------
    00093 class ParserErrorMsg
    00094 {
    00095 public:
    00096     typedef ParserErrorMsg self_type;
    00097
    00098     ParserErrorMsg& operator=(const ParserErrorMsg &);
    00099     ParserErrorMsg(const ParserErrorMsg&);
    00100     ParserErrorMsg();
    00101
    00102    ~ParserErrorMsg();
    00103
    00104     static const ParserErrorMsg& Instance();
    00105     string_type operator[](unsigned a_iIdx) const;
    00106
    00107 private:
    00108     std::vector<string_type>  m_vErrMsg;
    00109     static const self_type m_Instance;
    00110 };
    00111
    00112 //---------------------------------------------------------------------------
    00119 /* final */ class ParserError
    00120 {
    00121 private:
    00122     //------------------------------------------------------------------------------
    00124     void ReplaceSubString( string_type &strSource,
    00125                            const string_type &strFind,
    00126                            const string_type &strReplaceWith);
    00127     void Reset();
    00128
    00129 public:
    00130     ParserError();
    00131     explicit ParserError(EErrorCodes a_iErrc);
    00132     explicit ParserError(const string_type &sMsg);
    00133     ParserError( EErrorCodes a_iErrc,
    00134                  const string_type &sTok,
    00135                  const string_type &sFormula = string_type(_T("(formula is not available)")),
    00136                  int a_iPos = -1);
    00137     ParserError( EErrorCodes a_iErrc,
    00138                  int a_iPos,
    00139                  const string_type &sTok);
    00140     ParserError( const char_type *a_szMsg,
    00141                  int a_iPos = -1,
    00142                  const string_type &sTok = string_type());
    00143     ParserError(const ParserError &a_Obj);
    00144     ParserError& operator=(const ParserError &a_Obj);
    00145    ~ParserError();
    00146
    00147     void SetFormula(const string_type &a_strFormula);
    00148     const string_type& GetExpr() const;
    00149     const string_type& GetMsg() const;
    00150     std::size_t GetPos() const;
    00151     const string_type& GetToken() const;
    00152     EErrorCodes GetCode() const;
    00153
    00154 private:
    00155     string_type m_strMsg;
    00156     string_type m_strFormula;
    00157     string_type m_strTok;
    00158     int m_iPos;
    00159     EErrorCodes m_iErrc;
    00160     const ParserErrorMsg &m_ErrMsg;
    00161 };
    00162
    00163 } // namespace mu
    00164
    00165 #endif
    00166