00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_XML_EXP_VISITOR_HXX
00018 # define VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_XML_EXP_VISITOR_HXX
00019
00020 # include <vaucanson/algebra/implementation/series/rat/xml_exp_visitor.hh>
00021
00022 # include <algorithm>
00023 # include <sstream>
00024
00025 namespace vcsn {
00026
00027 namespace rat {
00028
00029 template<typename M_, typename W_>
00030 void
00031 XmlExpVisitor<M_,W_>::sum_or_product(const Node<M_, W_>* left_,
00032 const Node<M_, W_>* right_)
00033 {
00034 left_->accept(*this);
00035 right_->accept(*this);
00036 }
00037
00038 template<typename M_, typename W_>
00039 void
00040 XmlExpVisitor<M_, W_>::weight_or_star(const Node<M_, W_>* node)
00041 {
00042 node->accept(*this);
00043 }
00044
00045 template<typename M_, typename W_>
00046 void
00047 XmlExpVisitor<M_, W_>::product(const Node<M_, W_>* left_,
00048 const Node<M_, W_>* right_)
00049 {
00050 xercesc::DOMElement* tmp = current_;
00051 current_ = doc_->createElement(STR2XML("product"));
00052 sum_or_product(left_, right_);
00053 tmp->appendChild(current_);
00054 current_ = tmp;
00055 }
00056
00057 template<typename M_, typename W_>
00058 void
00059 XmlExpVisitor<M_, W_>::sum(const Node<M_, W_>* left_,
00060 const Node<M_, W_>* right_)
00061 {
00062 xercesc::DOMElement* tmp = current_;
00063 current_ = doc_->createElement(STR2XML("sum"));
00064 sum_or_product(left_, right_);
00065 tmp->appendChild(current_);
00066 current_ = tmp;
00067 }
00068
00069 template<typename M_, typename W_>
00070 void
00071 XmlExpVisitor<M_, W_>::star(const Node<M_, W_>* node)
00072 {
00073 current_->setAttribute(STR2XML("star"), STR2XML("true"));
00074 weight_or_star(node);
00075 }
00076
00077 template<typename M_, typename W_>
00078 void
00079 XmlExpVisitor<M_, W_>::left_weight(const W_& w, const Node<M_, W_>* node)
00080 {
00081 std::stringstream ss;
00082 ss << w;
00083 current_->setAttribute(STR2XML("weight"), STR2XML(ss.str().c_str()));
00084 weight_or_star(node);
00085 }
00086
00087 template<typename M_, typename W_>
00088 void
00089 XmlExpVisitor<M_, W_>::right_weight(const W_& w, const Node<M_, W_>* node)
00090 {
00091 std::stringstream ss;
00092 ss << w;
00093 current_->setAttribute(STR2XML("weight"), STR2XML(ss.str().c_str()));
00094 weight_or_star(node);
00095 }
00096
00097 template<typename M_, typename W_>
00098 void
00099 XmlExpVisitor<M_, W_>::constant(const M_& m)
00100 {
00101 std::stringstream ss;
00102 ss << m;
00103 xercesc::DOMElement* word = doc_->createElement(STR2XML("word"));
00104 word->setAttribute(STR2XML("value"), STR2XML(ss.str().c_str()));
00105 current_->appendChild(word);
00106 }
00107
00108 template<typename M_, typename W_>
00109 void XmlExpVisitor<M_, W_>::zero()
00110 {
00111 xercesc::DOMElement* zero = doc_->createElement(STR2XML("zero_val"));
00112 current_->appendChild(zero);
00113 }
00114
00115 template<typename M_, typename W_>
00116 void XmlExpVisitor<M_, W_>::one()
00117 {
00118 xercesc::DOMElement* identity = doc_->createElement(STR2XML("identity_val"));
00119 current_->appendChild(identity);
00120 }
00121
00122 template<typename M_, typename W_>
00123 xercesc::DOMElement* XmlExpVisitor<M_, W_>::get() const
00124 {
00125 return label_;
00126 }
00127
00128 }
00129
00130 }
00131
00132
00133
00134 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_XML_EXP_VISITOR_HXX