Vaucanson 1.4
handlers.hh
00001 // handlers.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_HANDLERS_HH
00019 # define VCSN_XML_HANDLERS_HH
00020 
00031 # include <map>
00032 # include <string>
00033 
00034 # include <xercesc/sax2/SAX2XMLReader.hpp>
00035 # include <xercesc/sax2/XMLReaderFactory.hpp>
00036 # include <xercesc/sax2/DefaultHandler.hpp>
00037 # include <xercesc/sax2/Attributes.hpp>
00038 
00039 # include <xercesc/sax/SAXException.hpp>
00040 # include <xercesc/util/XMLString.hpp>
00041 
00042 # include <vaucanson/xml/xmleq.hh>
00043 # include <vaucanson/xml/strings.hh>
00044 # include <vaucanson/xml/handlers_base.hh>
00045 # include <vaucanson/xml/builders.hh>
00046 # include <vaucanson/xml/regexp.hh>
00047 
00048 # include <vaucanson/algebra/implementation/series/series_rep.hh>
00049 
00050 namespace vcsn
00051 {
00052   namespace xml
00053   {
00057     template <typename T>
00058     class GeometryHandler : public Handler
00059     {
00060       public:
00061         typedef typename T::hstate_t            hstate_t;
00062 
00063         GeometryHandler (xercesc::SAX2XMLReader* parser,
00064                      Handler& root,
00065                      T& aut,
00066                      hstate_t state);
00067 
00068         void
00069         start (const XMLCh* const uri,
00070                       const XMLCh* const localname,
00071                       const XMLCh* const qname,
00072                       const xercesc::Attributes& attrs);
00073         void
00074         end (const XMLCh* const uri,
00075                     const XMLCh* const localname,
00076                     const XMLCh* const qname);
00077       private:
00078         T&              aut_;
00079         hstate_t        state_;
00080     };
00084     template <typename T>
00085     class StateHandler : public Handler
00086     {
00087       public:
00088         typedef typename T::hstate_t            hstate_t;
00089 
00090         StateHandler (xercesc::SAX2XMLReader* parser,
00091                      Handler& root,
00092                      T& aut,
00093                      hstate_t state);
00094 
00095         void
00096         start (const XMLCh* const uri,
00097                       const XMLCh* const localname,
00098                       const XMLCh* const qname,
00099                       const xercesc::Attributes& attrs);
00100         void
00101         end (const XMLCh* const uri,
00102                     const XMLCh* const localname,
00103                     const XMLCh* const qname);
00104       private:
00105         T&              aut_;
00106         hstate_t        state_;
00107 
00108         GeometryHandler<T>      geometryh_;
00109         UnsupHandler            unsuph_;
00110     };
00111 
00115     template <typename T>
00116     class StatesHandler : public Handler
00117     {
00118       public:
00119         typedef typename T::hstate_t            hstate_t;
00120         typedef std::map<std::string, hstate_t> map_t;
00121 
00122         StatesHandler (xercesc::SAX2XMLReader* parser,
00123                      Handler& root,
00124                      T& aut,
00125                      map_t& map);
00126 
00127         void
00128         start (const XMLCh* const uri,
00129                       const XMLCh* const localname,
00130                       const XMLCh* const qname,
00131                       const xercesc::Attributes& attrs);
00132         void
00133         end (const XMLCh* const uri,
00134                     const XMLCh* const localname,
00135                     const XMLCh* const qname);
00136       private:
00137         T&      aut_;
00138         map_t&  map_;
00139 
00140         StateHandler<T>*        stateh_;
00141     };
00142 
00146     template <typename T>
00147     class TransitionHandler : public Handler
00148     {
00149       public:
00150         typedef typename T::hstate_t    hstate_t;
00151         TransitionHandler (xercesc::SAX2XMLReader* parser,
00152                      Handler& root,
00153                      T& aut,
00154                      hstate_t src,
00155                      hstate_t dst);
00156 
00157         void
00158         start (const XMLCh* const uri,
00159                       const XMLCh* const localname,
00160                       const XMLCh* const qname,
00161                       const xercesc::Attributes& attrs);
00162         void
00163         end (const XMLCh* const uri,
00164                     const XMLCh* const localname,
00165                     const XMLCh* const qname);
00166 
00167       private:
00168         typedef typename T::series_set_elt_t    series_set_elt_t;
00169         T&                      aut_;
00170         hstate_t                src_;
00171         hstate_t                dst_;
00172 
00173         series_set_elt_t                s_;
00174 
00175         RegexpHandler<series_set_elt_t> labelh_;
00176         UnsupHandler            unsuph_;
00177     };
00178 
00182     template <typename T>
00183     class InitFinalHandler : public Handler
00184     {
00185       public:
00186         typedef typename T::hstate_t    hstate_t;
00187         InitFinalHandler (xercesc::SAX2XMLReader* parser,
00188                      Handler& root,
00189                      T& aut,
00190                      hstate_t state,
00191                      bool initial = true);
00192 
00193         void
00194         start (const XMLCh* const uri,
00195                       const XMLCh* const localname,
00196                       const XMLCh* const qname,
00197                       const xercesc::Attributes& attrs);
00198         void
00199         end (const XMLCh* const uri,
00200                     const XMLCh* const localname,
00201                     const XMLCh* const qname);
00202 
00203       private:
00204         typedef typename T::series_set_elt_t    series_set_elt_t;
00205         T&                      aut_;
00206         hstate_t                state_;
00207 
00208         bool                    initial_;
00209         series_set_elt_t        s_;
00210 
00211         RegexpHandler<series_set_elt_t> labelh_;
00212         UnsupHandler            unsuph_;
00213     };
00214 
00218     template <typename T>
00219     class TransitionsHandler : public Handler
00220     {
00221       public:
00222         typedef typename T::hstate_t                hstate_t;
00223         typedef std::map<std::string, hstate_t>     map_t;
00224 
00225         TransitionsHandler (xercesc::SAX2XMLReader* parser,
00226                      Handler& root,
00227                      T& aut,
00228                      map_t& map);
00229 
00230         void
00231         start (const XMLCh* const uri,
00232                       const XMLCh* const localname,
00233                       const XMLCh* const qname,
00234                       const xercesc::Attributes& attrs);
00235         void
00236         end (const XMLCh* const uri,
00237                     const XMLCh* const localname,
00238                     const XMLCh* const qname);
00239       private:
00240         T&                      aut_;
00241         map_t&                  map_;
00242 
00243         Handler*        transitionh_;
00244     };
00245 
00249     template <typename T>
00250     class ContHandler : public Handler
00251     {
00252       public:
00253         ContHandler (xercesc::SAX2XMLReader* parser,
00254                      Handler& root,
00255                      T& aut);
00256 
00257         void
00258         start (const XMLCh* const uri,
00259                       const XMLCh* const localname,
00260                       const XMLCh* const qname,
00261                       const xercesc::Attributes& attrs);
00262         void
00263         end (const XMLCh* const uri,
00264                     const XMLCh* const localname,
00265                     const XMLCh* const qname);
00266       private:
00267         typedef typename T::hstate_t                hstate_t;
00268         typedef std::map<std::string, hstate_t>     map_t;
00269 
00270         T&      aut_;
00271         map_t   map_;
00272 
00273 
00274         StatesHandler<T>        statesh_;
00275         TransitionsHandler<T>   transitionsh_;
00276     };
00277 
00281     template <typename T>
00282     class TypeHandler : public Handler
00283     {
00284       public:
00285         TypeHandler (xercesc::SAX2XMLReader* parser,
00286                      Handler& root,
00287                      T& param);
00288 
00289         void
00290         start (const XMLCh* const uri,
00291                       const XMLCh* const localname,
00292                       const XMLCh* const qname,
00293                       const xercesc::Attributes& attrs);
00294         void
00295         end (const XMLCh* const uri,
00296                     const XMLCh* const localname,
00297                     const XMLCh* const qname);
00298       private:
00299         // Type helpers.
00300         typedef typename T::monoid_t                    monoid_t;
00301         typedef typename T::semiring_t                  semiring_t;
00302         typedef typename T::series_set_t                series_set_t;
00303         typedef typename T::series_set_t::series_rep_t  series_rep_t;
00304 
00305         monoid_t*       monoid_;
00306         semiring_t*     semiring_;
00307         series_rep_t*   rep_;
00308 
00309         // FIXME: maybe we should rename this attribute to aut_,
00310         // as with all the other handlers.
00311         T&              param_;
00312         Handler*        monoidh_;
00313         Handler*        reph_;
00314         Handler*        semiringh_;
00315         UnsupHandler    unsuph_;
00316     };
00317 
00321     template <typename T>
00322     class AutHandler : public Handler
00323     {
00324       public:
00325         AutHandler (xercesc::SAX2XMLReader* parser,
00326                     Handler& root,
00327                     T& aut);
00328 
00329         void
00330         start (const XMLCh* const uri,
00331                       const XMLCh* const localname,
00332                       const XMLCh* const qname,
00333                       const xercesc::Attributes& attrs);
00334         void
00335         end (const XMLCh* const uri,
00336                     const XMLCh* const localname,
00337                     const XMLCh* const qname);
00338       private:
00339         T&                      aut_;
00340 
00341         TypeHandler<T>  typeh_;
00342         ContHandler<T>  contenth_;
00343         UnsupHandler    unsuph_;
00344     };
00345 
00349     template <typename RE>
00350     class RegExpHandler : public Handler
00351     {
00352       public:
00353         RegExpHandler (xercesc::SAX2XMLReader* parser,
00354                        Handler& root,
00355                        RE& regexp);
00356 
00357         void
00358         start (const XMLCh* const uri,
00359                       const XMLCh* const localname,
00360                       const XMLCh* const qname,
00361                       const xercesc::Attributes& attrs);
00362         void
00363         end (const XMLCh* const uri,
00364                     const XMLCh* const localname,
00365                     const XMLCh* const qname);
00366       private:
00367         RE&                     regexp_;
00368 
00369         TypeHandler<RE> typeh_;
00370         RegexpHandler<RE>       contenth_;
00371         UnsupHandler    unsuph_;
00372     };
00373 
00379     template <typename RE>
00380     class DocRegExpHandler : public Handler
00381     {
00382       public:
00383         DocRegExpHandler (xercesc::SAX2XMLReader* parser,
00384                           xercesc::DefaultHandler& root,
00385                           RE& regexp,
00386                           XMLEq& eq);
00387         void
00388         start (const XMLCh* const uri,
00389                       const XMLCh* const localname,
00390                       const XMLCh* const qname,
00391                       const xercesc::Attributes& attrs);
00392         void
00393         end (const XMLCh* const uri,
00394                     const XMLCh* const localname,
00395                     const XMLCh* const qname);
00396       private:
00397         RE& regexp_;
00398 
00399         RegExpHandler<RE>       regexph_;
00400     };
00401 
00407     template <typename T>
00408     class DocAutHandler : public Handler
00409     {
00410       public:
00411         DocAutHandler (xercesc::SAX2XMLReader* parser,
00412                        xercesc::DefaultHandler& root,
00413                        T& aut,
00414                        XMLEq& eq);
00415         void
00416         start (const XMLCh* const uri,
00417                       const XMLCh* const localname,
00418                       const XMLCh* const qname,
00419                       const xercesc::Attributes& attrs);
00420         void
00421         end (const XMLCh* const uri,
00422                     const XMLCh* const localname,
00423                     const XMLCh* const qname);
00424       private:
00425         T& aut_;
00426 
00427         AutHandler<T>   auth_;
00428     };
00429 
00430   } // !xml
00431 } // !vcsn
00432 
00433 # if ! defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00434 #  include <vaucanson/xml/handlers.hxx>
00435 # endif // !VCSN_USE_INTERFACE_ONLY || VCSN_USE_LIB
00436 
00437 #endif // !VCSN_XML_HANDLERS_HH