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

- File List
- File Members

# rw.hxx

    00001 // rw.hxx: this file is part of the Vaucanson project.
    00002 //
    00003 // Vaucanson, a generic library for finite state machines.
    00004 //
    00005 // Copyright (C) 2007, 2008, 2011 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
    00018 #ifndef VCSN_XML_CONTEXTS_RW_HXX
    00019 # define VCSN_XML_CONTEXTS_RW_HXX
    00020
    00021 # include <vaucanson/xml/builders.hh>
    00022
    00023 namespace vcsn
    00024 {
    00025   namespace xml
    00026   {
    00030     template <typename T>
    00031     SeriesSemiringHandler<T>::SeriesSemiringHandler (xercesc::SAX2XMLReader* parser,
    00032                                                Handler& root,
    00033                                                T& semiring)
    00034     : Handler(parser, root),
    00035       semiring_(semiring),
    00036       ssemiringh_(0),
    00037       monoidh_(0),
    00038       unsuph_(parser, *this)
    00039     {
    00040     }
    00041
    00042     template <typename T>
    00043     void
    00044     SeriesSemiringHandler<T>::start (const XMLCh* const,
    00045                                  const XMLCh* const localname,
    00046                                  const XMLCh* const,
    00047                                  const xercesc::Attributes& attrs)
    00048     {
    00049       if (xercesc::XMLString::equals(eq_.semiring, localname))
    00050       {
    00051         ssemiringh_ = builders::create_semiringh(semiring_.semiring(), attrs, parser_, *this);
    00052         parser_->setContentHandler(ssemiringh_);
    00053       }
    00054       else if (xercesc::XMLString::equals(eq_.monoid, localname))
    00055       {
    00056         monoidh_ = builders::create_monoidh(const_cast <typename T::monoid_t&>(semiring_.monoid()), attrs, parser_, *this);
    00057         parser_->setContentHandler(monoidh_);
    00058       }
    00059       else
    00060         error::token(localname);
    00061     }
    00062
    00063     template <typename T>
    00064     void
    00065     SeriesSemiringHandler<T>::end (const XMLCh* const,
    00066                                const XMLCh* const localname,
    00067                                const XMLCh* const)
    00068     {
    00069       if (xercesc::XMLString::equals(eq_.semiring, localname))
    00070         parser_->setContentHandler(&root_);
    00071       else
    00072         error::token(localname);
    00073       delete ssemiringh_;
    00074       delete monoidh_;
    00075     }
    00076
    00077     namespace builders
    00078     {
    00079       template <typename S, typename K, typename T>
    00080       typename TRANStype::semiring_t*
    00081       create_semiring (TRANStype&,
    00082                        const XMLCh* const,
    00083                        const xercesc::Attributes&)
    00084       {
    00085         typename TRANStype::semiring_t::monoid_t::alphabet_t    at;
    00086         typename TRANStype::semiring_t::monoid_t        md(at);
    00087         typename TRANStype::semiring_t::semiring_t      ssg;
    00088         typedef typename TRANStype::semiring_t semiring_t;
    00089         semiring_t*     semiring = new semiring_t(ssg, md);
    00090
    00091         return semiring;
    00092       }
    00093
    00094       template <typename S, typename T>
    00095       Handler*
    00096       create_semiringh(TRANSsemiring& semiring,
    00097                        const xercesc::Attributes&,
    00098                        xercesc::SAX2XMLReader* parser,
    00099                        Handler& root)
    00100       {
    00101         return new SeriesSemiringHandler<TRANSsemiring >(parser, root, semiring);
    00102       }
    00103
    00104     } // !builders
    00105
    00109     namespace builders
    00110     {
    00111       template <typename S, typename T>
    00112       const char* get_semiring_operations(const vcsn::algebra::Series<S, T>&)
    00113       {
    00114         return "SHOULD not append";
    00115       }
    00116     } // !builders
    00117
    00118     namespace builders
    00119     {
    00120       template <typename S, typename K, typename T>
    00121       void
    00122       create_semiring_node(const TRANStype& aut,
    00123                            xercesc::DOMDocument* doc,
    00124                            xercesc::DOMElement* root)
    00125       {
    00126         xercesc::DOMElement* node = tools::create_element(doc, "semiring");
    00127         tools::set_attribute(node, "type", "series");
    00128         xercesc::DOMElement* semiringn = tools::create_element(doc, "semiring");
    00129         xercesc::DOMElement* monoid = tools::create_element(doc, "monoid");
    00130
    00131         typedef typename TRANStype::semiring_elt_t::semiring_elt_t semiring_elt_t;
    00132         semiring_elt_t semiring;
    00133         tools::set_attribute(semiringn, "type", "numerical");
    00134         tools::set_attribute(semiringn, "set", get_semiring_set(semiring.value()));
    00135         tools::set_attribute(semiringn, "operations", get_semiring_operations(semiring.structure()));
    00136
    00137         tools::set_attribute(monoid, "type", "free");
    00138         tools::set_attribute(monoid, "genDescrip", "enum");
    00139         tools::set_attribute(monoid, "genKind", algebra::letter_traits<typename TRANStype::semiring_t::monoid_t::alphabet_t::letter_t>::kind());
    00140         typedef typename TRANStype::semiring_t::monoid_t::alphabet_t::const_iterator alphabet_iterator;
    00141         for_all_letters(l, aut.series().semiring().monoid().alphabet())
    00142         {
    00143           std::ostringstream letter;
    00144           xercesc::DOMElement* gen = tools::create_element(doc, "monGen");
    00145           letter << *l;
    00146           tools::set_attribute(gen, "value", letter.str());
    00147           monoid->appendChild(gen);
    00148         }
    00149         tools::set_attribute(monoid, "genSort", get_monoid_gen_sort(*(aut.series().semiring().monoid().alphabet().begin())));
    00150         node->appendChild(semiringn);
    00151         node->appendChild(monoid);
    00152         root->appendChild(node);
    00153       }
    00154     }
    00155
    00160     SParamTRANS
    00161     WeightHandler<TRANSseries >::WeightHandler (xercesc::SAX2XMLReader* parser,
    00162                                Handler& root,
    00163                                TRANSseries param)
    00164       : RegexpHandler<TRANSseries >(parser, root, param),
    00165         weighth_(0)
    00166     {
    00167       end_ = eq_.weight;
    00168     }
    00169
    00170     SParamTRANS
    00171     void
    00172     WeightHandler<TRANSseries >::start (const XMLCh* const,
    00173                                  const XMLCh* const localname,
    00174                                  const XMLCh* const,
    00175                                  const xercesc::Attributes&)
    00176     {
    00177       //RegexpHandler<series_set_elt_t>* tmp = new RegexpHandler<series_set_elt_t>(parser_, *this,
    00178 //        algebra::identity_as<typename series_set_elt_t::value_t>::of(param_.structure().semiring()));
    00179       if (!(weighth_ = create_weighth(localname)))
    00180         error::token(localname);
    00181       else
    00182         parser_->setContentHandler(weighth_);
    00183     }
    00184
    00185     SParamTRANS
    00186     void
    00187     WeightHandler<TRANSseries >::end (const XMLCh* const,
    00188                                const XMLCh* const localname,
    00189                                const XMLCh* const)
    00190     {
    00191
    00192       using namespace xercesc;
    00193       if (XMLString::equals(end_, localname))
    00194       {
    00195         TRANSseries s = algebra::identity_as<typename TRANSseries::value_t>::of(param_.structure());
    00196         typename TRANSseries::semiring_elt_t w(weighth_->series());
    00197         param_ = param_ * w;
    00198
    00199         parser_->setContentHandler(&root_);
    00200         delete weighth_;
    00201       }
    00202       else
    00203         error::token(localname);
    00204     }
    00205
    00206     SParamTRANS
    00207     RegexpHandler<typename WeightHandler<TRANSseries >::series_set_elt_t>*
    00208     WeightHandler<TRANSseries >::create_weighth (const XMLCh* const localname)
    00209     {
    00210       using namespace xercesc;
    00211       series_set_elt_t elt(param_.structure().semiring());
    00212
    00213       if (XMLString::equals(eq_.monElmt, localname))
    00214         return builders::create_monElmth(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()));
    00215       else if (XMLString::equals(eq_.star, localname))
    00216         return new StarHandler<series_set_elt_t>(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()));
    00217       else if (XMLString::equals(eq_.leftExtMul, localname))
    00218         return new ExtMulHandler<series_set_elt_t>(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()), true);
    00219       else if (XMLString::equals(eq_.rightExtMul, localname))
    00220         return new ExtMulHandler<series_set_elt_t>(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()), false);
    00221       else if (XMLString::equals(eq_.sum, localname))
    00222         return new SumHandler<series_set_elt_t>(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()));
    00223       else if (XMLString::equals(eq_.product, localname))
    00224         return new ProductHandler<series_set_elt_t>(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()));
    00225       else if (XMLString::equals(eq_.one, localname))
    00226         return new AtomHandler<series_set_elt_t>(parser_, *this, algebra::identity_as<typename series_set_elt_t::value_t>::of(elt.structure()), eq_.one);
    00227       else if (XMLString::equals(eq_.zero, localname))
    00228         return new AtomHandler<series_set_elt_t>(parser_, *this, algebra::zero_as<typename series_set_elt_t::value_t>::of(elt.structure()), eq_.zero);
    00229       else
    00230         return 0;
    00231     }
    00232
    00233     namespace builders
    00234     {
    00235       SParamTRANS
    00236       RegexpHandler<TRANSseries >*
    00237       create_weighth(xercesc::SAX2XMLReader* parser,
    00238                      RegexpHandler<TRANSseries >& root,
    00239                      TRANSseries param,
    00240                      const xercesc::Attributes&)
    00241       {
    00242         return new WeightHandler<TRANSseries >(parser, root, param);
    00243       }
    00244     } // !builders
    00245   } // !xml
    00246 } // !vcsn
    00247
    00248 #endif // !VCSN_XML_CONTEXTS_RW_HXX