builders.hh

Go to the documentation of this file.
00001 // builders.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2007, 2008 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_BUILDERS_HH
00019 # define VCSN_XML_BUILDERS_HH
00020 
00031 # include <string>
00032 
00033 // These includes are here to satisfy sanity checks, but we need a way
00034 // to force the inclusion of the XML related headers after the automaton
00035 // type is fully constructed (no undefined_type), and improve sanity
00036 // checks.
00037 # include <vaucanson/algebra/implementation/free_monoid/words.hh>
00038 # include <vaucanson/algebra/implementation/series/series.hh>
00039 
00040 # include <xercesc/sax2/Attributes.hpp>
00041 # include <xercesc/util/XMLString.hpp>
00042 # include <xercesc/dom/DOM.hpp>
00043 
00044 # include <vaucanson/xml/handlers_base.hh>
00045 
00046 namespace vcsn
00047 {
00048   namespace xml
00049   {
00053     template <typename T>
00054     class monGenAction
00055     {
00056     public:
00057       monGenAction(const T&);
00058     };
00059 
00060     // An action on a free monoid (insert monGen inside its alphabet)
00061     template <typename T>
00062     class monGenAction<vcsn::algebra::FreeMonoid<T> >
00063     {
00064     public:
00065       typedef vcsn::algebra::FreeMonoid<T> self_t;
00066       typedef typename self_t::alphabet_t alphabet_t;
00067 
00068       monGenAction(self_t&);
00069       void operator () (const std::string&);
00070     private:
00071       alphabet_t& alphabet_;
00072     };
00073 
00074     // An action on a series element (multiply it by monGen)
00075     template <typename T, typename U, typename V>
00076     class monGenAction<vcsn::Element<vcsn::algebra::Series<T, U>, V> >
00077     {
00078     public:
00079       typedef vcsn::Element<vcsn::algebra::Series<T, U>, V> self_t;
00080 
00081       monGenAction(self_t&);
00082       void operator () (const std::string&);
00083     private:
00084       self_t& s_;
00085     };
00086 
00093     template <typename T, typename U>
00094     class monGenHandler : public Handler
00095     {
00096       public:
00097         monGenHandler (xercesc::SAX2XMLReader* parser,
00098                      Handler& root,
00099                      const monGenAction<U>& action,
00100                      const XMLCh* value = 0);
00101 
00102         void
00103         start (const XMLCh* const uri,
00104                       const XMLCh* const localname,
00105                       const XMLCh* const qname,
00106                       const xercesc::Attributes& attrs);
00107         void
00108         end (const XMLCh* const uri,
00109                     const XMLCh* const localname,
00110                     const XMLCh* const qname);
00111       private:
00112         const XMLCh*    value_;
00113 
00114         // What to do with value_.
00115         monGenAction<U> action_;
00116     };
00117 
00124     template <typename T, typename U>
00125     class monGenTupleHandler : public Handler
00126     {
00127       public:
00128         monGenTupleHandler (xercesc::SAX2XMLReader* parser,
00129                      Handler& root,
00130                      const monGenAction<U>& action);
00131 
00132         void
00133         start (const XMLCh* const uri,
00134                       const XMLCh* const localname,
00135                       const XMLCh* const qname,
00136                       const xercesc::Attributes& attrs);
00137         void
00138         end (const XMLCh* const uri,
00139                     const XMLCh* const localname,
00140                     const XMLCh* const qname);
00141       private:
00142         std::string     value_;
00143         bool            wait_begin_;
00144         int             count_;
00145 
00146         // What to do with value_.
00147         monGenAction<U> action_;
00148     };
00149 
00153     template <typename T>
00154     class FreeMonoidHandler : public Handler
00155     {
00156       public:
00157         FreeMonoidHandler (xercesc::SAX2XMLReader* parser,
00158                      Handler& root,
00159                      T& monoid);
00160 
00161         void
00162         start (const XMLCh* const uri,
00163                       const XMLCh* const localname,
00164                       const XMLCh* const qname,
00165                       const xercesc::Attributes& attrs);
00166         void
00167         end (const XMLCh* const uri,
00168                     const XMLCh* const localname,
00169                     const XMLCh* const qname);
00170       private:
00171         T&              monoid_;
00172 
00173         Handler*        mongenh_;
00174         UnsupHandler    unsuph_;
00175     };
00176 
00177     namespace builders
00178     {
00179       template <typename T>
00180       typename T::monoid_t*
00181       create_monoid (T&,
00182                      const XMLCh* const localname,
00183                      const xercesc::Attributes& attrs);
00184 
00185       template <typename T>
00186       Handler*
00187       create_monoidh (T& monoid,
00188                       const xercesc::Attributes& attrs,
00189                       xercesc::SAX2XMLReader* parser,
00190                       Handler& root);
00191 
00192     } // !builders
00193 
00197     template <typename T>
00198     class NumSemiringHandler : public Handler
00199     {
00200       public:
00201         NumSemiringHandler (xercesc::SAX2XMLReader* parser,
00202                      Handler& root,
00203                      T& semiring);
00204 
00205         void
00206         start (const XMLCh* const uri,
00207                       const XMLCh* const localname,
00208                       const XMLCh* const qname,
00209                       const xercesc::Attributes& attrs);
00210         void
00211         end (const XMLCh* const uri,
00212                     const XMLCh* const localname,
00213                     const XMLCh* const qname);
00214       private:
00215         T&              semiring_;
00216 
00217         UnsupHandler    unsuph_;
00218     };
00219 
00220     namespace builders
00221     {
00222       template <typename T>
00223       typename T::semiring_t*
00224       create_semiring (T&,
00225                        const XMLCh* const localname,
00226                        const xercesc::Attributes& attrs);
00227 
00228       template <typename T>
00229       Handler*
00230       create_semiringh (T& semiring,
00231                         const xercesc::Attributes& attrs,
00232                         xercesc::SAX2XMLReader* parser,
00233                         Handler& root);
00234 
00235     } // !builders
00236 
00240     template <typename T>
00241     class RegexpHandler;
00242 
00243     namespace builders
00244     {
00245 
00246       template <typename S, typename T>
00247       RegexpHandler<S>*
00248       create_monElmth(xercesc::SAX2XMLReader* parser,
00249                       RegexpHandler<T>& root,
00250                       S param);
00251 
00252       template <typename T>
00253       RegexpHandler<T>*
00254       create_weight(xercesc::SAX2XMLReader* parser,
00255                     RegexpHandler<T>& root,
00256                     T param,
00257                     const xercesc::Attributes& attrs);
00258     } // !builders
00259 
00263     namespace builders
00264     {
00265       template <typename T>
00266       void
00267       check_monoid_consistency (T& param,
00268                                 const XMLCh* const localname,
00269                                 const xercesc::Attributes& attrs);
00270 
00271       template <typename T>
00272       void
00273       check_semiring_consistency (T& param,
00274                                   const XMLCh* const localname,
00275                                   const xercesc::Attributes& attrs);
00276     } // !builders
00277 
00281     namespace builders
00282     {
00283       template <typename T>
00284       void
00285       create_semiring_node(const T& semiring,
00286                            xercesc::DOMDocument* doc,
00287                            xercesc::DOMElement* root);
00288 
00289       template <typename T>
00290       void
00291       create_monoid_node(const T& monoid,
00292                          xercesc::DOMDocument* doc,
00293                          xercesc::DOMElement* root);
00294 
00295       template <typename T>
00296       void
00297       create_regexp_node(const T&,
00298                          xercesc::DOMDocument* doc,
00299                          xercesc::DOMElement* root);
00300 
00301       template <typename T>
00302       void
00303       create_monElmt_node(const T&,
00304                           xercesc::DOMDocument* doc,
00305                           xercesc::DOMElement* root);
00306 
00307       // Functor to allow partial specialization.
00308       template <typename T>
00309       struct
00310       create_monGen_node;
00311 
00312     } // ! builders
00313 
00314   } // ! xml
00315 
00316 } // ! vcsn
00317 
00318 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00319 #  include <vaucanson/xml/builders.hxx>
00320 # endif // VCSN_USE_INTERFACE_ONLY || !VCSN_USE_LIB
00321 
00322 #endif // !VCSN_XML_BUILDERS_HH

Generated on Thu Oct 9 20:22:34 2008 for Vaucanson by  doxygen 1.5.1