Vaucanson 1.4
XML.hxx
00001 // XML.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2005, 2006 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_XML_HXX
00019 # define VCSN_XML_XML_HXX
00020 
00021 # include <vaucanson/xml/parsers.hh>
00022 # include <vaucanson/xml/printers.hh>
00023 
00024 namespace vcsn
00025 {
00026   namespace xml
00027   {
00028     XML::XML(const std::string& name)
00029       : name_(name)
00030     {
00031       XML::inst_ += 1;
00032       if (XML::inst_ == 1)
00033         xercesc::XMLPlatformUtils::Initialize();
00034     }
00035 
00036     XML::~XML()
00037     {
00038       XML::inst_ -= 1;
00039       if (!XML::inst_)
00040         xercesc::XMLPlatformUtils::Terminate();
00041     }
00042 
00043     XML::XML(const XML& old)
00044       : name_(old.name_)
00045     {
00046       XML::inst_ += 1;
00047     }
00048 
00049     template <typename Auto, typename T, typename Format, typename Conv>
00050     void XML::operator()(std::ostream& out,
00051                          const vcsn::tools::automaton_saver_<Auto, T, Format>& s,
00052                          const Conv&) const
00053     {
00054       AutPrinter<Auto>* printer = new AutPrinter<Auto>(s.automaton(), name_);
00055       printer->print(out);
00056       delete printer;
00057     }
00058 
00059     template <typename RE, typename T, typename Format, typename Conv>
00060     void XML::operator()(std::ostream& out,
00061                          const vcsn::tools::regexp_saver_<RE, T, Format>& s,
00062                          const Conv&) const
00063     {
00064       RegExpPrinter<RE>* printer = new RegExpPrinter<RE>(s.rat_exp(), name_);
00065       printer->print(out);
00066       delete printer;
00067     }
00068 
00069     template <typename Auto, typename T, typename Format>
00070     void
00071     XML::operator()(std::istream& in,
00072                     vcsn::tools::automaton_loader_<Auto, T, Format>& l,
00073                     bool check)
00074     {
00075       AutParser<Auto>* parser = new AutParser<Auto>(l.automaton(), check);
00076       parser->parse(in);
00077       delete parser;
00078     }
00079 
00080     template <typename RE, typename T, typename Format>
00081     void
00082     XML::operator()(std::istream& in,
00083                     vcsn::tools::regexp_loader_<RE, T, Format>& l,
00084                     bool check)
00085     {
00086       RegExpParser<RE>* parser = new RegExpParser<RE>(l.rat_exp(), check);
00087       parser->parse(in);
00088       delete parser;
00089     }
00090 
00091 
00092     int XML::inst_ = 0;
00093   } // !xml
00094 } // !vcsn
00095 
00096 #endif // ! VCSN_XML_XML_HXX