Vaucanson  1.4.1
nodes.hh
1 // nodes.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2008 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_NODES_HH
18 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_NODES_HH
19 
20 namespace vcsn {
21 
22  namespace rat {
23 
24 
25  template<typename M_, typename W_>
26  class Node;
27 
28  /*-----------------.
29  | ConstNodeVisitor |
30  `-----------------*/
31 
32  template<typename M_, typename W_>
33  class ConstNodeVisitor
34  {
35  public:
36  virtual ~ConstNodeVisitor() {}
37  virtual void product(const Node<M_, W_>*, const Node<M_, W_>*) = 0;
38  virtual void sum(const Node<M_, W_>*, const Node<M_, W_>*) = 0;
39  virtual void star(const Node<M_, W_>*) = 0;
40  virtual void left_weight(const W_&, const Node<M_, W_>*) = 0;
41  virtual void right_weight(const W_&, const Node<M_, W_>*) = 0;
42  virtual void constant(const M_&) = 0;
43  virtual void zero() = 0;
44  virtual void one() = 0;
45  };
46 
47  template<typename M_, typename W_>
48  class DefaultMutableNodeVisitor : public ConstNodeVisitor<M_, W_>
49  {
50  public:
51  virtual void product( Node<M_, W_>* lhs, Node<M_, W_>* rhs);
52  virtual void sum( Node<M_, W_>* lhs, Node<M_, W_>* rhs);
53  virtual void star( Node<M_, W_>* n);
54  virtual void left_weight(W_&, Node<M_, W_>* n);
55  virtual void right_weight( W_&, Node<M_, W_>* n);
56  virtual void constant( M_&);
57  virtual void zero();
58  virtual void one();
59  };
60 
61  /*-----.
62  | Node |
63  `-----*/
64  template<typename M_, typename W_>
65  class Node
66  {
67  public:
68  enum type
69  {
70  constant,
71  lweight,
72  rweight,
73  one,
74  prod,
75  star,
76  sum,
77  zero
78  };
79 
80  // Pure virtual methods
81  virtual type what() const = 0;
82  virtual Node<M_, W_>* clone() const = 0;
83  virtual void accept(ConstNodeVisitor<M_, W_> &) const = 0;
84  virtual bool operator!=(const Node<M_, W_>& other) const = 0;
85  virtual bool operator<(const Node<M_, W_>& other) const = 0;
86 
87  // Defined methods
88  virtual ~Node();
89 
90  Node();
91  };
92 
93 
94  /*-----.
95  | Zero |
96  `-----*/
97  template<typename M_, typename W_>
98  class Zero : public Node<M_, W_>
99  {
100  public:
101  Zero();
102 
103  virtual
104  typename Node<M_, W_>::type
105  what() const;
106 
107  virtual
108  Node<M_, W_>* clone() const;
109  virtual void accept(ConstNodeVisitor<M_, W_>& v) const;
110  virtual bool operator!=(const Node<M_, W_>& other) const;
111  virtual bool operator<(const Node<M_, W_>& other) const;
112 
113  virtual ~Zero();
114  };
115 
116  /*----.
117  | One |
118  `----*/
119  template<typename M_, typename W_>
120  class One : public Node<M_, W_>
121  {
122  public:
123  One();
124  virtual typename Node<M_, W_>::type
125  what() const;
126  virtual Node<M_, W_>*
127  clone() const;
128  virtual void
129  accept(ConstNodeVisitor<M_, W_>& v) const;
130  virtual bool
131  operator!=(const Node<M_, W_>& other) const;
132  virtual bool
133  operator<(const Node<M_, W_>& other) const;
134  virtual
135  ~One();
136  };
137 
138 
139  /*---------.
140  | Constant |
141  `---------*/
142  template<typename M_, typename W_>
143  class Constant : public Node<M_, W_>
144  {
145  public:
146  Constant(const M_ &v);
147  virtual typename Node<M_, W_>::type what() const;
148  virtual Node<M_, W_>* clone() const;
149  virtual void
150  accept(ConstNodeVisitor<M_, W_>& v) const;
151  virtual bool
152  operator!=(const Node<M_, W_>& other) const;
153  virtual bool
154  operator<(const Node<M_, W_>& other) const;
155  virtual
156  ~Constant();
157 
158  /* protected */ public:
159  M_ value_;
160  };
161 
162  /*-------------.
163  | LeftWeighted |
164  `-------------*/
165  template<typename M_, typename W_>
166  class LeftWeighted : public Node<M_, W_>
167  {
168 
169  public:
170 
171  LeftWeighted(const W_& w, const Node<M_, W_>& c);
172  LeftWeighted(const W_& w, Node<M_, W_>* c);
173  LeftWeighted(const W_& w);
174  virtual typename Node<M_, W_>::type
175  what() const;
176  virtual Node<M_, W_>*
177  clone() const;
178  virtual void
179  accept(ConstNodeVisitor<M_, W_>& v) const;
180  virtual bool
181  operator!=(const Node<M_, W_>& other) const;
182  virtual bool
183  operator<(const Node<M_, W_>& other) const;
184  virtual
185  ~LeftWeighted();
186 
187  /* protected */ public:
188  W_ weight_;
189  Node<M_, W_>* child_;
190  };
191 
192  /*--------------.
193  | RightWeighted |
194  `--------------*/
195  template<typename M_, typename W_>
196  class RightWeighted : public Node<M_, W_>
197  {
198  public:
199 
200  RightWeighted(const W_& w, const Node<M_, W_>& c);
201  RightWeighted(const W_& w, Node<M_, W_>* c);
202  RightWeighted(const W_& w);
203  virtual typename Node<M_, W_>::type
204  what() const;
205  virtual Node<M_, W_>*
206  clone() const;
207  virtual void
208  accept(ConstNodeVisitor<M_, W_>& v) const;
209  virtual bool
210  operator!=(const Node<M_, W_>& other) const;
211  virtual bool
212  operator<(const Node<M_, W_>& other) const;
213  virtual
214  ~RightWeighted();
215  /* protected */ public:
216 
217  W_ weight_;
218  Node<M_, W_>* child_;
219  };
220 
221  /*-----.
222  | Star |
223  `-----*/
224  template<typename M_, typename W_>
225  class Star : public Node<M_, W_>
226  {
227 
228  public:
229 
230  Star(const Node<M_, W_>& other);
231  Star(Node<M_, W_>* other);
232  virtual typename Node<M_, W_>::type
233  what() const;
234  virtual Node<M_, W_>*
235  clone() const;
236  virtual void
237  accept(ConstNodeVisitor<M_, W_>& v) const;
238  virtual bool
239  operator!=(const Node<M_, W_>& other) const;
240  virtual bool
241  operator<(const Node<M_, W_>& other) const;
242  virtual
243  ~Star();
244 
245  /* protected */ public:
246 
247  Node<M_, W_>* child_;
248  };
249 
250  /*--------.
251  | Product |
252  `--------*/
253  template<typename M_, typename W_>
254  class Product : public Node<M_, W_>
255  {
256 
257  public:
258 
259  Product(const Node<M_, W_>& left, const Node<M_, W_>& right);
260  Product(Node<M_, W_>* left, Node<M_, W_>* right);
261  virtual typename Node<M_, W_>::type
262  what() const;
263  virtual Node<M_, W_>*
264  clone() const;
265  virtual void
266  accept(ConstNodeVisitor<M_, W_>& v) const;
267  virtual bool
268  operator!=(const Node<M_, W_>& other) const;
269  virtual bool
270  operator<(const Node<M_, W_>& other) const;
271  virtual
272  ~Product();
273 
274  /* protected */ public:
275 
276  Node<M_, W_>* left_;
277  Node<M_, W_>* right_;
278  };
279 
280  /*----.
281  | Sum |
282  `----*/
283  template<typename M_, typename W_>
284  class Sum : public Node<M_, W_>
285  {
286  public:
287  Sum(const Node<M_, W_>& left, const Node<M_, W_>& right);
288  Sum(Node<M_, W_>* left, Node<M_, W_>* right);
289  virtual void
290  accept(ConstNodeVisitor<M_, W_>& v) const;
291  virtual typename Node<M_, W_>::type
292  what() const;
293  virtual Node<M_, W_>*
294  clone() const;
295  virtual bool
296  operator!=(const Node<M_, W_>& other) const;
297  virtual bool
298  operator<(const Node<M_, W_>& other) const;
299  virtual
300  ~Sum();
301  /* protected */ public:
302 
303  Node<M_, W_> *left_;
304  Node<M_, W_> *right_;
305  };
306 
307  } // End of namespace rat.
308 
309 } // End of namespace vcsn.
310 
311 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
312 # include <vaucanson/algebra/implementation/series/rat/nodes.hxx>
313 # endif // VCSN_USE_INTERFACE_ONLY
314 
315 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_NODES_HH