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

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