00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include <vaucanson/config/system.hh>
00019
00020 #if not defined (VCSN_XML_XML_CONVERTER_HH) and \
00021 (not defined (VCSN_SANITY_CHECK) or defined (VCSN_USE_XML))
00022 # define VCSN_XML_XML_CONVERTER_HH
00023
00024 # ifndef VCSN_USE_XML
00025 # error Vaucanson XML support is disabled.
00026 # endif
00027
00039 # include <xercesc/dom/DOM.hpp>
00040 # include <xercesc/util/XMLString.hpp>
00041 # include <xercesc/util/PlatformUtils.hpp>
00042
00043 # include <string>
00044 # include <sstream>
00045
00046 # include <vaucanson/design_pattern/element.hh>
00047 # include <vaucanson/design_pattern/factory.hh>
00048 # include <vaucanson/tools/usual_macros.hh>
00049 # include <vaucanson/xml/xerces_parser.hh>
00050 # include <vaucanson/xml/node.hh>
00051 # include <vaucanson/xml/xml_chooser.hh>
00052
00053
00054 namespace vcsn
00055 {
00056 namespace xml
00057 {
00064 template <class Auto>
00065 struct xml_converter
00066 {
00067 xml_converter(bool use_label_node = false) :
00068 impl_(0), doc_(0), root_(0), use_label_node_(use_label_node) {};
00069
00070 typedef std::map<hstate_t, std::string> map_t;
00071 typedef typename Auto::set_t auto_set_t;
00072 typedef typename Auto::value_t auto_impl_t;
00073 typedef xml_chooser<auto_set_t, auto_impl_t> xml_chooser_t;
00074
00084 template <class OStream>
00085 void save(const Auto& a, OStream& out, const std::string& name = "");
00086
00095 template <class IStream>
00096 void load(Auto& a, IStream& in);
00097
00098 void create_document(const Auto& aut, const std::string& name = "");
00099
00100 xercesc::DOMElement* root_get() { return root_; }
00101
00102 private:
00103 std::string create_state(hstate_t, const Auto&, xercesc::DOMElement*);
00104 void create_transition(htransition_t, const Auto&,
00105 xercesc::DOMElement*, map_t&);
00106 void create_initial(hstate_t, const Auto&,
00107 xercesc::DOMElement*, map_t&);
00108 void create_final(hstate_t, const Auto&,
00109 xercesc::DOMElement*, map_t&);
00110
00111 template <class Map, class Key>
00112 void add_xml_geometry(Map&, Key&, xercesc::DOMElement* node);
00113 template <class Map, class Key>
00114 void add_xml_drawing(Map&, Key&, xercesc::DOMElement* node);
00115
00116 xercesc::DOMImplementation* impl_;
00117 xercesc::DOMDocument* doc_;
00118 xercesc::DOMElement* root_;
00119 xml_chooser_t chooser_;
00120 bool use_label_node_;
00121 };
00122
00123 }
00124
00125 }
00126
00127
00128 # ifndef VCSN_USE_INTERFACE_ONLY
00129 # include <vaucanson/xml/xml_converter.hxx>
00130 # endif // VCSN_USE_INTERFACE_ONLY
00131
00132 #endif // ! VCSN_XML_XML_CONVERTER_HH && (! VCSN_SANITY_CHECK || VCSN_USE_XML)