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 Saver, typename Conv>
00050     void XML::operator()(std::ostream& out,
00051                          const Saver& s,
00052                          const Conv&) const
00053     {
00054       typedef typename Saver::automaton_t automaton_t;
00055       AutPrinter<automaton_t>* printer = new AutPrinter<automaton_t>(s.automaton(), name_);
00056       printer->print(out);
00057       delete printer;
00058     }
00059 
00060     template <typename Loader>
00061     void
00062     XML::operator()(std::istream& in,
00063                     Loader& l,
00064                     bool check)
00065     {
00066       typedef typename Loader::automaton_t      automaton_t;
00067       AutParser<automaton_t>* parser = new AutParser<automaton_t>(l.automaton(), check);
00068       parser->parse(in);
00069       delete parser;
00070     }
00071 
00072     int XML::inst_ = 0;
00073   } // !xml
00074 } // !vcsn
00075 
00076 #endif // ! VCSN_XML_XML_HXX

Generated on Thu Oct 9 20:22:42 2008 for Vaucanson by  doxygen 1.5.1