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