xml_exp_visitor.hxx

00001 // xml_exp_visitor.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2006 The Vaucanson Group.
00006 //
00007 // This program is free software; you can redistribute it and/or
00008 // modify it under the terms of the GNU General Public License
00009 // as published by the Free Software Foundation; either version 2
00010 // of the License, or (at your option) any later version.
00011 //
00012 // The complete GNU General Public Licence Notice can be found as the
00013 // `COPYING' file in the root directory.
00014 //
00015 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
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   } // End of namespace rat.
00129 
00130 } // End of namespace vcsn.
00131 
00132 
00133 
00134 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_XML_EXP_VISITOR_HXX

Generated on Fri Jul 28 12:18:56 2006 for Vaucanson by  doxygen 1.4.6