xc
VarExpr.h
1 // -*-c++-*-
2 //----------------------------------------------------------------------------
3 // xc utils library; general purpose classes and functions.
4 //
5 // Copyright (C) Luis C. Pérez Tato
6 //
7 // XC utils is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // This software is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program.
19 // If not, see <http://www.gnu.org/licenses/>.
20 //----------------------------------------------------------------------------
21 //VarExpr.h
22 
23 #ifndef VAREXPR_H
24 #define VAREXPR_H
25 
26 #include "ExprAlgebra.h"
27 
28 class VarExpr : public Variable
29  {
30  ExprAlgebra expr;
31  public:
32  VarExpr(void) : Variable() {}
33  VarExpr(const std::string &nmb): Variable(nmb) {}
34  VarExpr(const VarExpr &other): Variable(other) {}
35  VarExpr &operator=(const VarExpr &other)
36  {
37  Variable::operator =(other);
38  expr= other.expr;
39  return *this;
40  }
41  inline ExprAlgebra GetExpr(void) const
42  { return expr; }
43  inline virtual void Asigna(const double &d)
44  {
45  Variable::Asigna(d);
46  expr= ExprAlgebra(d);
47  }
48  inline virtual void AsignaExpr(const ExprAlgebra &ex)
49  {
50  Variable::Asigna(0.0);
51  expr= ex;
52  }
53  virtual bool Evaluable(void) const
54  { return ((Variable::Evaluable()) && (expr.Evaluable())); }
55  inline virtual const Operando &Opera(const Operando *, const Operando *) const
56  {
57  if(Evaluable())
58  return *Lex().NuevoLiteral(expr.ToNum());
59  else
60  return *this;
61  }
62  inline virtual const double &GetValor(const double &v1=0.0, const double &v2=0.0) const
63  { return expr.ToNum(); }
64  };
65 
66 #endif
static Lexico & Lex(void)
Devuelve una referencia al léxico.
Definition: ProtoExpr.cc:32
Definition: Variable.h:31
Operando.
Definition: Operando.h:42
Expresión algebraica.
Definition: ExprAlgebra.h:32
Definition: VarExpr.h:28