node.hh

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

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