Vaucanson  1.4.1
builders.hh
Go to the documentation of this file.
1 // builders.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, 2009 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_BUILDERS_HH
19 # define VCSN_XML_BUILDERS_HH
20 
31 # include <string>
32 
33 // These includes are here to satisfy sanity checks, but we need a way
34 // to force the inclusion of the XML related headers after the automaton
35 // type is fully constructed (no undefined_type), and improve sanity
36 // checks.
37 # include <vaucanson/algebra/implementation/monoid/free_monoid.hh>
38 # include <vaucanson/algebra/implementation/series/series.hh>
39 
40 # include <xercesc/sax2/Attributes.hpp>
41 # include <xercesc/util/XMLString.hpp>
42 # include <xercesc/dom/DOM.hpp>
43 
44 # include <vaucanson/xml/handlers_base.hh>
45 
46 namespace vcsn
47 {
48  namespace xml
49  {
53  template <typename T>
55  {
56  public:
57  monGenAction(const T&);
58  };
59 
60  // An action on a free monoid (insert monGen inside its alphabet)
61  template <typename T>
62  class monGenAction<vcsn::algebra::FreeMonoid<T> >
63  {
64  public:
65  typedef vcsn::algebra::FreeMonoid<T> monoid_t;
66  typedef typename monoid_t::alphabet_t alphabet_t;
67 
68  monGenAction(monoid_t&);
69  void operator () (const std::string&);
70  private:
71  alphabet_t& alphabet_;
72  };
73 
74  // An action on a series element (multiply it by monGen)
75  template <typename T, typename U, typename V>
76  class monGenAction<vcsn::Element<vcsn::algebra::Series<T, U>, V> >
77  {
78  public:
79  typedef vcsn::Element<vcsn::algebra::Series<T, U>, V> series_t;
80  typedef typename series_t::set_t::monoid_t monoid_t;
81  typedef typename monoid_t::alphabet_t alphabet_t;
82  typedef typename alphabet_t::letter_t letter_t;
83 
84  monGenAction(series_t&);
85  void operator () (const std::string&);
86  private:
87  series_t& s_;
88  };
89 
96  template <typename T, typename U>
97  class monGenHandler : public Handler
98  {
99  public:
100  monGenHandler (xercesc::SAX2XMLReader* parser,
101  Handler& root,
102  const monGenAction<U>& action,
103  const XMLCh* value = 0);
104 
105  void
106  start (const XMLCh* const uri,
107  const XMLCh* const localname,
108  const XMLCh* const qname,
109  const xercesc::Attributes& attrs);
110  void
111  end (const XMLCh* const uri,
112  const XMLCh* const localname,
113  const XMLCh* const qname);
114  private:
115  const XMLCh* value_;
116 
117  // What to do with value_.
118  monGenAction<U> action_;
119  };
120 
127  template <typename T, typename U>
128  class monGenTupleHandler : public Handler
129  {
130  public:
131  monGenTupleHandler (xercesc::SAX2XMLReader* parser,
132  Handler& root,
133  const monGenAction<U>& action);
134 
135  void
136  start (const XMLCh* const uri,
137  const XMLCh* const localname,
138  const XMLCh* const qname,
139  const xercesc::Attributes& attrs);
140  void
141  end (const XMLCh* const uri,
142  const XMLCh* const localname,
143  const XMLCh* const qname);
144  private:
145  std::string value_;
146  bool wait_begin_;
147  int count_;
148 
149  // What to do with value_.
150  monGenAction<U> action_;
151  };
152 
156  template <typename T>
157  class FreeMonoidHandler : public Handler
158  {
159  public:
160  FreeMonoidHandler (xercesc::SAX2XMLReader* parser,
161  Handler& root,
162  T& monoid);
163 
164  void
165  start (const XMLCh* const uri,
166  const XMLCh* const localname,
167  const XMLCh* const qname,
168  const xercesc::Attributes& attrs);
169  void
170  end (const XMLCh* const uri,
171  const XMLCh* const localname,
172  const XMLCh* const qname);
173  private:
174  T& monoid_;
175  bool user_rep_;
176 
177  Handler* mongenh_;
178  UnsupHandler unsuph_;
179  };
180 
184  template <typename T>
185  class SeriesRepresentationHandler : public Handler
186  {
187  public:
188  SeriesRepresentationHandler(xercesc::SAX2XMLReader* parser,
189  Handler& root,
190  T& srep);
191 
192  void start(const XMLCh* const uri,
193  const XMLCh* const localname,
194  const XMLCh* const qname,
195  const xercesc::Attributes& attrs);
196 
197  void end(const XMLCh* const uri,
198  const XMLCh* const localname,
199  const XMLCh* const qname);
200 
201  private:
202  T& rep_;
203 
204  UnsupHandler unsuph_;
205  };
206 
207  namespace builders
208  {
209  template <typename T>
210  typename T::monoid_t*
211  create_monoid (T&,
212  const XMLCh* const localname,
213  const xercesc::Attributes& attrs,
214  XMLEq&);
215 
216  template <typename T>
217  Handler*
218  create_monoidh (T& monoid,
219  const xercesc::Attributes& attrs,
220  xercesc::SAX2XMLReader* parser,
221  Handler& root);
222 
223  template <typename T>
224  typename T::series_set_t::series_rep_t*
225  create_series_representation(T&,
226  const XMLCh* const localname,
227  const xercesc::Attributes& attrs,
228  XMLEq&);
229 
230  template <typename T>
231  Handler*
232  create_series_representationh(T& srep,
233  const xercesc::Attributes& attrs,
234  xercesc::SAX2XMLReader* parser,
235  Handler& root,
236  XMLEq&);
237 
238  } // ! builders
239 
243  template <typename T>
244  class NumSemiringHandler : public Handler
245  {
246  public:
247  NumSemiringHandler (xercesc::SAX2XMLReader* parser,
248  Handler& root,
249  T& semiring);
250 
251  void
252  start (const XMLCh* const uri,
253  const XMLCh* const localname,
254  const XMLCh* const qname,
255  const xercesc::Attributes& attrs);
256  void
257  end (const XMLCh* const uri,
258  const XMLCh* const localname,
259  const XMLCh* const qname);
260  private:
261  T& semiring_;
262 
263  UnsupHandler unsuph_;
264  };
265 
266  namespace builders
267  {
268  template <typename T>
269  typename T::semiring_t*
270  create_semiring (T&,
271  const XMLCh* const localname,
272  const xercesc::Attributes& attrs);
273 
274  template <typename T>
275  Handler*
276  create_semiringh (T& semiring,
277  const xercesc::Attributes& attrs,
278  xercesc::SAX2XMLReader* parser,
279  Handler& root);
280 
281  } // !builders
282 
286  template <typename T>
287  class RegexpHandler;
288 
289  namespace builders
290  {
291 
292  template <typename S, typename T>
293  RegexpHandler<S>*
294  create_monElmth(xercesc::SAX2XMLReader* parser,
295  RegexpHandler<T>& root,
296  S param);
297 
298  template <typename T>
299  RegexpHandler<T>*
300  create_weight(xercesc::SAX2XMLReader* parser,
301  RegexpHandler<T>& root,
302  T param,
303  const xercesc::Attributes& attrs);
304  } // !builders
305 
309  namespace builders
310  {
311  template <typename T>
312  void
313  check_monoid_consistency (T& param,
314  const XMLCh* const localname,
315  const xercesc::Attributes& attrs,
316  XMLEq&);
317 
318  template <typename T>
319  void
320  check_semiring_consistency (T& param,
321  const XMLCh* const localname,
322  const xercesc::Attributes& attrs);
323  } // !builders
324 
328  namespace builders
329  {
330  template <typename T>
331  void
332  create_semiring_node(const T& semiring,
333  xercesc::DOMDocument* doc,
334  xercesc::DOMElement* root);
335 
336  template <typename T>
337  void
338  create_monoid_node(const T& monoid,
339  xercesc::DOMDocument* doc,
340  xercesc::DOMElement* root);
341 
342  template <typename T>
343  void
344  create_regexp_node(const T&,
345  xercesc::DOMDocument* doc,
346  xercesc::DOMElement* root,
347  const char* root_name = "label");
348 
349  template <typename T>
350  void
351  create_monElmt_node(const T&,
352  xercesc::DOMDocument* doc,
353  xercesc::DOMElement* root);
354 
355  template <typename T>
356  void
357  create_type_writingData_node(const T&,
358  xercesc::DOMDocument* doc,
359  xercesc::DOMElement* root);
360 
361  // Functor to allow partial specialization.
362  template <typename T>
363  struct
364  create_monGen_node;
365 
366  } // ! builders
367 
368  } // ! xml
369 
370 } // ! vcsn
371 
372 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
373 # include <vaucanson/xml/builders.hxx>
374 # endif // VCSN_USE_INTERFACE_ONLY || !VCSN_USE_LIB
375 
376 #endif // !VCSN_XML_BUILDERS_HH