parsedFormula.hh

Go to the documentation of this file.
1 
6 #ifndef parsedformula_hh
7 #define parsedformula_hh
8 
9 #include "toolbox/sequence.hh"
10 #include "formula.hh"
11 
12 
13 namespace concepts {
14 
15  // **************************************************** FormulaSyntaxError **
16 
23  public:
27  FormulaSyntaxError(const std::string& errMsg) throw();
28  protected:
29  virtual std::ostream& info(std::ostream& os) const throw();
30  };
31 
32  // ********************************************************* ParsedFormula **
33 
59  template<uint dim>
61  public:
63 
65  for(uint i = 0; i < dim; ++i) {
66  formula_[i] = "";
67  len_[i] = 0;
68  }
69  }
72  for(uint i = 0; i < dim; ++i) {
73  formula_[i] = frm.formula_[i];
74  pgm_[i] = frm.pgm_[i]; // copy the data
75  len_[i] = frm.len_[i];
76  }
77  }
79  void set(const std::string formula, uint i = 0,
80  RepSeq rep = RepSeq());
81  protected:
83  Real process_(const Real3d& p, const Real t=0.0, uint i=0) const;
85  std::string formula_[dim];
86  private:
90  uint len_[dim];
91  };
92 
93  template<class F = Real>
94  class ParsedFormula {};
95 
96  template<>
97  class ParsedFormula<Real> : public Formula<Real>, public ParsedFormulaBase<1> {
98  public:
100  ParsedFormula(const std::string formula);
101  virtual ~ParsedFormula();
102  virtual ParsedFormula<Real>* clone() const;
103 
104  virtual Real operator() (const Real p, const Real t = 0.0) const;
105  virtual Real operator() (const Real2d& p, const Real t = 0.0) const;
106  virtual Real operator() (const Real3d& p, const Real t = 0.0) const;
107  protected:
108  virtual std::ostream& info(std::ostream& os) const;
109  };
110 
111  template<>
112  class ParsedFormula<Cmplx> : public Formula<Cmplx>, public ParsedFormulaBase<2>
113  {
114  public:
116  ParsedFormula(const std::string formulaR, const std::string formulaI);
117  virtual ~ParsedFormula();
118  virtual ParsedFormula<Cmplx>* clone() const;
119 
120  virtual Cmplx operator() (const Real p, const Real t = 0.0) const;
121  virtual Cmplx operator() (const Real2d& p, const Real t = 0.0) const;
122  virtual Cmplx operator() (const Real3d& p, const Real t = 0.0) const;
123  protected:
124  virtual std::ostream& info(std::ostream& os) const;
125  };
126 
127  template<>
128  class ParsedFormula<Real2d> : public Formula<Real2d>,
129  public ParsedFormulaBase<2>
130  {
131  public:
133  ParsedFormula(const std::string formula1, const std::string formula2);
134  virtual ~ParsedFormula();
135  virtual ParsedFormula<Real2d>* clone() const;
136 
137  virtual Real2d operator() (const Real p, const Real t = 0.0) const;
138  virtual Real2d operator() (const Real2d& p, const Real t = 0.0) const;
139  virtual Real2d operator() (const Real3d& p, const Real t = 0.0) const;
140  protected:
141  virtual std::ostream& info(std::ostream& os) const;
142  };
143 
144 
145 } // namespace concepts
146 
147 #endif // parsedformula_hh
148 
ParsedFormulaBase(const ParsedFormulaBase< dim > &frm)
Copy constructor.
virtual std::ostream & info(std::ostream &os) const
virtual ParsedFormula< Real > * clone() const
Interface for a formula.
Definition: lform.hh:18
FormulaSyntaxError(const std::string &errMsg)
Constructor.
virtual std::ostream & info(std::ostream &os) const
Returns information in an output stream.
ParsedFormula(const std::string formulaR, const std::string formulaI)
Constructor.
Real process_(const Real3d &p, const Real t=0.0, uint i=0) const
Processing the i th formula (with time-dependency variable)
concepts::Sequence< std::pair< std::string, std::string > > RepSeq
Array< uchar > pgm_[dim]
The parsed formula.
Exception indication that a formula contains a syntax error reported by the parser.
ParsedFormula(const std::string formula)
Constructor.
virtual std::ostream & info(std::ostream &os) const
Sequence with operations, output operator, and method of the particular element types.
Definition: sequence.hh:39
std::string formula_[dim]
The original formula.
std::complex< Real > Cmplx
Type for a complex number. It also depends on the setting of Real.
Definition: typedefs.hh:39
ParsedFormula(const std::string formula1, const std::string formula2)
Constructor.
virtual std::ostream & info(std::ostream &os) const
virtual ParsedFormula< Cmplx > * clone() const
virtual ParsedFormula< Real2d > * clone() const
void set(const std::string formula, uint i=0, RepSeq rep=RepSeq())
Sets the i th formula.
Exception class to express a missing feature.
Definition: exceptions.hh:206
Parses the given string and evaluates it on request.
uint len_[dim]
Length of the parsed formula
double Real
Type normally used for a floating point number.
Definition: typedefs.hh:36
Basic namespace for Concepts-2.
Definition: pml_formula.h:16
Page URL: http://wiki.math.ethz.ch/bin/view/Concepts/WebHome
21 August 2020
© 2020 Eidgenössische Technische Hochschule Zürich