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 # include <vaucanson/xml/strings.hh>
00025 
00026 namespace vcsn {
00027 
00028   namespace rat {
00029 
00030     using xml::transcode;
00031 
00032     template<typename M_, typename W_>
00033     XmlExpVisitor<M_,W_>::XmlExpVisitor(xercesc::DOMDocument* doc, char* node_name) :
00034       doc_(doc),
00035       label_(doc_->createElement(transcode(node_name))),
00036       current_(label_)
00037     {}
00038 
00039 
00040     template<typename M_, typename W_>
00041     void
00042     XmlExpVisitor<M_,W_>::sum_or_product(const Node<M_, W_>* left_,
00043                                          const Node<M_, W_>* right_)
00044     {
00045       left_->accept(*this);
00046       right_->accept(*this);
00047     }
00048 
00049     template<typename M_, typename W_>
00050     void
00051     XmlExpVisitor<M_, W_>::weight_or_star(const Node<M_, W_>* node)
00052     {
00053       node->accept(*this);
00054     }
00055 
00056     template<typename M_, typename W_>
00057     void
00058     XmlExpVisitor<M_, W_>::product(const Node<M_, W_>* left_,
00059                                    const Node<M_, W_>* right_)
00060     {
00061       xercesc::DOMElement* tmp = current_;
00062       current_ = doc_->createElement(transcode("product"));
00063       sum_or_product(left_, right_);
00064       tmp->appendChild(current_);
00065       current_ = tmp;
00066     }
00067 
00068     template<typename M_, typename W_>
00069     void
00070     XmlExpVisitor<M_, W_>::sum(const Node<M_, W_>* left_,
00071                                const Node<M_, W_>* right_)
00072     {
00073       xercesc::DOMElement* tmp = current_;
00074       current_ = doc_->createElement(transcode("sum"));
00075       sum_or_product(left_, right_);
00076       tmp->appendChild(current_);
00077       current_ = tmp;
00078     }
00079 
00080     template<typename M_, typename W_>
00081     void
00082     XmlExpVisitor<M_, W_>::star(const Node<M_, W_>* node)
00083     {
00084       xercesc::DOMElement* tmp = current_;
00085       current_ = doc_->createElement(transcode("star"));
00086       weight_or_star(node);
00087       tmp->appendChild(current_);
00088       current_ = tmp;
00089     }
00090 
00091     template<typename M_, typename W_>
00092     void
00093     XmlExpVisitor<M_, W_>::left_weight(const W_& w, const Node<M_, W_>* node)
00094     {
00095       std::stringstream ss;
00096       ss << w;
00097       current_->setAttribute(transcode("weight"), transcode(ss.str()));
00098       weight_or_star(node);
00099     }
00100 
00101     template<typename M_, typename W_>
00102     void
00103     XmlExpVisitor<M_, W_>::right_weight(const W_& w, const Node<M_, W_>* node)
00104     {
00105       std::stringstream ss;
00106       ss << w;
00107       current_->setAttribute(transcode("weight"), transcode(ss.str()));
00108       weight_or_star(node);
00109     }
00110 
00111     template<typename M_, typename W_>
00112     void
00113     XmlExpVisitor<M_, W_>::constant(const M_& m)
00114     {
00115       std::stringstream ss;
00116       ss << m;
00117       xercesc::DOMElement* word = doc_->createElement(transcode("word"));
00118       word->setAttribute(transcode("value"), transcode(ss.str()));
00119       current_->appendChild(word);
00120     }
00121 
00122     template<typename M_, typename W_>
00123     void XmlExpVisitor<M_, W_>::zero()
00124     {
00125       xercesc::DOMElement* zero = doc_->createElement(transcode("zeroVal"));
00126       current_->appendChild(zero);
00127     }
00128 
00129     template<typename M_, typename W_>
00130     void XmlExpVisitor<M_, W_>::one()
00131     {
00132       xercesc::DOMElement* identity = doc_->createElement(transcode("identityVal"));
00133       current_->appendChild(identity);
00134     }
00135 
00136     template<typename M_, typename W_>
00137     xercesc::DOMElement*
00138     XmlExpVisitor<M_, W_>::get() const
00139     {
00140       return label_;
00141     }
00142 
00143     template<typename M_, typename W_>
00144     xercesc::DOMDocument*
00145     XmlExpVisitor<M_, W_>::set(xercesc::DOMDocument* v)
00146     {
00147       this->doc_ = v;
00148       return this->doc_;
00149     }
00150 
00151 
00152   } // End of namespace rat.
00153 
00154 } // End of namespace vcsn.
00155 
00156 
00157 
00158 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_XML_EXP_VISITOR_HXX

Generated on Sat Jul 29 17:13:13 2006 for Vaucanson by  doxygen 1.4.6