Vaucanson  1.4.1
xml/handlers.hh
1 // handlers.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2007, 2008 The Vaucanson Group.
6 //
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License
9 // as published by the Free Software Foundation; either version 2
10 // of the License, or (at your option) any later version.
11 //
12 // The complete GNU General Public Licence Notice can be found as the
13 // `COPYING' file in the root directory.
14 //
15 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
16 //
17 
18 #ifndef VCSN_XML_HANDLERS_HH
19 # define VCSN_XML_HANDLERS_HH
20 
31 # include <map>
32 # include <string>
33 
34 # include <xercesc/sax2/SAX2XMLReader.hpp>
35 # include <xercesc/sax2/XMLReaderFactory.hpp>
36 # include <xercesc/sax2/DefaultHandler.hpp>
37 # include <xercesc/sax2/Attributes.hpp>
38 
39 # include <xercesc/sax/SAXException.hpp>
40 # include <xercesc/util/XMLString.hpp>
41 
42 # include <vaucanson/xml/xmleq.hh>
43 # include <vaucanson/xml/strings.hh>
44 # include <vaucanson/xml/handlers_base.hh>
45 # include <vaucanson/xml/builders.hh>
46 # include <vaucanson/xml/regexp.hh>
47 
48 # include <vaucanson/algebra/implementation/series/series_rep.hh>
49 
50 namespace vcsn
51 {
52  namespace xml
53  {
57  template <typename T>
58  class GeometryHandler : public Handler
59  {
60  public:
61  typedef typename T::hstate_t hstate_t;
62 
63  GeometryHandler (xercesc::SAX2XMLReader* parser,
64  Handler& root,
65  T& aut,
66  hstate_t state);
67 
68  void
69  start (const XMLCh* const uri,
70  const XMLCh* const localname,
71  const XMLCh* const qname,
72  const xercesc::Attributes& attrs);
73  void
74  end (const XMLCh* const uri,
75  const XMLCh* const localname,
76  const XMLCh* const qname);
77  private:
78  T& aut_;
79  hstate_t state_;
80  };
84  template <typename T>
85  class StateHandler : public Handler
86  {
87  public:
88  typedef typename T::hstate_t hstate_t;
89 
90  StateHandler (xercesc::SAX2XMLReader* parser,
91  Handler& root,
92  T& aut,
93  hstate_t state);
94 
95  void
96  start (const XMLCh* const uri,
97  const XMLCh* const localname,
98  const XMLCh* const qname,
99  const xercesc::Attributes& attrs);
100  void
101  end (const XMLCh* const uri,
102  const XMLCh* const localname,
103  const XMLCh* const qname);
104  private:
105  T& aut_;
106  hstate_t state_;
107 
108  GeometryHandler<T> geometryh_;
109  UnsupHandler unsuph_;
110  };
111 
115  template <typename T>
116  class StatesHandler : public Handler
117  {
118  public:
119  typedef typename T::hstate_t hstate_t;
120  typedef std::map<std::string, hstate_t> map_t;
121 
122  StatesHandler (xercesc::SAX2XMLReader* parser,
123  Handler& root,
124  T& aut,
125  map_t& map);
126 
127  void
128  start (const XMLCh* const uri,
129  const XMLCh* const localname,
130  const XMLCh* const qname,
131  const xercesc::Attributes& attrs);
132  void
133  end (const XMLCh* const uri,
134  const XMLCh* const localname,
135  const XMLCh* const qname);
136  private:
137  T& aut_;
138  map_t& map_;
139 
140  StateHandler<T>* stateh_;
141  };
142 
146  template <typename T>
147  class TransitionHandler : public Handler
148  {
149  public:
150  typedef typename T::hstate_t hstate_t;
151  TransitionHandler (xercesc::SAX2XMLReader* parser,
152  Handler& root,
153  T& aut,
154  hstate_t src,
155  hstate_t dst);
156 
157  void
158  start (const XMLCh* const uri,
159  const XMLCh* const localname,
160  const XMLCh* const qname,
161  const xercesc::Attributes& attrs);
162  void
163  end (const XMLCh* const uri,
164  const XMLCh* const localname,
165  const XMLCh* const qname);
166 
167  private:
168  typedef typename T::series_set_elt_t series_set_elt_t;
169  T& aut_;
170  hstate_t src_;
171  hstate_t dst_;
172 
173  series_set_elt_t s_;
174 
176  UnsupHandler unsuph_;
177  };
178 
182  template <typename T>
183  class InitFinalHandler : public Handler
184  {
185  public:
186  typedef typename T::hstate_t hstate_t;
187  InitFinalHandler (xercesc::SAX2XMLReader* parser,
188  Handler& root,
189  T& aut,
190  hstate_t state,
191  bool initial = true);
192 
193  void
194  start (const XMLCh* const uri,
195  const XMLCh* const localname,
196  const XMLCh* const qname,
197  const xercesc::Attributes& attrs);
198  void
199  end (const XMLCh* const uri,
200  const XMLCh* const localname,
201  const XMLCh* const qname);
202 
203  private:
204  typedef typename T::series_set_elt_t series_set_elt_t;
205  T& aut_;
206  hstate_t state_;
207 
208  bool initial_;
209  series_set_elt_t s_;
210 
212  UnsupHandler unsuph_;
213  };
214 
218  template <typename T>
219  class TransitionsHandler : public Handler
220  {
221  public:
222  typedef typename T::hstate_t hstate_t;
223  typedef std::map<std::string, hstate_t> map_t;
224 
225  TransitionsHandler (xercesc::SAX2XMLReader* parser,
226  Handler& root,
227  T& aut,
228  map_t& map);
229 
230  void
231  start (const XMLCh* const uri,
232  const XMLCh* const localname,
233  const XMLCh* const qname,
234  const xercesc::Attributes& attrs);
235  void
236  end (const XMLCh* const uri,
237  const XMLCh* const localname,
238  const XMLCh* const qname);
239  private:
240  T& aut_;
241  map_t& map_;
242 
243  Handler* transitionh_;
244  };
245 
249  template <typename T>
250  class ContHandler : public Handler
251  {
252  public:
253  ContHandler (xercesc::SAX2XMLReader* parser,
254  Handler& root,
255  T& aut);
256 
257  void
258  start (const XMLCh* const uri,
259  const XMLCh* const localname,
260  const XMLCh* const qname,
261  const xercesc::Attributes& attrs);
262  void
263  end (const XMLCh* const uri,
264  const XMLCh* const localname,
265  const XMLCh* const qname);
266  private:
267  typedef typename T::hstate_t hstate_t;
268  typedef std::map<std::string, hstate_t> map_t;
269 
270  T& aut_;
271  map_t map_;
272 
273 
274  StatesHandler<T> statesh_;
275  TransitionsHandler<T> transitionsh_;
276  };
277 
281  template <typename T>
282  class TypeHandler : public Handler
283  {
284  public:
285  TypeHandler (xercesc::SAX2XMLReader* parser,
286  Handler& root,
287  T& param);
288 
289  void
290  start (const XMLCh* const uri,
291  const XMLCh* const localname,
292  const XMLCh* const qname,
293  const xercesc::Attributes& attrs);
294  void
295  end (const XMLCh* const uri,
296  const XMLCh* const localname,
297  const XMLCh* const qname);
298  private:
299  // Type helpers.
300  typedef typename T::monoid_t monoid_t;
301  typedef typename T::semiring_t semiring_t;
302  typedef typename T::series_set_t series_set_t;
303  typedef typename T::series_set_t::series_rep_t series_rep_t;
304 
305  monoid_t* monoid_;
306  semiring_t* semiring_;
307  series_rep_t* rep_;
308 
309  // FIXME: maybe we should rename this attribute to aut_,
310  // as with all the other handlers.
311  T& param_;
312  Handler* monoidh_;
313  Handler* reph_;
314  Handler* semiringh_;
315  UnsupHandler unsuph_;
316  };
317 
321  template <typename T>
322  class AutHandler : public Handler
323  {
324  public:
325  AutHandler (xercesc::SAX2XMLReader* parser,
326  Handler& root,
327  T& aut);
328 
329  void
330  start (const XMLCh* const uri,
331  const XMLCh* const localname,
332  const XMLCh* const qname,
333  const xercesc::Attributes& attrs);
334  void
335  end (const XMLCh* const uri,
336  const XMLCh* const localname,
337  const XMLCh* const qname);
338  private:
339  T& aut_;
340 
341  TypeHandler<T> typeh_;
342  ContHandler<T> contenth_;
343  UnsupHandler unsuph_;
344  };
345 
349  template <typename RE>
350  class RegExpHandler : public Handler
351  {
352  public:
353  RegExpHandler (xercesc::SAX2XMLReader* parser,
354  Handler& root,
355  RE& regexp);
356 
357  void
358  start (const XMLCh* const uri,
359  const XMLCh* const localname,
360  const XMLCh* const qname,
361  const xercesc::Attributes& attrs);
362  void
363  end (const XMLCh* const uri,
364  const XMLCh* const localname,
365  const XMLCh* const qname);
366  private:
367  RE& regexp_;
368 
369  TypeHandler<RE> typeh_;
370  RegexpHandler<RE> contenth_;
371  UnsupHandler unsuph_;
372  };
373 
379  template <typename RE>
380  class DocRegExpHandler : public Handler
381  {
382  public:
383  DocRegExpHandler (xercesc::SAX2XMLReader* parser,
384  xercesc::DefaultHandler& root,
385  RE& regexp,
386  XMLEq& eq);
387  void
388  start (const XMLCh* const uri,
389  const XMLCh* const localname,
390  const XMLCh* const qname,
391  const xercesc::Attributes& attrs);
392  void
393  end (const XMLCh* const uri,
394  const XMLCh* const localname,
395  const XMLCh* const qname);
396  private:
397  RE& regexp_;
398 
399  RegExpHandler<RE> regexph_;
400  };
401 
407  template <typename T>
408  class DocAutHandler : public Handler
409  {
410  public:
411  DocAutHandler (xercesc::SAX2XMLReader* parser,
412  xercesc::DefaultHandler& root,
413  T& aut,
414  XMLEq& eq);
415  void
416  start (const XMLCh* const uri,
417  const XMLCh* const localname,
418  const XMLCh* const qname,
419  const xercesc::Attributes& attrs);
420  void
421  end (const XMLCh* const uri,
422  const XMLCh* const localname,
423  const XMLCh* const qname);
424  private:
425  T& aut_;
426 
427  AutHandler<T> auth_;
428  };
429 
430  } // !xml
431 } // !vcsn
432 
433 # if ! defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
434 # include <vaucanson/xml/handlers.hxx>
435 # endif // !VCSN_USE_INTERFACE_ONLY || VCSN_USE_LIB
436 
437 #endif // !VCSN_XML_HANDLERS_HH