17 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_DUMP_VISITOR_HXX
18 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_DUMP_VISITOR_HXX
20 # include <vaucanson/algebra/concept/letter.hh>
21 # include <vaucanson/algebra/implementation/series/rat/dump_visitor.hh>
22 # include <vaucanson/algebra/implementation/series/rat/nodes.hh>
38 static const int idx = std::ios::xalloc();
47 static const int idx = std::ios::xalloc();
56 static const int idx = std::ios::xalloc();
66 template <
class Word,
class Weight,
typename Semiring,
typename Mono
id>
67 class DumpVisitor :
public ConstNodeVisitor<Word, Weight>
72 typedef Word monoid_elt_value_t;
73 typedef Weight semiring_elt_value_t;
74 typedef Node<Word, Weight> node_t;
75 typedef algebra::MonoidRep<Monoid> monoid_rep_t;
76 typedef boost::shared_ptr<monoid_rep_t> shared_monoid_rep_t;
77 typedef algebra::SeriesRep<Semiring, Monoid> series_rep_t;
78 typedef boost::shared_ptr<series_rep_t> shared_series_rep_t;
79 typedef algebra::MonoidRepDefault<Monoid> default_monoid_rep_t;
80 typedef algebra::SeriesRepDefault<Semiring, Monoid>
83 DumpVisitor(std::ostream& ostr,
85 shared_series_rep_t sr = default_series_rep_t::
89 monoid_rep_(monoid.representation()),
92 if (not ostr_.pword(rat::zero()))
93 ostr_ << setzero(series_rep_->zero);
95 if (not ostr_.pword(rat::id()))
96 ostr_ << setid(monoid_rep_->empty);
108 enclose_if(
const bool cond,
const node_t* node)
112 ostr_ << series_rep_->open_par;
114 ostr_ << series_rep_->close_par;
122 NODE_LWEIGHT = Node<Word, Weight>::lweight,
123 NODE_RWEIGHT = Node<Word, Weight>::rweight,
124 NODE_PROD = Node<Word, Weight>::prod,
125 NODE_SUM = Node<Word, Weight>::sum,
129 product_print_child(
const node_t* child)
131 switch (child->what())
136 enclose_if(not (ostr_.iword(print_mode()) & MODE_ADD), child);
139 child->accept(*
this);
148 product(
const node_t* lhs,
const node_t* rhs)
150 const long verbose = ostr_.iword(print_mode()) & MODE_MUL;
153 ostr_ << series_rep_->open_par;
155 product_print_child(lhs);
156 ostr_ << series_rep_->times;
157 product_print_child(rhs);
160 ostr_ << series_rep_->close_par;
165 sum(
const node_t* lhs,
const node_t* rhs)
167 const long verbose = ostr_.iword(print_mode()) & MODE_ADD;
170 ostr_ << series_rep_->open_par;
173 ostr_ << series_rep_->plus;
177 ostr_ << series_rep_->close_par;
182 star(
const node_t* node)
184 const long mode = ostr_.iword(print_mode());
185 const unsigned node_type = node->what();
190 enclose_if(not (mode & MODE_ADD), node);
193 enclose_if(not (mode & MODE_MUL), node);
196 enclose_if(not (mode & MODE_LWEIGHT), node);
199 enclose_if(not (mode & MODE_RWEIGHT), node);
202 enclose_if(mode & MODE_STAR, node);
205 ostr_ << series_rep_->star;
210 left_weight(
const semiring_elt_value_t& w,
const node_t* node)
212 const long mode = ostr_.iword(print_mode());
213 const unsigned node_type = node->what();
215 bool enclose_all (
false);
220 verbose = not (mode & MODE_MUL);
223 verbose = not (mode & MODE_ADD);
226 verbose = not (mode & MODE_LWEIGHT);
229 verbose = not (mode & MODE_RWEIGHT);
233 enclose_all = mode & MODE_LWEIGHT;
238 ostr_ << series_rep_->open_par;
240 ostr_ << series_rep_->open_weight << w
241 << series_rep_->close_weight << series_rep_->spaces.front();
242 enclose_if(verbose, node);
245 ostr_ << series_rep_->close_par;
250 right_weight(
const semiring_elt_value_t& w,
const node_t* node)
252 const long mode = ostr_.iword(print_mode());
253 const unsigned node_type = node->what();
255 bool enclose_all (
false);
260 verbose = not (mode & MODE_MUL);
263 verbose = not (mode & MODE_ADD);
266 verbose = not (mode & MODE_LWEIGHT);
269 verbose = not (mode & MODE_RWEIGHT);
273 enclose_all = mode & MODE_RWEIGHT;
278 ostr_ << series_rep_->open_par;
280 enclose_if(verbose, node);
281 ostr_ << series_rep_->spaces.front() << series_rep_->open_weight
282 << w << series_rep_->close_weight;
285 ostr_ << series_rep_->close_par;
290 constant(
const monoid_elt_value_t& m)
300 ostr_ << *static_cast<const std::string*> (ostr_.pword(rat::zero()));
308 ostr_ << *static_cast<const std::string*> (ostr_.pword(rat::id()));
313 const Monoid& monoid_;
314 shared_monoid_rep_t monoid_rep_;
315 shared_series_rep_t series_rep_;
336 setpm::setpm(print_mode_t mode) : mode_ (mode)
342 setpm::operator () (std::ostream& ostr)
const
344 ostr.iword(print_mode()) = mode_;
354 getpm(std::ostream& ostr)
356 return print_mode_t (ostr.iword(print_mode()));
364 setzero::setzero(
const std::string& zero) : z_ (zero)
370 setzero::operator () (std::ostream& ostr)
const
372 const int idx = zero();
374 if (not ostr.pword(idx))
375 ostr.register_callback(misc::pword_delete<std::string>, idx);
377 delete static_cast<std::string*
> (ostr.pword(idx));
378 ostr.pword(idx) =
new std::string (z_);
387 setid::setid(
const std::string&
id) : i_ (id)
393 setid::operator () (std::ostream& ostr)
const
395 const int idx = id();
397 if (not ostr.pword(idx))
398 ostr.register_callback(misc::pword_delete<std::string>, idx);
400 delete static_cast<std::string*
> (ostr.pword(idx));
401 ostr.pword(idx) =
new std::string (i_);
409 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_DUMP_VISITOR_HXX