session.hxx

Go to the documentation of this file.
00001 // session.hxx: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2005 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 #ifndef VCSN_XML_SESSION_HXX
00018 # define VCSN_XML_SESSION_HXX
00019 
00032 namespace vcsn
00033 {
00034   namespace xml
00035   {
00036 
00037     xml_session::xml_session()
00038     {
00039       using namespace xercesc;
00040 
00041       XMLPlatformUtils::Initialize();
00042       impl = DOMImplementationRegistry::getDOMImplementation(STR2XML("LS"));
00043       doc = impl->createDocument(STR2XML("http://vaucanson.lrde.epita.fr"),
00044                                  STR2XML("session"), 0);
00045       root = doc->getDocumentElement();
00046     }
00047 
00048 
00049     xml_session::~xml_session()
00050     {
00051       xercesc::XMLPlatformUtils::Terminate();
00052     }
00053 
00054   } // ! xml
00055 
00056   template<typename S, typename T>
00057   xml::xml_session&
00058   op_rout(const S& structure,
00059           xml::xml_session& s,
00060           const T& value)
00061   {
00062     xercesc::XMLPlatformUtils::Initialize();
00063 
00064     Element<S, T> a(structure, value);
00065     xml::xml_converter<Element<S, T> > x;
00066     x.create_document(a);
00067     xercesc::DOMNode* node =
00068       s.doc->importNode(static_cast<xercesc::DOMNode*>(x.root_get()), true);
00069 
00070     s.root->appendChild(node);
00071 
00072     return s;
00073   }
00074 
00075 
00076   template <class S, class T>
00077   xml::xml_session& op_rin(S& structure,
00078                            xml::xml_session& s,
00079                            T& value)
00080   {
00081     using namespace xercesc;
00082     using namespace vcsn;
00083     using namespace vcsn::xml;
00084 
00085     XMLPlatformUtils::Initialize();
00086     Element<S, T> a(structure, value);
00087 
00088     // Clear the automaton content.
00089     for (typename Element<S, T>::state_iterator is = a.states().begin();
00090          is != a.states().end(); ++is)
00091       a.del_state(*is);
00092 
00093     if (! s.root->getFirstChild())
00094       FAIL("No more automaton in session");
00095     for (DOMNode* n = s.root->getFirstChild(); n; n = n->getNextSibling())
00096       if (n->getNodeType() == DOMNode::ELEMENT_NODE)
00097         {
00098           DOMElement* elt = static_cast<DOMElement*>(n);
00099 
00100           typedef Element<S, T> automaton_t;
00101           typedef Node<automaton_t> node_t;
00102           Factory<node_t, std::string> f;
00103           register_all_factory(f, automaton_t);
00104           typename node_t::map_t str2state;
00105 
00106           node_t* node = factory_create(f, xml2str(n->getNodeName()));
00107           node->process(elt, a, str2state, f);
00108           s.root->removeChild(n);
00109         }
00110     op_assign(structure.self(), value, a.value());
00111 
00112     return s;
00113   }
00114 
00115 
00116   template <class IStream>
00117   IStream& operator >> (IStream& is, xml::xml_session& s)
00118   {
00119     using namespace xercesc;
00120 
00121     xercesc::XMLPlatformUtils::Initialize();
00122     DOMNode* node = xml::xerces_parser::stream_parser(is);
00123 
00124     for (DOMNode* n = node->getFirstChild(); n; n = n->getNextSibling())
00125       if (n->getNodeType() == DOMNode::ELEMENT_NODE)
00126         (s.root)->appendChild(s.doc->importNode(n, true));
00127 
00128     return is;
00129   }
00130 
00131 
00132   template <class OStream>
00133   OStream& operator << (OStream& out, const xml::xml_session& s)
00134   {
00135     xercesc::XMLPlatformUtils::Initialize();
00136     xml::tools::print_document(s.root, out);
00137 
00138     return out;
00139   }
00140 
00141 
00142 } // !vcsn
00143 
00144 #endif // ! VCSN_XML_SESSION_HXX

Generated on Fri Jul 28 12:18:52 2006 for Vaucanson by  doxygen 1.4.6