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_NODE_HH) and VCSN_INCLUDE_XML()
00021 # define VCSN_XML_NODE_HH
00022
00023 # ifndef VCSN_USE_XML
00024 # error Vaucanson XML support is disabled.
00025 # endif
00026
00037 # include <string>
00038 # include <sstream>
00039 # include <map>
00040 # include <xercesc/dom/DOM.hpp>
00041 # include <vaucanson/design_pattern/factory.hh>
00042 # include <vaucanson/algebra/concept/freemonoid_product.hh>
00043 # include <vaucanson/algebra/implementation/series/krat_exp_parser.hh>
00044 # include <vaucanson/misc/usual_macros.hh>
00045 # include <vaucanson/xml/xml_chooser.hh>
00046 # include <vaucanson/xml/tools.hh>
00047
00048
00049 namespace vcsn
00050 {
00051 namespace xml
00052 {
00053
00054
00055 template <class T1, class T2>
00056 struct reference_pair
00057 {
00058 reference_pair(T1& f, T2& s) : first(f), second(s) {}
00059 T1& first;
00060 T2& second;
00061 };
00062
00069 template <class T>
00070 struct Node
00071 {
00072 typedef Factory<Node<T>, std::string> factory_t;
00073 typedef std::map<std::string, hstate_t> map_t;
00074 typedef reference_pair<std::map<hstate_t, std::pair<double, double> >,
00075 hstate_t> map_state_pair_t;
00076 typedef reference_pair<std::map<htransition_t, std::pair<double, double> >,
00077 htransition_t> map_transition_pair_t;
00078 virtual void process(xercesc::DOMElement*, T&, map_t&, factory_t&) = 0;
00079 virtual ~Node();
00080 };
00081
00082
00083 # define CREATE_CLASSNODE(name) \
00084 template <class T> \
00085 struct name ## Node : Node<T> \
00086 { \
00087 void process(xercesc::DOMElement*, T&, \
00088 typename Node<T>::map_t&, \
00089 typename Node<T>::factory_t&); \
00090 static Node<T>* create() { return new name ## Node; } \
00091 };
00092
00093 # define CREATE_PARAM_CLASSNODE(name) \
00094 template <class T> \
00095 struct name ## Node : Node<T> \
00096 { \
00097 void process(xercesc::DOMElement*, T&, \
00098 typename Node<T>::map_t&, \
00099 typename Node<T>::factory_t&) {}; \
00100 \
00101 template <class U> \
00102 void process(xercesc::DOMElement*, T&, U &, \
00103 typename Node<T>::map_t&, \
00104 typename Node<T>::factory_t&); \
00105 static Node<T>* create() { return new name ## Node; } \
00106 };
00107
00108
00109 CREATE_CLASSNODE(automaton)
00110 CREATE_CLASSNODE(transducer)
00111 CREATE_CLASSNODE(labelType)
00112 CREATE_CLASSNODE(content)
00113 CREATE_CLASSNODE(states)
00114 CREATE_CLASSNODE(transitions)
00115 CREATE_CLASSNODE(state)
00116 CREATE_CLASSNODE(transition)
00117 CREATE_CLASSNODE(initial)
00118 CREATE_CLASSNODE(final)
00119 CREATE_PARAM_CLASSNODE(semiring)
00120 CREATE_PARAM_CLASSNODE(monoid)
00121 CREATE_PARAM_CLASSNODE(freemonoid)
00122 CREATE_PARAM_CLASSNODE(generator)
00123 CREATE_PARAM_CLASSNODE(geometry)
00124 CREATE_PARAM_CLASSNODE(drawing)
00125
00126
00127 # define TParm \
00128 template <class S, class T>
00129 # define TParmFMP \
00130 template <class S, class T, class M1, class M2>
00131 # define AUTtype \
00132 Element<Automata<S>, T>
00133 # define TRANStype \
00134 Element<Transducer<S>, T>
00135
00136 # define FMPtype \
00137 Element< \
00138 Automata< \
00139 vcsn::algebra::Series<S, vcsn::algebra::FreeMonoidProduct<M1, M2> > \
00140 >, \
00141 T>
00142
00143 # define CREATE_SPEC_TYPE_NODE(TempParam, Type) \
00144 TempParam \
00145 struct labelTypeNode<Type > : Node<Type > \
00146 { \
00147 void process(xercesc::DOMElement*, Type&, \
00148 typename Node<Type >::map_t&, \
00149 typename Node<Type >::factory_t&); \
00150 static Node<Type >* create() { return new labelTypeNode; } \
00151 };
00152
00153
00154 # define CREATE_SPEC_PARAM_NODE(name, TempParam, Type) \
00155 TempParam \
00156 struct name ## Node<Type > : Node<Type > \
00157 { \
00158 void process(xercesc::DOMElement*, Type&, \
00159 typename Node<Type >::map_t&, \
00160 typename Node<Type >::factory_t&) {}; \
00161 template <class U> \
00162 void process(xercesc::DOMElement*, Type&, U &, \
00163 typename Node<Type >::map_t&, \
00164 typename Node<Type >::factory_t&); \
00165 static Node<Type >* create() { return new name ## Node; } \
00166 };
00167
00168
00169 CREATE_SPEC_TYPE_NODE(TParm, AUTtype)
00170 CREATE_SPEC_TYPE_NODE(TParm, TRANStype)
00171 CREATE_SPEC_TYPE_NODE(TParmFMP, FMPtype)
00172 CREATE_SPEC_PARAM_NODE(semiring, TParm, TRANStype)
00173 CREATE_SPEC_PARAM_NODE(monoid, TParmFMP, FMPtype)
00174
00175
00176 }
00177
00178 }
00179
00180
00181
00182
00183 # define register_in_factory(f, T, name) \
00184 factory_reg(f, std::string(#name), name ## Node<T>::create);
00185
00186 # define register_all_factory(f, T) \
00187 register_in_factory(f, T, automaton) \
00188 register_in_factory(f, T, transducer) \
00189 register_in_factory(f, T, labelType) \
00190 register_in_factory(f, T, semiring) \
00191 register_in_factory(f, T, monoid) \
00192 register_in_factory(f, T, freemonoid) \
00193 register_in_factory(f, T, generator) \
00194 register_in_factory(f, T, content) \
00195 register_in_factory(f, T, states) \
00196 register_in_factory(f, T, transitions) \
00197 register_in_factory(f, T, state) \
00198 register_in_factory(f, T, transition) \
00199 register_in_factory(f, T, initial) \
00200 register_in_factory(f, T, final)
00201
00202
00203 # ifndef VCSN_USE_INTERFACE_ONLY
00204 # include <vaucanson/xml/node.hxx>
00205 # endif
00206
00207 #endif