- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

# exp.hxx

    00001 // exp.hxx: 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, 2006 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_EXP_HXX
    00018 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_EXP_HXX
    00019
    00020 # include <vaucanson/algebra/implementation/series/rat/exp.hh>
    00021
    00022 # include <vaucanson/algebra/implementation/series/rat/depth_visitor.hh>
    00023 # include <vaucanson/algebra/implementation/series/rat/star_height_visitor.hh>
    00024 # include <vaucanson/algebra/implementation/series/rat/length_visitor.hh>
    00025 # include <vaucanson/algebra/implementation/series/rat/xml_exp_visitor.hh>
    00026
    00027 namespace vcsn {
    00028
    00029   namespace rat {
    00030
    00031     template<typename LetterT, typename WeightT>
    00032     exp<LetterT, WeightT>::exp()
    00033       : base_(new n_zero_t)
    00034     {}
    00035
    00036     template<typename LetterT, typename WeightT>
    00037     exp<LetterT, WeightT>::exp(node_t* p)
    00038       : base_(p)
    00039     {}
    00040
    00041     template<typename LetterT, typename WeightT>
    00042     exp<LetterT, WeightT>::exp(const node_t* p)
    00043       : base_(p->clone())
    00044     {}
    00045
    00046     template<typename LetterT, typename WeightT>
    00047     exp<LetterT, WeightT>::exp(const exp& other)
    00048       : base_(other.base_->clone())
    00049     {}
    00050
    00051     template<typename LetterT, typename WeightT>
    00052     exp<LetterT, WeightT>::~exp()
    00053     {
    00054       delete base_;
    00055     }
    00056
    00057     template<typename LetterT, typename WeightT>
    00058     exp<LetterT, WeightT>&
    00059     exp<LetterT, WeightT>::operator = (const exp& other)
    00060     {
    00061       if (other.base_ != base_)
    00062         {
    00063           delete base_;
    00064           base_ = other.base_->clone();
    00065         }
    00066       return *this;
    00067     }
    00068
    00069     template<typename LetterT, typename WeightT>
    00070     exp<LetterT, WeightT>&
    00071     exp<LetterT, WeightT>::operator += (const exp& other)
    00072     {
    00073       base_ = new n_sum_t(base_, other.base_->clone());
    00074       return *this;
    00075     }
    00076
    00077     template<typename LetterT, typename WeightT>
    00078     exp<LetterT, WeightT>&
    00079     exp<LetterT, WeightT>::operator *= (const exp& other)
    00080     {
    00081       base_ = new n_prod_t(base_, other.base_->clone());
    00082       return *this;
    00083     }
    00084
    00085     template<typename LetterT, typename WeightT>
    00086     exp<LetterT, WeightT>& exp<LetterT, WeightT>::star()
    00087     {
    00088       base_ = new n_star_t(base_);
    00089       return *this;
    00090     }
    00091
    00092     template<typename LetterT, typename WeightT>
    00093     exp<LetterT, WeightT>&
    00094     exp<LetterT, WeightT>::swap(exp& other)
    00095     {
    00096       std::swap(base_, other.base_);
    00097       return *this;
    00098     }
    00099
    00100     template<typename LetterT, typename WeightT>
    00101     void exp<LetterT, WeightT>::
    00102     accept(ConstNodeVisitor<monoid_elt_value_t, semiring_elt_value_t>& v) const
    00103     {
    00104       base_->accept(v);
    00105     }
    00106
    00107     template<typename LetterT, typename WeightT>
    00108     size_t exp<LetterT, WeightT>::depth() const
    00109     {
    00110       DepthVisitor<monoid_elt_value_t, semiring_elt_value_t> v;
    00111       accept(v);
    00112       return v.get();
    00113     }
    00114
    00115     template<typename LetterT, typename WeightT>
    00116     size_t exp<LetterT, WeightT>::star_height() const
    00117     {
    00118       StarHeightVisitor<monoid_elt_value_t, semiring_elt_value_t> v;
    00119       accept(v);
    00120       return v.get();
    00121     }
    00122
    00123     template<typename LetterT, typename WeightT>
    00124     size_t exp<LetterT, WeightT>::length() const
    00125     {
    00126       LengthVisitor<monoid_elt_value_t, semiring_elt_value_t> v;
    00127       accept(v);
    00128       return v.get();
    00129     }
    00130
    00131     template<typename LetterT, typename WeightT>
    00132     xercesc::DOMElement* exp<LetterT, WeightT>::xml_tree(
    00133       xercesc::DOMDocument* doc, const char* node_name) const
    00134     {
    00135       XmlExpVisitor<monoid_elt_value_t, semiring_elt_value_t> v(doc, node_name);
    00136       accept(v);
    00137       return v.get();
    00138     }
    00139
    00140     template<typename LetterT, typename WeightT>
    00141     typename exp<LetterT, WeightT>::node_t* &
    00142     exp<LetterT, WeightT>::base()
    00143     {
    00144       return base_;
    00145     }
    00146
    00147     template<typename LetterT, typename WeightT>
    00148     typename exp<LetterT, WeightT>::node_t* const &
    00149     exp<LetterT, WeightT>::base() const
    00150     {
    00151       return base_;
    00152     }
    00153
    00154     template<typename LetterT, typename WeightT>
    00155     bool exp<LetterT, WeightT>::operator == (const exp& other) const
    00156     {
    00157       return !(*base_ != *other.base_);
    00158     }
    00159
    00160     template<typename LetterT, typename WeightT>
    00161     bool exp<LetterT, WeightT>::operator != (const exp& other) const
    00162     {
    00163       return *base_ != *other.base_;
    00164     }
    00165
    00166     template<typename LetterT, typename WeightT>
    00167     bool exp<LetterT, WeightT>::operator < (const exp& other) const
    00168     {
    00169       return *base_ < *other.base_;
    00170     }
    00171
    00172     template<typename LetterT, typename WeightT>
    00173     exp<LetterT, WeightT>
    00174     exp<LetterT, WeightT>::clone() const
    00175     {
    00176       return exp(base_->clone());
    00177     }
    00178
    00179     template<typename LetterT, typename WeightT>
    00180     exp<LetterT, WeightT>
    00181     exp<LetterT, WeightT>::one()
    00182     {
    00183       return exp(new n_one_t);
    00184     }
    00185
    00186     template<typename LetterT, typename WeightT>
    00187     exp<LetterT, WeightT> exp<LetterT, WeightT>::zero()
    00188     {
    00189       return exp(new n_zero_t);
    00190     }
    00191
    00192     template<typename LetterT, typename WeightT>
    00193     exp<LetterT, WeightT> exp<LetterT, WeightT>::
    00194     constant(const monoid_elt_value_t& l)
    00195     {
    00196       return exp(new n_const_t(l));
    00197     }
    00198
    00199     template<typename LetterT, typename WeightT>
    00200     bool exp<LetterT, WeightT>::starable()
    00201     {
    00202       return true;
    00203     }
    00204
    00205     template<typename M, typename W>
    00206     const exp<M, W> operator * (const exp<M, W>& lhs,
    00207                                 const exp<M, W>& rhs)
    00208     {
    00209       exp<M, W> ret(lhs);
    00210       ret *= rhs;
    00211       return ret;
    00212     }
    00213
    00214     template<typename M, typename W>
    00215     exp<M, W> operator + (const exp<M, W>& lhs,
    00216                           const exp<M, W>& rhs)
    00217     {
    00218       exp<M, W> ret(lhs);
    00219       ret += rhs;
    00220       return ret;
    00221     }
    00222
    00223     template<typename M, typename W>
    00224     exp<M, W> operator * (const W& lhs,
    00225                           const exp<M, W>& rhs)
    00226     {
    00227       exp<M, W> ret(rhs);
    00228       ret.base() = new LeftWeighted<M, W>(lhs, ret.base());
    00229       return ret;
    00230     }
    00231
    00232     template<typename M, typename W>
    00233     exp<M, W> operator * (const exp<M, W>& lhs,
    00234                           const W& rhs)
    00235     {
    00236       exp<M, W> ret(lhs);
    00237       ret.base() = new RightWeighted<M, W>(rhs, ret.base());
    00238       return ret;
    00239     }
    00240
    00241     // FIXME: this is an evil hack, but without it there is an ambiguity
    00242     // FIXME: in calls to exp * number or number * exp.
    00243
    00244     template<typename M, typename S, typename T>
    00245     exp<M, Element<S, T> >
    00246     operator*(const Element<S, T>& lhs,
    00247               const exp<M, Element<S, T> >& rhs)
    00248     {
    00249       exp<M, Element<S, T> > ret(rhs);
    00250       ret.base()
    00251         = new LeftWeighted<M, Element<S, T> >(lhs, ret.base());
    00252       return ret;
    00253     }
    00254
    00255     template<typename M, typename S, typename T>
    00256     exp<M, Element<S, T> >
    00257     operator*(const exp<M, Element<S, T> >& lhs,
    00258               const Element<S, T>& rhs)
    00259     {
    00260       exp<M, Element<S, T> > ret(lhs);
    00261       ret.base()
    00262         = new RightWeighted<M, Element<S, T> >(rhs, ret.base());
    00263       return ret;
    00264     }
    00265
    00266     template<typename M, typename W>
    00267     void swap(vcsn::rat::exp<M, W>& lhs,
    00268               vcsn::rat::exp<M, W>& rhs)
    00269     {
    00270       lhs.swap(rhs);
    00271     }
    00272
    00273   } // End of namespace rat.
    00274
    00275 } // End of namespace vcsn.
    00276
    00277 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_EXP_HXX