XML.hxx

Go to the documentation of this file.
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 
00031 # include <xercesc/sax/SAXException.hpp>
00032 
00033 # include <vaucanson/misc/usual_macros.hh>
00034 # include <vaucanson/xml/xml_converter.hh>
00035 # include <vaucanson/xml/parsers.hh>
00036 
00037 namespace vcsn
00038 {
00039   namespace xml
00040   {
00041     XML::XML(const std::string& name, bool use_label_node)
00042       : name_(name), use_label_node_(use_label_node), check_(true)
00043     {
00044       XML::inst_ += 1;
00045       if (XML::inst_ == 1)
00046         xercesc::XMLPlatformUtils::Initialize();
00047     }
00048 
00049     XML::~XML()
00050     {
00051       XML::inst_ -= 1;
00052       if (!XML::inst_)
00053         xercesc::XMLPlatformUtils::Terminate();
00054     }
00055 
00056     XML::XML(const XML& old)
00057       : name_(old.name_),
00058         use_label_node_(old.use_label_node_),
00059         check_(old.check_)
00060     {
00061       XML::inst_ += 1;
00062     }
00063 
00064     void
00065     XML::check(bool check)
00066     {
00067       check_ = check;
00068     }
00069 
00070     template<typename Saver, typename Conv>
00071     void XML::operator()(std::ostream& out, const Saver& s,
00072                          const Conv&) const
00073     {
00074       typedef typename Saver::automaton_t automaton_t;
00075 
00076       xml_converter<automaton_t> xc(use_label_node_);
00077       xc.save(s.automaton(), out, name_);
00078     }
00079 
00080     template <typename Loader>
00081     void
00082     XML::operator()(std::istream& in, Loader& l)
00083     {
00084 
00085       typedef typename Loader::automaton_t      automaton_t;
00086       AutParser<automaton_t>* parser = new AutParser<automaton_t>(l.automaton(), check_);
00087       parser->parse(in);
00088       // FIXME The use of xercesc::XMLPlatformUtils::Terminate()
00089       // does not seems to appreciate the parser to be deleted.
00090       // delete parser;
00091     }
00092 
00093     int XML::inst_ = 0;
00094   } // !xml
00095 } // !vcsn
00096 
00097 #endif // ! VCSN_XML_XML_HXX

Generated on Sun Jul 29 19:35:31 2007 for Vaucanson by  doxygen 1.5.2