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 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       W_* &                     c();
00090       W_ const * &              c() const;
00091 
00092       Node();
00093 
00094     /* protected */ public:
00095       const W_*         constant_term_;
00096     };
00097 
00098 
00099     /*-----.
00100     | Zero |
00101     `-----*/
00102     template<typename M_, typename W_>
00103     class Zero : public Node<M_, W_>
00104     {
00105     public:
00106       Zero();
00107 
00108       virtual
00109       typename Node<M_, W_>::type
00110       what() const;
00111 
00112       virtual
00113       Node<M_, W_>*     clone() const;
00114       virtual void      accept(ConstNodeVisitor<M_, W_>& v) const;
00115       virtual bool      operator!=(const Node<M_, W_>& other) const;
00116       virtual bool      operator<(const Node<M_, W_>& other) const;
00117 
00118       virtual           ~Zero();
00119     };
00120 
00121     /*----.
00122     | One |
00123     `----*/
00124     template<typename M_, typename W_>
00125     class One : public Node<M_, W_>
00126     {
00127     public:
00128       One();
00129       virtual typename Node<M_, W_>::type
00130       what() const;
00131       virtual Node<M_, W_>*
00132       clone() const;
00133       virtual void
00134       accept(ConstNodeVisitor<M_, W_>& v) const;
00135       virtual bool
00136       operator!=(const Node<M_, W_>& other) const;
00137       virtual bool
00138       operator<(const Node<M_, W_>& other) const;
00139       virtual
00140       ~One();
00141     };
00142 
00143 
00144     /*---------.
00145     | Constant |
00146     `---------*/
00147     template<typename M_, typename W_>
00148     class Constant : public Node<M_, W_>
00149     {
00150     public:
00151       Constant(const M_ &v);
00152       virtual typename Node<M_, W_>::type     what() const;
00153       virtual Node<M_, W_>*          clone() const;
00154       virtual void
00155       accept(ConstNodeVisitor<M_, W_>& v) const;
00156       virtual bool
00157       operator!=(const Node<M_, W_>& other) const;
00158       virtual bool
00159       operator<(const Node<M_, W_>& other) const;
00160       virtual
00161       ~Constant();
00162 
00163     /* protected */ public:
00164       M_        value_;
00165     };
00166 
00167     /*-------------.
00168     | LeftWeighted |
00169     `-------------*/
00170     template<typename M_, typename W_>
00171     class LeftWeighted : public Node<M_, W_>
00172     {
00173 
00174     public:
00175 
00176       LeftWeighted(const W_& w, const Node<M_, W_>& c);
00177       LeftWeighted(const W_& w, Node<M_, W_>* c);
00178       LeftWeighted(const W_& w);
00179       virtual typename Node<M_, W_>::type
00180       what() const;
00181       virtual Node<M_, W_>*
00182       clone() const;
00183       virtual void
00184       accept(ConstNodeVisitor<M_, W_>& v) const;
00185       virtual bool
00186       operator!=(const Node<M_, W_>& other) const;
00187       virtual bool
00188       operator<(const Node<M_, W_>& other) const;
00189       virtual
00190       ~LeftWeighted();
00191 
00192     /* protected */ public:
00193       W_                weight_;
00194       Node<M_, W_>*     child_;
00195     };
00196 
00197     /*--------------.
00198     | RightWeighted |
00199     `--------------*/
00200     template<typename M_, typename W_>
00201     class RightWeighted : public Node<M_, W_>
00202     {
00203     public:
00204 
00205       RightWeighted(const W_& w, const Node<M_, W_>& c);
00206       RightWeighted(const W_& w, Node<M_, W_>* c);
00207       RightWeighted(const W_& w);
00208       virtual typename Node<M_, W_>::type
00209       what() const;
00210       virtual Node<M_, W_>*
00211       clone() const;
00212       virtual void
00213       accept(ConstNodeVisitor<M_, W_>& v) const;
00214       virtual bool
00215       operator!=(const Node<M_, W_>& other) const;
00216       virtual bool
00217       operator<(const Node<M_, W_>& other) const;
00218       virtual
00219       ~RightWeighted();
00220     /* protected */ public:
00221 
00222       W_                weight_;
00223       Node<M_, W_>*     child_;
00224     };
00225 
00226     /*-----.
00227     | Star |
00228     `-----*/
00229     template<typename M_, typename W_>
00230     class Star : public Node<M_, W_>
00231     {
00232 
00233     public:
00234 
00235       Star(const Node<M_, W_>& other);
00236       Star(Node<M_, W_>* other);
00237       virtual typename Node<M_, W_>::type
00238       what() const;
00239       virtual Node<M_, W_>*
00240       clone() const;
00241       virtual void
00242       accept(ConstNodeVisitor<M_, W_>& v) const;
00243       virtual bool
00244       operator!=(const Node<M_, W_>& other) const;
00245       virtual bool
00246       operator<(const Node<M_, W_>& other) const;
00247       virtual
00248       ~Star();
00249 
00250     /* protected */ public:
00251 
00252       Node<M_, W_>*             child_;
00253     };
00254 
00255     /*--------.
00256     | Product |
00257     `--------*/
00258     template<typename M_, typename W_>
00259     class Product : public Node<M_, W_>
00260     {
00261 
00262     public:
00263 
00264       Product(const Node<M_, W_>& left, const Node<M_, W_>& right);
00265       Product(Node<M_, W_>* left, Node<M_, W_>* right);
00266       virtual typename Node<M_, W_>::type
00267       what() const;
00268       virtual Node<M_, W_>*
00269       clone() const;
00270       virtual void
00271       accept(ConstNodeVisitor<M_, W_>& v) const;
00272       virtual bool
00273       operator!=(const Node<M_, W_>& other) const;
00274       virtual bool
00275       operator<(const Node<M_, W_>& other) const;
00276       virtual
00277       ~Product();
00278 
00279     /* protected */ public:
00280 
00281       Node<M_, W_>*             left_;
00282       Node<M_, W_>*             right_;
00283     };
00284 
00285     /*----.
00286     | Sum |
00287     `----*/
00288     template<typename M_, typename W_>
00289     class Sum : public Node<M_, W_>
00290     {
00291     public:
00292       Sum(const Node<M_, W_>& left, const Node<M_, W_>& right);
00293       Sum(Node<M_, W_>* left, Node<M_, W_>* right);
00294       virtual void
00295       accept(ConstNodeVisitor<M_, W_>& v) const;
00296       virtual typename Node<M_, W_>::type
00297       what() const;
00298       virtual Node<M_, W_>*
00299       clone() const;
00300       virtual bool
00301       operator!=(const Node<M_, W_>& other) const;
00302       virtual bool
00303       operator<(const Node<M_, W_>& other) const;
00304       virtual
00305       ~Sum();
00306     /* protected */ public:
00307 
00308       Node<M_, W_>              *left_;
00309       Node<M_, W_>              *right_;
00310     };
00311 
00312   } // End of namespace rat.
00313 
00314 } // End of namespace vcsn.
00315 
00316 # ifndef VCSN_USE_INTERFACE_ONLY
00317 #  include <vaucanson/algebra/implementation/series/rat/nodes.hxx>
00318 # endif // VCSN_USE_INTERFACE_ONLY
00319 
00320 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_NODES_HH

Generated on Fri Jul 28 12:18:49 2006 for Vaucanson by  doxygen 1.4.6