muParser: muParserDef.h Source File

- Main Page
- Namespaces
- Classes
- Files
- Examples

# muParserDef.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 #ifndef MUP_DEF_H
    00026 #define MUP_DEF_H
    00027
    00028 #include <iostream>
    00029 #include <string>
    00030 #include <sstream>
    00031 #include <map>
    00032
    00033 #include "muParserFixes.h"
    00034
    00045 #define MUP_BASETYPE double
    00046
    00051 #define MUP_BYTECODE_TYPE long
    00052
    00053 #if defined(_UNICODE)
    00054
    00055   #define MUP_STRING_TYPE std::wstring
    00056
    00057   #if !defined(_T)
    00058     #define _T(x) L##x
    00059   #endif // not defined _T
    00060 #else
    00061   #ifndef _T
    00062   #define _T
    00063   #endif
    00064
    00066   #define MUP_STRING_TYPE std::string
    00067 #endif
    00068
    00069 #if defined(_DEBUG)
    00070
    00072   #define MUP_FAIL(MSG)    \
    00073           bool MSG=false;  \
    00074           assert(MSG);
    00075
    00076   #ifndef _UNICODE
    00077
    00082     #define MUP_ASSERT(COND)                         \
    00083             if (!(COND))                             \
    00084             {                                        \
    00085               stringstream_type ss;                  \
    00086               ss << "Assertion \""#COND"\" failed: " \
    00087                  << __FILE__ << " line "             \
    00088                  << __LINE__ << ".";                 \
    00089               throw ParserError( ss.str() );         \
    00090             }
    00091   #else
    00092     #define MUP_ASSERT(COND)
    00093   #endif // _UNICODE
    00094 #else
    00095   #define MUP_FAIL(MSG)
    00096   #define MUP_ASSERT(COND)
    00097 #endif
    00098
    00099 //------------------------------------------------------------------------------
    00100 //
    00101 // do not change anything beyond this point...
    00102 //
    00103 // !!! This section is devoted to macros that are used for debugging
    00104 // !!! or for features that are not fully implemented yet.
    00105 //
    00106 //#define MUP_DUMP_STACK
    00107 //#define MUP_DUMP_CMDCODE
    00108
    00109
    00110 namespace mu
    00111 {
    00112 #if defined(_UNICODE)
    00113
    00114   //------------------------------------------------------------------------------
    00116   inline std::wostream& console()
    00117   {
    00118     return std::wcout;
    00119   }
    00120
    00122   inline std::wistream& console_in()
    00123   {
    00124     return std::wcin;
    00125   }
    00126
    00127 #else
    00128
    00133   inline std::ostream& console()
    00134   {
    00135     return std::cout;
    00136   }
    00137
    00142   inline std::istream& console_in()
    00143   {
    00144     return std::cin;
    00145   }
    00146
    00147 #endif
    00148
    00149   //------------------------------------------------------------------------------
    00154   enum ECmdCode
    00155   {
    00156     // The following are codes for built in binary operators
    00157     // apart from built in operators the user has the opportunity to
    00158     // add user defined operators.
    00159     cmLE            = 0,
    00160     cmGE            = 1,
    00161     cmNEQ           = 2,
    00162     cmEQ            = 3,
    00163     cmLT            = 4,
    00164     cmGT            = 5,
    00165     cmADD           = 6,
    00166     cmSUB           = 7,
    00167     cmMUL           = 8,
    00168     cmDIV           = 9,
    00169     cmPOW           = 10,
    00170     cmAND           = 11,
    00171     cmOR            = 12,
    00172     cmXOR           = 13,
    00173     cmASSIGN        = 14,
    00174     cmBO            = 15,
    00175     cmBC            = 16,
    00176     cmARG_SEP,
    00177     cmVAR,
    00178     cmVAL,
    00179     cmFUNC,
    00180     cmFUNC_STR,
    00181     cmSTRING,
    00182     cmOPRT_BIN,
    00183     cmOPRT_POSTFIX,
    00184     cmOPRT_INFIX,
    00185     cmEND,
    00186     cmUNKNOWN,
    00187   };
    00188
    00189   //------------------------------------------------------------------------------
    00192   enum ETypeCode
    00193   {
    00194     tpSTR  = 0,
    00195     tpDBL  = 1,
    00196     tpVOID = 2
    00197   };
    00198
    00199   //------------------------------------------------------------------------------
    00201   enum EPrec
    00202   {
    00203     // binary operators
    00204     prLOGIC   = 1,
    00205     prCMP     = 2,
    00206     prADD_SUB = 3,
    00207     prMUL_DIV = 4,
    00208     prPOW     = 5,
    00209
    00210     // infix operators
    00211     prINFIX    = 4,
    00212     prPOSTFIX  = 4
    00213   };
    00214
    00215   //------------------------------------------------------------------------------
    00216   // basic types
    00217
    00222   typedef MUP_BASETYPE value_type;
    00223
    00228   typedef MUP_STRING_TYPE string_type;
    00229
    00234   typedef MUP_BYTECODE_TYPE bytecode_type;
    00235
    00240   typedef string_type::value_type char_type;
    00241
    00243   typedef std::basic_stringstream<char_type,
    00244                                   std::char_traits<char_type>,
    00245                                   std::allocator<char_type> > stringstream_type;
    00246
    00247   // Data container types
    00248
    00250   typedef std::map<string_type, value_type*> varmap_type;
    00251
    00253   typedef std::map<string_type, value_type> valmap_type;
    00254
    00256   typedef std::map<string_type, std::size_t> strmap_type;
    00257
    00258   // Parser callbacks
    00259
    00261   typedef value_type (*fun_type0)();
    00262
    00264   typedef value_type (*fun_type1)(value_type);
    00265
    00267   typedef value_type (*fun_type2)(value_type, value_type);
    00268
    00270   typedef value_type (*fun_type3)(value_type, value_type, value_type);
    00271
    00273   typedef value_type (*fun_type4)(value_type, value_type, value_type, value_type);
    00274
    00276   typedef value_type (*fun_type5)(value_type, value_type, value_type, value_type, value_type);
    00277
    00279   typedef value_type (*multfun_type)(const value_type*, int);
    00280
    00282   typedef value_type (*strfun_type1)(const char_type*);
    00283
    00285   typedef value_type (*strfun_type2)(const char_type*, value_type);
    00286
    00288   typedef value_type (*strfun_type3)(const char_type*, value_type, value_type);
    00289
    00291   typedef int (*identfun_type)(const char_type *sExpr, int *nPos, value_type *fVal);
    00292
    00294   typedef value_type* (*facfun_type)(const char_type*, void*);
    00295
    00296   //------------------------------------------------------------------------------
    00304   template <bool> struct STATIC_ASSERTION_FAILURE;
    00305   template <> struct STATIC_ASSERTION_FAILURE<true> {};
    00306
    00311   typedef char MAP_TYPE_CANT_BE_UNSIGNED[ sizeof( STATIC_ASSERTION_FAILURE< bytecode_type(-1)<0 >) ];
    00312 } // end fo namespace
    00313
    00314 #endif
    00315