OpendTect-6_4  6.4
mathexpression.h
Go to the documentation of this file.
1 #ifndef mathexpression_h
2 #define mathexpression_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: Kristofer Tingdahl
9  Date: 10-12-1999
10  RCS: $Id$
11 ________________________________________________________________________
12 
13 -*/
14 
15 #include "generalmod.h"
16 #include "bufstringset.h"
17 
18 
19 namespace Math
20 {
21 
33 {
34 public:
35 
36  virtual double getValue() const = 0;
37 
38  virtual int nrVariables() const;
39  virtual const char* fullVariableExpression(int) const;
40  virtual void setVariableValue(int,double);
41 
42  // recursive "out" or "this" excluded
43  int nrUniqueVarNames() const
44  { return varnms_.size(); }
45  const char* uniqueVarName( int idx ) const
46  { return varnms_.get(idx).buf(); }
47  int indexOfUnVarName( const char* nm ) const
48  { return varnms_.indexOf( nm ); }
49  int firstOccurVarName(const char*) const;
50 
51  enum VarType { Variable, Constant, Recursive };
52  VarType getType(int varidx) const;
53  int getConstIdx(int varidx) const;
54 
55  bool isRecursive() const
56  { return isrecursive_; }
57 
58  virtual Expression* clone() const = 0;
59 
60  virtual ~Expression();
61 
62  const char* type() const;
63  void dump( BufferString& str ) const { doDump(str,0); }
64 
65 protected:
66 
67  Expression(int nrinputs);
68 
69  int nrInputs() const { return inputs_.size(); }
70  bool setInput( int, Expression* );
71  void copyInput( Expression* target ) const;
72 
73  void addIfOK(const char*);
74 
80 
81  friend class ExpressionParser;
82 
83  void doDump(BufferString&,int nrtabs) const;
84  virtual void dumpSpecifics(BufferString&,int nrtabs) const {}
85 
86 };
87 
88 
110 {
111 public:
112 
113  ExpressionParser( const char* str=0,
114  bool inputsareseries=true )
115  : inp_(str), abswarn_(false)
116  , inputsareseries_(inputsareseries) {}
117 
118  void setInput( const char* s ) { inp_ = s; }
119  Expression* parse() const;
120 
121  static BufferString varNameOf(const char* fullvarnm,int* shift=0);
122  static Expression::VarType varTypeOf(const char*);
123  static int constIdxOf(const char*);
124 
125  const char* errMsg() const { return errmsg_; }
126  bool foundOldAbs() const { return abswarn_; }
127 
128 protected:
129 
131  const bool inputsareseries_;
133  mutable bool abswarn_;
134 
135  Expression* parse(const char*) const;
136 
137  bool findOuterParens(char*,int,Expression*&) const;
138  bool findOuterAbs(char*,int,Expression*&) const;
139  bool findQMarkOper(char*,int,Expression*&) const;
140  bool findAndOrOr(char*,int,Expression*&) const;
141  bool findInequality(char*,int,Expression*&) const;
142  bool findPlusAndMinus(char*,int,Expression*&) const;
143  bool findOtherOper(BufferString&,int,Expression*&) const;
144  bool findVariable(char*,int,Expression*&) const;
145  bool findMathFunction(BufferString&,int,
146  Expression*&) const;
147  bool findStatsFunction(BufferString&,int,
148  Expression*&) const;
149 
150 };
151 
152 
158 {
159 public:
160  ExpressionOperatorDesc( const char* s,
161  const char* d, bool isop, int n )
162  : symbol_(s), desc_(d)
163  , isoperator_(isop), nrargs_(n) {}
164 
165  const char* symbol_; // can have spaces, e.g. "? :"
166  const char* desc_;
167  bool isoperator_;
168  int nrargs_;
169 };
170 
171 
177 {
178 public:
179 
182 
183  static const ObjectSet<const ExpressionOperatorDescGroup>& supported();
184 
185 };
186 
187 } // namespace Math
188 
189 #endif
#define mExpClass(module)
Definition: commondefs.h:160
void dump(BufferString &str) const
Definition: mathexpression.h:63
const char * uniqueVarName(int idx) const
Definition: mathexpression.h:45
void setInput(const char *s)
Definition: mathexpression.h:118
const bool inputsareseries_
Definition: mathexpression.h:131
BufferString inp_
Definition: mathexpression.h:130
BufferString errmsg_
Definition: mathexpression.h:132
virtual void dumpSpecifics(BufferString &, int nrtabs) const
Definition: mathexpression.h:84
ObjectSet< Expression > inputs_
Definition: mathexpression.h:77
int nrInputs() const
Definition: mathexpression.h:69
Set of BufferString objects.
Definition: bufstringset.h:28
bool isrecursive_
Definition: mathexpression.h:79
bool abswarn_
Definition: mathexpression.h:133
ExpressionOperatorDesc(const char *s, const char *d, bool isop, int n)
Definition: mathexpression.h:160
Set of pointers to objects.
Definition: commontypes.h:32
int nrUniqueVarNames() const
Definition: mathexpression.h:43
bool foundOldAbs() const
Definition: mathexpression.h:126
const char * desc_
Definition: mathexpression.h:166
const char * symbol_
Definition: mathexpression.h:165
BufferString name_
Definition: mathexpression.h:180
const char * errMsg() const
Definition: mathexpression.h:125
Parsed Math expression.
Definition: mathexpression.h:32
Group of similar expression descs.
Definition: mathexpression.h:176
ObjectSet< TypeSet< int > > variableobj_
Definition: mathexpression.h:75
OD::String with its own variable length buffer. The buffer has a guaranteed minimum size...
Definition: bufstring.h:40
ObjectSet< TypeSet< int > > variablenr_
Definition: mathexpression.h:76
BufferString errmsg_
Definition: horizontracker.h:119
VarType
Definition: mathexpression.h:51
int indexOfUnVarName(const char *nm) const
Definition: mathexpression.h:47
Expression desc to build UI.
Definition: mathexpression.h:157
Definition: math2.h:29
bool isRecursive() const
Definition: mathexpression.h:55
ExpressionParser(const char *str=0, bool inputsareseries=true)
Definition: mathexpression.h:113
int nrargs_
2 for normal operators
Definition: mathexpression.h:168
Parses a string with a mathematical expression.
Definition: mathexpression.h:109
bool isoperator_
if not, function
Definition: mathexpression.h:167
BufferStringSet varnms_
Definition: mathexpression.h:78
ObjectSet< ExpressionOperatorDesc > opers_
Definition: mathexpression.h:181

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019