Vaucanson 1.4
nodes.hh
00001 // nodes.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2008 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
00016 //
00017 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_NODES_HH
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_NODES_HH
00019 
00020 namespace vcsn {
00021 
00022   namespace rat {
00023 
00024 
00025     template<typename M_, typename W_>
00026     class Node;
00027 
00028     /*-----------------.
00029     | ConstNodeVisitor |
00030     `-----------------*/
00031 
00032     template<typename M_, typename W_>
00033     class ConstNodeVisitor
00034     {
00035     public:
00036       virtual ~ConstNodeVisitor() {}
00037       virtual void product(const Node<M_, W_>*, const Node<M_, W_>*) = 0;
00038       virtual void sum(const Node<M_, W_>*, const Node<M_, W_>*) = 0;
00039       virtual void star(const Node<M_, W_>*) = 0;
00040       virtual void left_weight(const W_&, const Node<M_, W_>*) = 0;
00041       virtual void right_weight(const W_&, const Node<M_, W_>*) = 0;
00042       virtual void constant(const M_&) = 0;
00043       virtual void zero() = 0;
00044       virtual void one() = 0;
00045     };
00046 
00047     template<typename M_, typename W_>
00048     class DefaultMutableNodeVisitor : public ConstNodeVisitor<M_, W_>
00049     {
00050     public:
00051       virtual void product( Node<M_, W_>* lhs,  Node<M_, W_>* rhs);
00052       virtual void sum( Node<M_, W_>* lhs,  Node<M_, W_>* rhs);
00053       virtual void star( Node<M_, W_>* n);
00054       virtual void left_weight(W_&,  Node<M_, W_>* n);
00055       virtual void right_weight( W_&,  Node<M_, W_>* n);
00056       virtual void constant( M_&);
00057       virtual void zero();
00058       virtual void one();
00059     };
00060 
00061     /*-----.
00062     | Node |
00063     `-----*/
00064     template<typename M_, typename W_>
00065     class Node
00066     {
00067     public:
00068       enum type
00069         {
00070           constant,
00071           lweight,
00072           rweight,
00073           one,
00074           prod,
00075           star,
00076           sum,
00077           zero
00078         };
00079 
00080       // Pure virtual methods
00081       virtual type              what() const = 0;
00082       virtual Node<M_, W_>*     clone() const = 0;
00083       virtual void              accept(ConstNodeVisitor<M_, W_> &) const = 0;
00084       virtual bool              operator!=(const Node<M_, W_>& other) const = 0;
00085       virtual bool              operator<(const Node<M_, W_>& other) const = 0;
00086 
00087       // Defined methods
00088       virtual                   ~Node();
00089 
00090       Node();
00091     };
00092 
00093 
00094     /*-----.
00095     | Zero |
00096     `-----*/
00097     template<typename M_, typename W_>
00098     class Zero : public Node<M_, W_>
00099     {
00100     public:
00101       Zero();
00102 
00103       virtual
00104       typename Node<M_, W_>::type
00105       what() const;
00106 
00107       virtual
00108       Node<M_, W_>*     clone() const;
00109       virtual void      accept(ConstNodeVisitor<M_, W_>& v) const;
00110       virtual bool      operator!=(const Node<M_, W_>& other) const;
00111       virtual bool      operator<(const Node<M_, W_>& other) const;
00112 
00113       virtual           ~Zero();
00114     };
00115 
00116     /*----.
00117     | One |
00118     `----*/
00119     template<typename M_, typename W_>
00120     class One : public Node<M_, W_>
00121     {
00122     public:
00123       One();
00124       virtual typename Node<M_, W_>::type
00125       what() const;
00126       virtual Node<M_, W_>*
00127       clone() const;
00128       virtual void
00129       accept(ConstNodeVisitor<M_, W_>& v) const;
00130       virtual bool
00131       operator!=(const Node<M_, W_>& other) const;
00132       virtual bool
00133       operator<(const Node<M_, W_>& other) const;
00134       virtual
00135       ~One();
00136     };
00137 
00138 
00139     /*---------.
00140     | Constant |
00141     `---------*/
00142     template<typename M_, typename W_>
00143     class Constant : public Node<M_, W_>
00144     {
00145     public:
00146       Constant(const M_ &v);
00147       virtual typename Node<M_, W_>::type     what() const;
00148       virtual Node<M_, W_>*          clone() const;
00149       virtual void
00150       accept(ConstNodeVisitor<M_, W_>& v) const;
00151       virtual bool
00152       operator!=(const Node<M_, W_>& other) const;
00153       virtual bool
00154       operator<(const Node<M_, W_>& other) const;
00155       virtual
00156       ~Constant();
00157 
00158     /* protected */ public:
00159       M_        value_;
00160     };
00161 
00162     /*-------------.
00163     | LeftWeighted |
00164     `-------------*/
00165     template<typename M_, typename W_>
00166     class LeftWeighted : public Node<M_, W_>
00167     {
00168 
00169     public:
00170 
00171       LeftWeighted(const W_& w, const Node<M_, W_>& c);
00172       LeftWeighted(const W_& w, Node<M_, W_>* c);
00173       LeftWeighted(const W_& w);
00174       virtual typename Node<M_, W_>::type
00175       what() const;
00176       virtual Node<M_, W_>*
00177       clone() const;
00178       virtual void
00179       accept(ConstNodeVisitor<M_, W_>& v) const;
00180       virtual bool
00181       operator!=(const Node<M_, W_>& other) const;
00182       virtual bool
00183       operator<(const Node<M_, W_>& other) const;
00184       virtual
00185       ~LeftWeighted();
00186 
00187     /* protected */ public:
00188       W_                weight_;
00189       Node<M_, W_>*     child_;
00190     };
00191 
00192     /*--------------.
00193     | RightWeighted |
00194     `--------------*/
00195     template<typename M_, typename W_>
00196     class RightWeighted : public Node<M_, W_>
00197     {
00198     public:
00199 
00200       RightWeighted(const W_& w, const Node<M_, W_>& c);
00201       RightWeighted(const W_& w, Node<M_, W_>* c);
00202       RightWeighted(const W_& w);
00203       virtual typename Node<M_, W_>::type
00204       what() const;
00205       virtual Node<M_, W_>*
00206       clone() const;
00207       virtual void
00208       accept(ConstNodeVisitor<M_, W_>& v) const;
00209       virtual bool
00210       operator!=(const Node<M_, W_>& other) const;
00211       virtual bool
00212       operator<(const Node<M_, W_>& other) const;
00213       virtual
00214       ~RightWeighted();
00215     /* protected */ public:
00216 
00217       W_                weight_;
00218       Node<M_, W_>*     child_;
00219     };
00220 
00221     /*-----.
00222     | Star |
00223     `-----*/
00224     template<typename M_, typename W_>
00225     class Star : public Node<M_, W_>
00226     {
00227 
00228     public:
00229 
00230       Star(const Node<M_, W_>& other);
00231       Star(Node<M_, W_>* other);
00232       virtual typename Node<M_, W_>::type
00233       what() const;
00234       virtual Node<M_, W_>*
00235       clone() const;
00236       virtual void
00237       accept(ConstNodeVisitor<M_, W_>& v) const;
00238       virtual bool
00239       operator!=(const Node<M_, W_>& other) const;
00240       virtual bool
00241       operator<(const Node<M_, W_>& other) const;
00242       virtual
00243       ~Star();
00244 
00245     /* protected */ public:
00246 
00247       Node<M_, W_>*             child_;
00248     };
00249 
00250     /*--------.
00251     | Product |
00252     `--------*/
00253     template<typename M_, typename W_>
00254     class Product : public Node<M_, W_>
00255     {
00256 
00257     public:
00258 
00259       Product(const Node<M_, W_>& left, const Node<M_, W_>& right);
00260       Product(Node<M_, W_>* left, Node<M_, W_>* right);
00261       virtual typename Node<M_, W_>::type
00262       what() const;
00263       virtual Node<M_, W_>*
00264       clone() const;
00265       virtual void
00266       accept(ConstNodeVisitor<M_, W_>& v) const;
00267       virtual bool
00268       operator!=(const Node<M_, W_>& other) const;
00269       virtual bool
00270       operator<(const Node<M_, W_>& other) const;
00271       virtual
00272       ~Product();
00273 
00274     /* protected */ public:
00275 
00276       Node<M_, W_>*             left_;
00277       Node<M_, W_>*             right_;
00278     };
00279 
00280     /*----.
00281     | Sum |
00282     `----*/
00283     template<typename M_, typename W_>
00284     class Sum : public Node<M_, W_>
00285     {
00286     public:
00287       Sum(const Node<M_, W_>& left, const Node<M_, W_>& right);
00288       Sum(Node<M_, W_>* left, Node<M_, W_>* right);
00289       virtual void
00290       accept(ConstNodeVisitor<M_, W_>& v) const;
00291       virtual typename Node<M_, W_>::type
00292       what() const;
00293       virtual Node<M_, W_>*
00294       clone() const;
00295       virtual bool
00296       operator!=(const Node<M_, W_>& other) const;
00297       virtual bool
00298       operator<(const Node<M_, W_>& other) const;
00299       virtual
00300       ~Sum();
00301     /* protected */ public:
00302 
00303       Node<M_, W_>              *left_;
00304       Node<M_, W_>              *right_;
00305     };
00306 
00307   } // End of namespace rat.
00308 
00309 } // End of namespace vcsn.
00310 
00311 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00312 #  include <vaucanson/algebra/implementation/series/rat/nodes.hxx>
00313 # endif // VCSN_USE_INTERFACE_ONLY
00314 
00315 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_NODES_HH