xc
Expresion.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 //Expresion.h
22 
23 #ifndef EXPRESION_H
24 #define EXPRESION_H
25 
26 #include "ExprBase.h"
27 #include <list>
28 #include "Segnal.h"
29 #include <iostream>
30 
31 class Expresion: public ExprBase
32  {
33  typedef std::list<Segnal *> l_Expr;
34  l_Expr lista;
35  protected:
36 
37  void borra_lista(void);
38  void update_nueva_lista(void);
39 
41  virtual void Traduce(std::istream &is) = 0;
42  void Traduce(const std::string &str);
43  public:
44 
45  typedef l_Expr::const_iterator const_iterator_segnales;
46  typedef l_Expr::iterator iterator_segnales;
47 
49  Expresion(void)
50  : ExprBase(false), lista() {}
52  Expresion(const Expresion &other)
53  : ExprBase(other), lista(other.lista)
54  { update_nueva_lista(); }
56  Expresion &operator=(const Expresion &other)
57  {
58  ExprBase::operator=(other);
59  borra_lista();
60  lista=(other.lista);
61  update_nueva_lista();
62  return *this;
63  }
65  Expresion &operator=(const std::string &str)
66  {
67  Traduce(str);
68  return *this;
69  }
71  bool Vacia(void) const
72  { return lista.empty(); }
74  bool Size(void) const
75  { return lista.size(); }
77  Expresion::l_Expr::const_iterator Begin(void) const
78  { return lista.begin(); }
80  Expresion::l_Expr::const_iterator End(void) const
81  { return lista.end(); }
82 
83  void PonerDouble(const double &);
84  void PonerSegnal(const Segnal *);
85 
86  bool Inicial(void);
87 
88  friend std::ostream &operator <<(std::ostream &stream,const Expresion &expr);
90  friend std::istream &operator >>(std::istream &is, Expresion &e)
91  {
92  e.Traduce(is);
93  return is;
94  }
95  virtual ~Expresion(void);
96  };
97 
98 #endif
99 
100 
101 
102 
103 
104 
105 
106 
107 
108 
109 
110 
111 
Expresion & operator=(const Expresion &other)
Operador de asignación.
Definition: Expresion.h:56
Expresion(const Expresion &other)
Constructor de copia.
Definition: Expresion.h:52
Expresion & operator=(const std::string &str)
Operador de asignación.
Definition: Expresion.h:65
bool Vacia(void) const
Devuelve verdadero si la expresión está vacía.
Definition: Expresion.h:71
bool Inicial(void)
Devuelve verdadero si -La expresión está vacía.
Definition: Expresion.cc:64
bool Size(void) const
Devuelve el tamaño de la expresión.
Definition: Expresion.h:74
Expresion::l_Expr::const_iterator Begin(void) const
Devuelve un iterador apuntando al principio de la lista de señales.
Definition: Expresion.h:77
void PonerDouble(const double &)
Inserts a literal on the list, this functions exists to avoid calling PonerSegnal and to increment by...
Definition: Expresion.cc:44
Definition: Expresion.h:31
Componente elemental de una expresión.
Definition: Segnal.h:60
Expresion(void)
Constructor por defecto.
Definition: Expresion.h:49
friend std::istream & operator>>(std::istream &is, Expresion &e)
Operador entrada.
Definition: Expresion.h:90
void PonerSegnal(const Segnal *)
Inserta una señal en la lista.
Definition: Expresion.cc:48
Expresion::l_Expr::const_iterator End(void) const
Devuelve un iterador apuntando al final de la lista de señales.
Definition: Expresion.h:80
virtual void Traduce(std::istream &is)=0
Crea la expresión a partir del istream que se pasa como parámetro.
Definition: ExprBase.h:28
friend std::ostream & operator<<(std::ostream &stream, const Expresion &expr)
Operador salida.
Definition: Expresion.cc:93