- Main Page
- Modules
- Namespaces
- Classes
- Files
- Related Pages

# 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, const 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       weight_ = 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       weight_or_star(node);
    00108     }
    00109
    00110     template<typename M_, typename W_>
    00111     void
    00112     XmlExpVisitor<M_, W_>::constant(const M_& m)
    00113     {
    00114       std::stringstream ss;
    00115       ss << m;
    00116       xercesc::DOMElement* word = doc_->createElement(transcode("word"));
    00117       word->setAttribute(transcode("value"), transcode(ss.str()));
    00118       if (weight_.size())
    00119       {
    00120         word->setAttribute(transcode("weight"), transcode(weight_));
    00121         weight_ = "";
    00122       }
    00123       current_->appendChild(word);
    00124     }
    00125
    00126     template<typename M_, typename W_>
    00127     void XmlExpVisitor<M_, W_>::zero()
    00128     {
    00129       xercesc::DOMElement* zero = doc_->createElement(transcode("zero"));
    00130       current_->appendChild(zero);
    00131     }
    00132
    00133     template<typename M_, typename W_>
    00134     void XmlExpVisitor<M_, W_>::one()
    00135     {
    00136       xercesc::DOMElement* identity = doc_->createElement(transcode("identity"));
    00137       current_->appendChild(identity);
    00138       if (weight_.size())
    00139       {
    00140         identity->setAttribute(transcode("weight"), transcode(weight_));
    00141         weight_ = "";
    00142       }
    00143     }
    00144
    00145     template<typename M_, typename W_>
    00146     xercesc::DOMElement*
    00147     XmlExpVisitor<M_, W_>::get() const
    00148     {
    00149       return label_;
    00150     }
    00151
    00152     template<typename M_, typename W_>
    00153     xercesc::DOMDocument*
    00154     XmlExpVisitor<M_, W_>::set(xercesc::DOMDocument* v)
    00155     {
    00156       this->doc_ = v;
    00157       return this->doc_;
    00158     }
    00159
    00160
    00161   } // End of namespace rat.
    00162
    00163 } // End of namespace vcsn.
    00164
    00165
    00166
    00167 #endif // ! VCSN_ALGEBRA_IMPLEMENTATION_SERIES_RAT_XML_EXP_VISITOR_HXX