All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MathParser.h
Go to the documentation of this file.
1 //-----------------------------------------------------------------------------
2 // (c) 2006 by Basler Vision Technologies
3 // Section: Vision Components
4 // Project: GenApi
5 // Author: Margret Albrecht
6 // $Header$
7 //
8 // License: Derived from Kirill Zaborski's MathParser library (http://kirya.narod.ru/mathparser.html ).
9 // This library comes under LGPL license (see http://www.gnu.org/licenses/lgpl.html).
10 // Kirill's implementation is a C++ port of the CCalc library from Walery Studennikov (http://www.sama.ru/~despair/ccalc/)
11 // which also comes under the LGPL.
12 //-----------------------------------------------------------------------------
19 #ifndef _MATHPARSER_H_
20 #define _MATHPARSER_H_
21 
22 #include "MathParserDll.h"
23 #include "GenApi/Types.h"
24 #include "GenApi/GenApiDll.h"
25 #include "StrMap.h"
26 #include "Lexer.h"
27 
28 #include <vector>
29 
30 #ifdef _MSC_VER // *JS*
31 # pragma warning(push)
32 # pragma warning(disable: 4251) // class 'xxx' needs to have dll-interface to be used by clients of class 'yyy'
33 #endif
34 
35 #define ORIGINAL_STACK_SIZE 64
36 
37 namespace GENAPI_NAMESPACE
38 {
39  extern const double DblErR;
40  extern const double DblNiN;
41 
42 
43  typedef double ( *OneArgFunc ) ( double arg );
44  typedef char* ( *MultiArgFunc ) ( int paramcnt, double* args,
45  CStrMap* strparams, double* result );
46  typedef int ( *PrmSrchFunc ) ( const char* str, size_t len, double* value,
47  void* param );
54  {
55  typedef enum
56  {
57  // Binary
58  OP_SHL, OP_SHR, OP_POW,
59  OP_LOGIC_NEQ, OP_LOGIC_GEQ, OP_LOGIC_LEQ,
60  OP_LOGIC_AND, OP_LOGIC_OR, // Logical
61  OP_COMSTART, OP_ASSIGN, // For internal needs
62  OP_OBR, // Special
63  OP_ADD, OP_SUB, OP_MUL, OP_DIV, OP_MOD, OP_UNK, // Arithmetic
64  OP_XOR, OP_NOT, OP_AND, OP_OR, // Bitwise
65  OP_EQU, OP_GREATER, OP_LESS,
66  OP_LOGIC, OP_LOGIC_SEP, OP_CBR, OP_COMMA, // Logical
67  OP_FORMULAEND, // For script
68  OP_INDEX_TO_VAR, OP_FUNC_ONEARG, OP_FUNC_MULTIARG // Special
69  } OperType_t;
70  static const signed char OpPriorities[OP_FUNC_MULTIARG + 1];
71  typedef struct Operation
72  {
74  const void* Func;
75  signed char PrevValTop;
77  explicit Operation() : Func( 0 ), PrevValTop( 0 ), StrParams( 0 ) {}
78  explicit Operation( OperType_t op ) : OperType( op ), Func( 0 ), PrevValTop( 0 ), StrParams( 0 ) {}
79  explicit Operation( OperType_t op, const void* p, signed char a, CStrMap* pM ) : OperType( op ), Func( p ), PrevValTop( a ), StrParams( pM ) {}
80  } Operation;
81  static const Operation BrOp;
82  static const Operation CbrOp;
83  static const Operation NegOp;
84  static const Operation ItvOp;
85  static const Operation CommaOp;
86  std::vector<Operation> OpStack;
87  std::vector<Operation> OpStackEval;
88  std::vector<double> ValStack;
89  std::vector<double> ValStackEval;
90  int OpTop, ValTop;
91  int ObrDist;
94  std::vector<char> errbuf;
97  const char* ParseFormula( bool ConvertUpperCase );
98  const char* PrepareFormula();
99  const char* Calc();
100  const char* CalcToObr();
101  public:
106  CMathParser( void );
107  const char* Parse( const char* Formula, bool ConvertUpperCase );
108  const char* Eval( double* result );
109  ~CMathParser();
110  };
111 
112 } /* GENAPI_NAMESPACE*/
113 
114 #ifdef _MSC_VER // *JS*
115 # pragma warning(pop)
116 #endif
117 
118 #endif //_MATHPARSER_H_
GENAPI_NAMESPACE
Lexical analyzer for CIntSwissKnife.
Definition: Destructible.h:30
GENAPI_NAMESPACE::CMathParser::Parameters
CStrMap * Parameters
Definition: MathParser.h:102
MATHPARSERDLL_API
#define MATHPARSERDLL_API
Definition: MathParserDll.h:46
GENAPI_NAMESPACE::CMathParser::NegOp
static const Operation NegOp
Definition: MathParser.h:83
GENAPI_NAMESPACE::CMathParser::MoreParams
PrmSrchFunc MoreParams
Definition: MathParser.h:104
GENAPI_NAMESPACE::CMathParser::CommaOp
static const Operation CommaOp
Definition: MathParser.h:85
GENAPI_NAMESPACE::CMathParser::Operation
Definition: MathParser.h:71
Types.h
Common types used in the public GenApi interface.
GENAPI_NAMESPACE::CMathParser::OP_LOGIC_OR
@ OP_LOGIC_OR
Definition: MathParser.h:60
GENAPI_NAMESPACE::CMathParser::ParamFuncParam
void * ParamFuncParam
Definition: MathParser.h:105
GENAPI_NAMESPACE::CMathParser::OpStack
std::vector< Operation > OpStack
Definition: MathParser.h:86
GENAPI_NAMESPACE::CMathParser::Lexer
CLexer Lexer
Definition: MathParser.h:92
GENAPI_NAMESPACE::CMathParser::OP_OBR
@ OP_OBR
Definition: MathParser.h:62
GENAPI_NAMESPACE::CMathParser::Operation::Operation
Operation(OperType_t op)
Definition: MathParser.h:78
GENAPI_NAMESPACE::CMathParser::OP_INDEX_TO_VAR
@ OP_INDEX_TO_VAR
Definition: MathParser.h:68
GENAPI_NAMESPACE::CMathParser::Operation::Func
const void * Func
Definition: MathParser.h:74
GENAPI_NAMESPACE::CMathParser::ItvOp
static const Operation ItvOp
Definition: MathParser.h:84
GENAPI_NAMESPACE::CMathParser
Expression parser and evaluator of CSwissKnife.
Definition: MathParser.h:53
GENAPI_NAMESPACE::CMathParser::ValStackEval
std::vector< double > ValStackEval
Definition: MathParser.h:89
GENAPI_NAMESPACE::CMathParser::ValStack
std::vector< double > ValStack
Definition: MathParser.h:88
GENAPI_NAMESPACE::CMathParser::errbuf
std::vector< char > errbuf
Definition: MathParser.h:94
StrMap.h
Definition of CStrMap.
GENAPI_NAMESPACE::CMathParser::OP_SHR
@ OP_SHR
Definition: MathParser.h:58
GENAPI_NAMESPACE::CMathParser::MathSymTable
static CSymTable MathSymTable
Definition: MathParser.h:96
GENAPI_NAMESPACE::CMathParser::BrOp
static const Operation BrOp
Definition: MathParser.h:81
GENAPI_NAMESPACE::CMathParser::Operation::OperType
OperType_t OperType
Definition: MathParser.h:73
GENAPI_NAMESPACE::CStaticFuncMapDouble
Definition: StrMap.h:60
GENAPI_NAMESPACE::CMathParser::OP_LOGIC_NEQ
@ OP_LOGIC_NEQ
Definition: MathParser.h:59
GENAPI_NAMESPACE::CStrMap
Definition: StrMap.h:31
GENAPI_NAMESPACE::DblNiN
const double DblNiN
MathParserDll.h
Export Macros.
GENAPI_NAMESPACE::CMathParser::Operation::Operation
Operation(OperType_t op, const void *p, signed char a, CStrMap *pM)
Definition: MathParser.h:79
GENAPI_NAMESPACE::CMathParser::OP_COMSTART
@ OP_COMSTART
Definition: MathParser.h:61
GENAPI_NAMESPACE::CMathParser::OP_UNK
@ OP_UNK
Definition: MathParser.h:63
GENAPI_NAMESPACE::CMathParser::ObrDist
int ObrDist
Definition: MathParser.h:91
GENAPI_NAMESPACE::CMathParser::OP_FORMULAEND
@ OP_FORMULAEND
Definition: MathParser.h:67
GENAPI_NAMESPACE::CMathParser::ExtFunctions
CStrMap * ExtFunctions
Definition: MathParser.h:103
GENAPI_NAMESPACE::CMathParser::OP_XOR
@ OP_XOR
Definition: MathParser.h:64
GENAPI_NAMESPACE::CMathParser::OP_LOGIC_SEP
@ OP_LOGIC_SEP
Definition: MathParser.h:66
GENAPI_NAMESPACE::CSymTable
Definition: SymTable.h:26
Lexer.h
Definition of CLexer.
GENAPI_NAMESPACE::CMathParser::ValTop
int ValTop
Definition: MathParser.h:90
GENAPI_NAMESPACE::CMathParser::OperType_t
OperType_t
Definition: MathParser.h:55
GENAPI_NAMESPACE::DblErR
const double DblErR
Definition: MathParser.h:39
GENAPI_NAMESPACE::CMathParser::OpStackEval
std::vector< Operation > OpStackEval
Definition: MathParser.h:87
GENAPI_NAMESPACE::CMathParser::CbrOp
static const Operation CbrOp
Definition: MathParser.h:82
GENAPI_NAMESPACE::CMathParser::Operation::StrParams
CStrMap * StrParams
Definition: MathParser.h:76
GENAPI_NAMESPACE::PrmSrchFunc
int(* PrmSrchFunc)(const char *str, size_t len, double *value, void *param)
Definition: MathParser.h:46
GENAPI_NAMESPACE::CMathParser::Operation::Operation
Operation()
Definition: MathParser.h:77
GENAPI_NAMESPACE::CMathParser::DoubleFunctions
static CStaticFuncMapDouble DoubleFunctions
Definition: MathParser.h:95
GENAPI_NAMESPACE::CLexer
Definition: Lexer.h:48
GenApiDll.h
declspec's to be used for GenApi Windows dll
GENAPI_NAMESPACE::CMathParser::Operation::PrevValTop
signed char PrevValTop
Definition: MathParser.h:75
GENAPI_NAMESPACE::OneArgFunc
double(* OneArgFunc)(double arg)
Definition: MathParser.h:43
GENAPI_NAMESPACE::CMathParser::VarParams
CStrMap * VarParams
Definition: MathParser.h:93
GENAPI_NAMESPACE::CMathParser::OP_LESS
@ OP_LESS
Definition: MathParser.h:65


rc_genicam_api
Author(s): Heiko Hirschmueller
autogenerated on Wed Dec 4 2024 03:10:11