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 # 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 # if (not defined (VCSN_SANITY_CHECK)) or (defined (VCSN_USE_XML))
00132 template<typename LetterT, typename WeightT>
00133 xercesc::DOMElement* exp<LetterT, WeightT>::xml_tree(
00134 xercesc::DOMDocument* doc, char* node_name) const
00135 {
00136 XmlExpVisitor<monoid_elt_value_t, semiring_elt_value_t> v(doc, node_name);
00137 accept(v);
00138 return v.get();
00139 }
00140 # endif
00141
00142 template<typename LetterT, typename WeightT>
00143 typename exp<LetterT, WeightT>::node_t* &
00144 exp<LetterT, WeightT>::base()
00145 {
00146 return base_;
00147 }
00148
00149 template<typename LetterT, typename WeightT>
00150 typename exp<LetterT, WeightT>::node_t* const &
00151 exp<LetterT, WeightT>::base() const
00152 {
00153 return 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 bool exp<LetterT, WeightT>::operator != (const exp& other) const
00164 {
00165 return *base_ != *other.base_;
00166 }
00167
00168 template<typename LetterT, typename WeightT>
00169 bool exp<LetterT, WeightT>::operator < (const exp& other) const
00170 {
00171 return *base_ < *other.base_;
00172 }
00173
00174 template<typename LetterT, typename WeightT>
00175 exp<LetterT, WeightT>
00176 exp<LetterT, WeightT>::clone() const
00177 {
00178 return exp(base_->clone());
00179 }
00180
00181 template<typename LetterT, typename WeightT>
00182 exp<LetterT, WeightT>
00183 exp<LetterT, WeightT>::one()
00184 {
00185 return exp(new n_one_t);
00186 }
00187
00188 template<typename LetterT, typename WeightT>
00189 exp<LetterT, WeightT> exp<LetterT, WeightT>::zero()
00190 {
00191 return exp(new n_zero_t);
00192 }
00193
00194 template<typename LetterT, typename WeightT>
00195 exp<LetterT, WeightT> exp<LetterT, WeightT>::
00196 constant(const monoid_elt_value_t& l)
00197 {
00198 return exp(new n_const_t(l));
00199 }
00200
00201 template<typename LetterT, typename WeightT>
00202 bool exp<LetterT, WeightT>::starable()
00203 {
00204 return true;
00205 }
00206
00207 template<typename M, typename W>
00208 const exp<M, W> operator * (const exp<M, W>& lhs,
00209 const exp<M, W>& rhs)
00210 {
00211 exp<M, W> ret(lhs);
00212 ret *= rhs;
00213 return ret;
00214 }
00215
00216 template<typename M, typename W>
00217 exp<M, W> operator + (const exp<M, W>& lhs,
00218 const exp<M, W>& rhs)
00219 {
00220 exp<M, W> ret(lhs);
00221 ret += rhs;
00222 return ret;
00223 }
00224
00225 template<typename M, typename W>
00226 exp<M, W> operator * (const W& lhs,
00227 const exp<M, W>& rhs)
00228 {
00229 exp<M, W> ret(rhs);
00230 ret.base() = new LeftWeighted<M, W>(lhs, ret.base());
00231 return ret;
00232 }
00233
00234 template<typename M, typename W>
00235 exp<M, W> operator * (const exp<M, W>& lhs,
00236 const W& rhs)
00237 {
00238 exp<M, W> ret(lhs);
00239 ret.base() = new RightWeighted<M, W>(rhs, ret.base());
00240 return ret;
00241 }
00242
00243
00244
00245
00246 template<typename M, typename S, typename T>
00247 exp<M, Element<S, T> >
00248 operator*(const Element<S, T>& lhs,
00249 const exp<M, Element<S, T> >& rhs)
00250 {
00251 exp<M, Element<S, T> > ret(rhs);
00252 ret.base()
00253 = new LeftWeighted<M, Element<S, T> >(lhs, ret.base());
00254 return ret;
00255 }
00256
00257 template<typename M, typename S, typename T>
00258 exp<M, Element<S, T> >
00259 operator*(const exp<M, Element<S, T> >& lhs,
00260 const Element<S, T>& rhs)
00261 {
00262 exp<M, Element<S, T> > ret(lhs);
00263 ret.base()
00264 = new RightWeighted<M, Element<S, T> >(rhs, ret.base());
00265 return ret;
00266 }
00267
00268 template<typename M, typename W>
00269 void swap(vcsn::rat::exp<M, W>& lhs,
00270 vcsn::rat::exp<M, W>& rhs)
00271 {
00272 lhs.swap(rhs);
00273 }
00274
00275 }
00276
00277 }
00278
00279 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_EXP_HXX