Vaucanson  1.4.1
XML.hxx
1 // XML.hxx: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2005, 2006 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_XML_HXX
19 # define VCSN_XML_XML_HXX
20 
21 # include <vaucanson/xml/parsers.hh>
22 # include <vaucanson/xml/printers.hh>
23 
24 namespace vcsn
25 {
26  namespace xml
27  {
28  XML::XML(const std::string& name)
29  : name_(name)
30  {
31  XML::inst_ += 1;
32  if (XML::inst_ == 1)
33  xercesc::XMLPlatformUtils::Initialize();
34  }
35 
36  XML::~XML()
37  {
38  XML::inst_ -= 1;
39  if (!XML::inst_)
40  xercesc::XMLPlatformUtils::Terminate();
41  }
42 
43  XML::XML(const XML& old)
44  : name_(old.name_)
45  {
46  XML::inst_ += 1;
47  }
48 
49  template <typename Auto, typename T, typename Format, typename Conv>
50  void XML::operator()(std::ostream& out,
51  const vcsn::tools::automaton_saver_<Auto, T, Format>& s,
52  const Conv&) const
53  {
54  AutPrinter<Auto>* printer = new AutPrinter<Auto>(s.automaton(), name_);
55  printer->print(out);
56  delete printer;
57  }
58 
59  template <typename RE, typename T, typename Format, typename Conv>
60  void XML::operator()(std::ostream& out,
61  const vcsn::tools::regexp_saver_<RE, T, Format>& s,
62  const Conv&) const
63  {
64  RegExpPrinter<RE>* printer = new RegExpPrinter<RE>(s.rat_exp(), name_);
65  printer->print(out);
66  delete printer;
67  }
68 
69  template <typename Auto, typename T, typename Format>
70  void
71  XML::operator()(std::istream& in,
72  vcsn::tools::automaton_loader_<Auto, T, Format>& l,
73  bool check)
74  {
75  AutParser<Auto>* parser = new AutParser<Auto>(l.automaton(), check);
76  parser->parse(in);
77  delete parser;
78  }
79 
80  template <typename RE, typename T, typename Format>
81  void
82  XML::operator()(std::istream& in,
83  vcsn::tools::regexp_loader_<RE, T, Format>& l,
84  bool check)
85  {
86  RegExpParser<RE>* parser = new RegExpParser<RE>(l.rat_exp(), check);
87  parser->parse(in);
88  delete parser;
89  }
90 
91 
92  int XML::inst_ = 0;
93  } // !xml
94 } // !vcsn
95 
96 #endif // ! VCSN_XML_XML_HXX