00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef VCSN_XML_NODE_HH
00019 # define VCSN_XML_NODE_HH
00020
00031 # include <string>
00032 # include <sstream>
00033 # include <map>
00034 # include <xercesc/dom/DOM.hpp>
00035 # include <vaucanson/design_pattern/factory.hh>
00036 # include <vaucanson/algebra/concept/freemonoid_product.hh>
00037 # include <vaucanson/algebra/implementation/series/krat_exp_parser.hh>
00038 # include <vaucanson/misc/usual_macros.hh>
00039 # include <vaucanson/xml/xml_chooser.hh>
00040 # include <vaucanson/xml/tools.hh>
00041
00042
00043 namespace vcsn
00044 {
00045 namespace xml
00046 {
00047
00048
00049 template <class T1, class T2>
00050 struct reference_pair
00051 {
00052 reference_pair(T1& f, T2& s) : first(f), second(s) {}
00053 T1& first;
00054 T2& second;
00055 };
00056
00063 template <class T>
00064 struct Node
00065 {
00066 typedef Factory<Node<T>, std::string> factory_t;
00067 typedef typename T::hstate_t hstate_t;
00068 typedef typename T::htransition_t htransition_t;
00069 typedef std::map<std::string, hstate_t> map_t;
00070 typedef reference_pair<std::map<hstate_t, typename T::geometry_t::coords_t>,
00071 hstate_t> map_state_pair_t;
00072 typedef reference_pair<std::map<htransition_t,
00073 typename T::geometry_t::coords_t>,
00074 htransition_t> map_transition_pair_t;
00075 virtual void process(xercesc::DOMElement* node, T& aut,
00076 map_t& m, factory_t& f) = 0;
00077 virtual ~Node();
00078 };
00079
00080
00081 # define CREATE_CLASSNODE(name) \
00082 template <class T> \
00083 struct name ## Node : Node<T> \
00084 { \
00085 void process(xercesc::DOMElement* node, T& aut, \
00086 typename Node<T>::map_t& m, \
00087 typename Node<T>::factory_t& f); \
00088 static Node<T>* create() { return new name ## Node; } \
00089 };
00090
00091
00092 CREATE_CLASSNODE(automaton)
00093 CREATE_CLASSNODE(content)
00094 CREATE_CLASSNODE(final)
00095 CREATE_CLASSNODE(initial)
00096 CREATE_CLASSNODE(labelType)
00097 CREATE_CLASSNODE(state)
00098 CREATE_CLASSNODE(states)
00099 CREATE_CLASSNODE(transducer)
00100 CREATE_CLASSNODE(transition)
00101 CREATE_CLASSNODE(transitions)
00102
00103 #undef CREATE_CLASSNODE
00104
00108
00109 # define CREATE_PARAM_CLASSNODE(Name) \
00110 template <class T> \
00111 struct Name ## Node : Node<T> \
00112 { \
00113 void process(xercesc::DOMElement*, T&, \
00114 typename Node<T>::map_t&, \
00115 typename Node<T>::factory_t&) \
00116 {}; \
00117 \
00118 template <class U> \
00119 void process(xercesc::DOMElement*, T&, U &, \
00120 typename Node<T>::map_t&, \
00121 typename Node<T>::factory_t&); \
00122 \
00123 static \
00124 Node<T>* \
00125 create() \
00126 { \
00127 return new Name ## Node; \
00128 } \
00129 };
00130
00131 CREATE_PARAM_CLASSNODE(drawing)
00132 CREATE_PARAM_CLASSNODE(freemonoid)
00133 CREATE_PARAM_CLASSNODE(generator)
00134 CREATE_PARAM_CLASSNODE(geometry)
00135 CREATE_PARAM_CLASSNODE(monoid)
00136 CREATE_PARAM_CLASSNODE(semiring)
00137
00138 #undef CREATE_PARAM_CLASSNODE
00139
00140
00141 # define TParm \
00142 template <class S, class T>
00143 # define TParmFMP \
00144 template <class S, class T, class M1, class M2>
00145 # define AUTtype \
00146 Element<Automata<S>, T>
00147 # define TRANStype \
00148 Element<Transducer<S>, T>
00149
00150 # define FMPtype \
00151 Element< \
00152 Automata< \
00153 vcsn::algebra::Series<S, vcsn::algebra::FreeMonoidProduct<M1, M2> > \
00154 >, \
00155 T>
00156
00157 # define CREATE_SPEC_TYPE_NODE(TempParam, Type) \
00158 TempParam \
00159 struct labelTypeNode<Type > : Node<Type > \
00160 { \
00161 void process(xercesc::DOMElement*, Type&, \
00162 typename Node<Type >::map_t&, \
00163 typename Node<Type >::factory_t&); \
00164 static Node<Type >* create() { return new labelTypeNode; } \
00165 };
00166
00167
00168 CREATE_SPEC_TYPE_NODE(TParm, AUTtype)
00169 CREATE_SPEC_TYPE_NODE(TParm, TRANStype)
00170 CREATE_SPEC_TYPE_NODE(TParmFMP, FMPtype)
00171
00172 #undef CREATE_SPEC_TYPE_NODE
00173
00174
00175 # define CREATE_SPEC_PARAM_NODE(name, TempParam, Type) \
00176 TempParam \
00177 struct name ## Node<Type > : Node<Type > \
00178 { \
00179 void process(xercesc::DOMElement*, Type&, \
00180 typename Node<Type >::map_t&, \
00181 typename Node<Type >::factory_t&) {}; \
00182 template <class U> \
00183 void process(xercesc::DOMElement*, Type&, U &, \
00184 typename Node<Type >::map_t&, \
00185 typename Node<Type >::factory_t&); \
00186 static Node<Type >* create() { return new name ## Node; } \
00187 };
00188
00189
00190 CREATE_SPEC_PARAM_NODE(semiring, TParm, TRANStype)
00191 CREATE_SPEC_PARAM_NODE(monoid, TParmFMP, FMPtype)
00192
00193 # undef CREATE_SPEC_PARAM_NODE
00194
00195
00196 }
00197
00198 }
00199
00200
00201
00202
00203 # define register_in_factory(f, T, name) \
00204 factory_reg(f, std::string(#name), name ## Node<T>::create);
00205
00206 # define register_all_factory(f, T) \
00207 register_in_factory(f, T, automaton) \
00208 register_in_factory(f, T, transducer) \
00209 register_in_factory(f, T, labelType) \
00210 register_in_factory(f, T, semiring) \
00211 register_in_factory(f, T, monoid) \
00212 register_in_factory(f, T, freemonoid) \
00213 register_in_factory(f, T, generator) \
00214 register_in_factory(f, T, content) \
00215 register_in_factory(f, T, states) \
00216 register_in_factory(f, T, transitions) \
00217 register_in_factory(f, T, state) \
00218 register_in_factory(f, T, transition) \
00219 register_in_factory(f, T, initial) \
00220 register_in_factory(f, T, final)
00221
00222
00223 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00224 # include <vaucanson/xml/node.hxx>
00225 # endif // VCSN_USE_INTERFACE_ONLY
00226
00227 # undef AUTtype
00228 # undef FMPtype
00229 # undef TParm
00230 # undef TParmFMP
00231 # undef TRANStype
00232
00233 #endif // ! VCSN_XML_NODE_HH