17 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_NODES_HXX
18 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_NODES_HXX
20 # include <vaucanson/algebra/implementation/series/rat/nodes.hh>
26 template<
class M_,
class W_>
28 DefaultMutableNodeVisitor<M_,W_>::product(Node<M_, W_>* lhs,
35 template<
class M_,
class W_>
36 void DefaultMutableNodeVisitor<M_,W_>::sum(Node<M_, W_>* lhs,
43 template<
class M_,
class W_>
49 template<
class M_,
class W_>
50 void DefaultMutableNodeVisitor<M_,W_>::left_weight(W_&,
56 template<
class M_,
class W_>
57 void DefaultMutableNodeVisitor<M_,W_>::right_weight(W_&,
63 template<
class M_,
class W_>
64 void DefaultMutableNodeVisitor<M_,W_>::constant( M_&)
67 template<
class M_,
class W_>
68 void DefaultMutableNodeVisitor<M_,W_>::zero()
71 template<
class M_,
class W_>
72 void DefaultMutableNodeVisitor<M_,W_>::one()
80 template<
typename M_,
typename W_>
85 template<
typename M_,
typename W_>
92 template <
class M_,
class W_>
96 template <
class M_,
class W_>
97 typename Node<M_, W_>::type
98 Zero<M_,W_>::what()
const
100 return Node<M_, W_>::zero;
103 template <
class M_,
class W_>
105 Zero<M_,W_>::clone()
const
107 Node<M_, W_>* p =
new Zero<M_, W_>;
111 template <
class M_,
class W_>
113 Zero<M_,W_>::accept(ConstNodeVisitor<M_, W_>& v)
const
118 template <
class M_,
class W_>
122 return (
dynamic_cast<const Zero<M_, W_>*
>(&other) == 0);
125 template <
class M_,
class W_>
127 Zero<M_,W_>::operator<(
const Node<M_, W_>& other)
const
129 return what() < other.what();
132 template <
class M_,
class W_>
141 template<
typename M_,
typename W_>
145 template<
typename M_,
typename W_>
146 typename Node<M_, W_>::type
147 One<M_,W_>::what()
const
149 return Node<M_, W_>::one;
152 template<
typename M_,
typename W_>
154 One<M_,W_>::clone()
const
156 Node<M_, W_>* p =
new One<M_, W_>;
160 template<
typename M_,
typename W_>
162 One<M_,W_>::accept(ConstNodeVisitor<M_, W_>& v)
const
167 template<
typename M_,
typename W_>
171 return (
dynamic_cast<const One<M_, W_>*
>(&other) == 0);
174 template<
typename M_,
typename W_>
176 One<M_,W_>::operator<(
const Node<M_, W_>& other)
const
178 return what() < other.what();
181 template<
typename M_,
typename W_>
190 template<
typename M_,
typename W_>
191 Constant<M_,W_>::Constant(
const M_ &v) : value_(v)
194 template<
typename M_,
typename W_>
195 typename Node<M_, W_>::type
196 Constant<M_,W_>::what()
const
198 return Node<M_, W_>::constant;
201 template<
typename M_,
typename W_>
203 Constant<M_,W_>::clone()
const
205 Node<M_, W_>* p =
new Constant<M_, W_>(value_);
209 template<
typename M_,
typename W_>
211 Constant<M_,W_>::accept(ConstNodeVisitor<M_, W_>& v)
const
216 template<
typename M_,
typename W_>
220 const Constant<M_, W_>* otherp =
221 dynamic_cast<const Constant<M_, W_>*
>(&other);
224 return (value_ != otherp->value_);
227 template<
typename M_,
typename W_>
229 Constant<M_,W_>::operator<(
const Node<M_, W_>& other)
const
231 const Constant<M_, W_>* otherp =
232 dynamic_cast<const Constant<M_, W_>*
>(&other);
234 return value_ < otherp->value_;
236 return what() < other.what();
239 template<
typename M_,
typename W_>
241 Constant<M_,W_>::~Constant()
247 template<
typename M_,
typename W_>
248 LeftWeighted<M_,W_>::LeftWeighted(
const W_& w,
const Node<M_, W_>& c)
249 : weight_(w), child_(c.clone())
252 template<
typename M_,
typename W_>
253 LeftWeighted<M_,W_>::LeftWeighted(
const W_& w, Node<M_, W_>* c)
254 : weight_(w), child_(c)
257 template<
typename M_,
typename W_>
258 LeftWeighted<M_,W_>::LeftWeighted(
const W_& w)
260 child_(new One<M_, W_>)
263 template<
typename M_,
typename W_>
264 typename Node<M_, W_>::type
265 LeftWeighted<M_,W_>::what()
const
267 return Node<M_, W_>::lweight;
270 template<
typename M_,
typename W_>
272 LeftWeighted<M_,W_>::clone()
const
274 Node<M_, W_>* p =
new LeftWeighted<M_, W_>(weight_, *child_);
278 template<
typename M_,
typename W_>
280 LeftWeighted<M_,W_>::accept(ConstNodeVisitor<M_, W_>& v)
const
282 v.left_weight(weight_, child_);
285 template<
typename M_,
typename W_>
289 const LeftWeighted<M_, W_>* otherp =
290 dynamic_cast<const LeftWeighted<M_, W_>*
>(&other);
291 if(!otherp || (weight_ != otherp->weight_))
293 return (*child_ != *otherp->child_);
296 template<
typename M_,
typename W_>
298 LeftWeighted<M_,W_>::operator<(
const Node<M_, W_>& other)
const
300 const LeftWeighted<M_, W_>* otherp =
301 dynamic_cast<const LeftWeighted<M_, W_>*
>(&other);
304 if (weight_ == otherp->weight_)
305 return *child_ < *otherp->child_;
307 return weight_ < otherp->weight_;
310 return what() < other.what();
313 template<
typename M_,
typename W_>
315 LeftWeighted<M_,W_>::~LeftWeighted()
323 template<
typename M_,
typename W_>
324 RightWeighted<M_,W_>::RightWeighted(
const W_& w,
const Node<M_, W_>& c)
325 : weight_(w), child_(c.clone())
328 template<
typename M_,
typename W_>
329 RightWeighted<M_,W_>::RightWeighted(
const W_& w, Node<M_, W_>* c)
330 : weight_(w), child_(c)
333 template<
typename M_,
typename W_>
334 RightWeighted<M_,W_>::RightWeighted(
const W_& w)
336 child_(new One<M_, W_>)
339 template<
typename M_,
typename W_>
340 typename Node<M_, W_>::type
341 RightWeighted<M_,W_>::what()
const
343 return Node<M_, W_>::rweight;
346 template<
typename M_,
typename W_>
348 RightWeighted<M_,W_>::clone()
const
350 Node<M_, W_>* p =
new RightWeighted<M_, W_>(weight_, *child_);
354 template<
typename M_,
typename W_>
356 RightWeighted<M_,W_>::accept(ConstNodeVisitor<M_, W_>& v)
const
358 v.right_weight(weight_, child_);
361 template<
typename M_,
typename W_>
365 const RightWeighted<M_, W_>* otherp =
366 dynamic_cast<const RightWeighted<M_, W_>*
>(&other);
367 if(!otherp || (weight_ != otherp->weight_))
369 return (*child_ != *otherp->child_);
372 template<
typename M_,
typename W_>
374 RightWeighted<M_,W_>::operator<(
const Node<M_, W_>& other)
const
376 const RightWeighted<M_, W_>* otherp =
377 dynamic_cast<const RightWeighted<M_, W_>*
>(&other);
380 if (weight_ == otherp->weight_)
381 return *child_ < *otherp->child_;
383 return weight_ < otherp->weight_;
386 return what() < other.what();
389 template<
typename M_,
typename W_>
391 RightWeighted<M_,W_>::~RightWeighted()
399 template <
class M_,
class W_>
400 Star<M_,W_>::Star(
const Node<M_, W_>& other)
401 : child_(other.clone())
404 template <
class M_,
class W_>
405 Star<M_,W_>::Star(Node<M_, W_>* other)
409 template <
class M_,
class W_>
410 typename Node<M_, W_>::type
411 Star<M_,W_>::what()
const
416 template <
class M_,
class W_>
418 Star<M_,W_>::clone()
const
420 Node<M_, W_>* p =
new Star<M_, W_>(*child_);
424 template <
class M_,
class W_>
426 Star<M_,W_>::accept(ConstNodeVisitor<M_, W_>& v)
const
431 template <
class M_,
class W_>
435 const Star<M_, W_>* otherp =
436 dynamic_cast<const Star<M_, W_>*
>(&other);
439 return (*child_ != *otherp->child_);
442 template <
class M_,
class W_>
444 Star<M_,W_>::operator<(
const Node<M_, W_>& other)
const
446 const Star<M_, W_>* otherp =
447 dynamic_cast<const Star<M_, W_>*
>(&other);
449 return *child_ < *otherp->child_;
451 return what() < other.what();
454 template <
class M_,
class W_>
464 template <
class M_,
class W_>
465 Product<M_,W_>::Product(
const Node<M_, W_>& left,
466 const Node<M_, W_>& right)
467 : left_(left.clone()), right_(right.clone())
470 template <
class M_,
class W_>
471 Product<M_,W_>::Product(Node<M_, W_>* left, Node<M_, W_>* right)
472 : left_(left), right_(right)
475 template <
class M_,
class W_>
476 typename Node<M_, W_>::type
477 Product<M_,W_>::what()
const
479 return Node<M_, W_>::prod;
482 template <
class M_,
class W_>
484 Product<M_,W_>::clone()
const
486 Node<M_, W_>* p =
new Product<M_, W_>(*left_, *right_);
490 template <
class M_,
class W_>
492 Product<M_,W_>::accept(ConstNodeVisitor<M_, W_>& v)
const
494 return v.product(left_, right_);
497 template <
class M_,
class W_>
501 const Product<M_, W_>* otherp =
502 dynamic_cast<const Product<M_, W_>*
>(&other);
503 if(!otherp || (*left_ != *otherp->left_))
505 return (*right_ != *otherp->right_);
508 template <
class M_,
class W_>
510 Product<M_,W_>::operator<(
const Node<M_, W_>& other)
const
512 const Product<M_, W_>* otherp =
513 dynamic_cast<const Product<M_, W_>*
>(&other);
516 if (*left_ != *otherp->left_)
517 return *left_ < *otherp->left_;
519 return *right_ < *otherp->right_;
522 return what() < other.what();
525 template <
class M_,
class W_>
527 Product<M_,W_>::~Product()
536 template<
typename M_,
typename W_>
537 Sum<M_,W_>::Sum(
const Node<M_, W_>& left,
const Node<M_, W_>& right)
538 : left_(left.clone()), right_(right.clone())
541 template<
typename M_,
typename W_>
542 Sum<M_,W_>::Sum(Node<M_, W_>* left, Node<M_, W_>* right)
543 : left_(left), right_(right)
546 template<
typename M_,
typename W_>
548 Sum<M_,W_>::accept(ConstNodeVisitor<M_, W_>& v)
const
550 return v.sum(left_, right_);
553 template<
typename M_,
typename W_>
554 typename Node<M_, W_>::type
555 Sum<M_,W_>::what()
const
557 return Node<M_, W_>::sum;
560 template<
typename M_,
typename W_>
562 Sum<M_,W_>::clone()
const
564 Node<M_, W_>* p =
new Sum<M_, W_>(*left_, *right_);
568 template<
typename M_,
typename W_>
572 const Sum<M_, W_>* otherp =
573 dynamic_cast<const Sum<M_, W_>*
>(&other);
579 return (*left_ != *otherp->left_) || (*right_ != *otherp->right_);
582 template<
typename M_,
typename W_>
584 Sum<M_,W_>::operator<(
const Node<M_, W_>& other)
const
586 const Sum<M_, W_>* otherp =
587 dynamic_cast<const Sum<M_, W_>*
>(&other);
590 if (*left_ != *otherp->left_)
591 return *left_ < *otherp->left_;
593 return *right_ < *otherp->right_;
596 return what() < other.what();
599 template<
typename M_,
typename W_>
611 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_NODES_HXX