node.hh

Go to the documentation of this file.
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, 2006 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 #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     // Structure used to simulate pair of references, used in geometry.
00048     // FIXME: Use boost::tuple instead.
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 std::map<std::string, hstate_t> map_t;
00068       typedef reference_pair<std::map<hstate_t, std::pair<double, double> >,
00069                              hstate_t> map_state_pair_t;
00070       typedef reference_pair<std::map<htransition_t, std::pair<double, double> >,
00071                              htransition_t> map_transition_pair_t;
00072       virtual void process(xercesc::DOMElement* node, T& aut, 
00073                            map_t& m, factory_t& f) = 0;
00074       virtual ~Node();
00075     };
00076 
00077 
00078 # define CREATE_CLASSNODE(name)                                 \
00079     template <class T>                                          \
00080     struct name ## Node : Node<T>                               \
00081     {                                                           \
00082       void process(xercesc::DOMElement* node, T& aut,           \
00083                    typename Node<T>::map_t& m,                  \
00084                    typename Node<T>::factory_t& f);             \
00085       static Node<T>* create() { return new name ## Node; }     \
00086     };
00087 
00088 
00089     CREATE_CLASSNODE(automaton)
00090     CREATE_CLASSNODE(content)
00091     CREATE_CLASSNODE(final)
00092     CREATE_CLASSNODE(initial)
00093     CREATE_CLASSNODE(labelType)
00094     CREATE_CLASSNODE(state)
00095     CREATE_CLASSNODE(states)
00096     CREATE_CLASSNODE(transducer)
00097     CREATE_CLASSNODE(transition)
00098     CREATE_CLASSNODE(transitions)
00099 
00100 #undef CREATE_CLASSNODE
00101 
00105 
00106 # define CREATE_PARAM_CLASSNODE(Name)                           \
00107     template <class T>                                          \
00108     struct Name ## Node : Node<T>                               \
00109     {                                                           \
00110       void process(xercesc::DOMElement*, T&,                    \
00111                    typename Node<T>::map_t&,                    \
00112                    typename Node<T>::factory_t&)                \
00113       {};                                                       \
00114                                                                 \
00115       template <class U>                                        \
00116       void process(xercesc::DOMElement*, T&, U &,               \
00117                    typename Node<T>::map_t&,                    \
00118                    typename Node<T>::factory_t&);               \
00119                                                                 \
00120       static                                                    \
00121       Node<T>*                                                  \
00122       create()                                                  \
00123       {                                                         \
00124         return new Name ## Node;                                \
00125       }                                                         \
00126     };
00127 
00128     CREATE_PARAM_CLASSNODE(drawing)
00129     CREATE_PARAM_CLASSNODE(freemonoid)
00130     CREATE_PARAM_CLASSNODE(generator)
00131     CREATE_PARAM_CLASSNODE(geometry)
00132     CREATE_PARAM_CLASSNODE(monoid)
00133     CREATE_PARAM_CLASSNODE(semiring)
00134 
00135 #undef CREATE_PARAM_CLASSNODE
00136 
00137 
00138 # define TParm                                  \
00139     template <class S, class T>
00140 # define TParmFMP                                       \
00141     template <class S, class T, class M1, class M2>
00142 # define AUTtype                                \
00143     Element<Automata<S>, T>
00144 # define TRANStype                              \
00145     Element<Transducer<S>, T>
00146 
00147 # define FMPtype                                                        \
00148     Element<                                                            \
00149       Automata<                                                         \
00150         vcsn::algebra::Series<S, vcsn::algebra::FreeMonoidProduct<M1, M2> > \
00151         >,                                                              \
00152       T>
00153 
00154 # define CREATE_SPEC_TYPE_NODE(TempParam, Type)                         \
00155     TempParam                                                           \
00156     struct labelTypeNode<Type > : Node<Type >                           \
00157     {                                                                   \
00158       void process(xercesc::DOMElement*, Type&,                         \
00159                    typename Node<Type >::map_t&,                        \
00160                    typename Node<Type >::factory_t&);                   \
00161       static Node<Type >* create() { return new labelTypeNode; }        \
00162     };
00163 
00164 
00165     CREATE_SPEC_TYPE_NODE(TParm, AUTtype)
00166     CREATE_SPEC_TYPE_NODE(TParm, TRANStype)
00167     CREATE_SPEC_TYPE_NODE(TParmFMP, FMPtype)
00168 
00169 #undef CREATE_SPEC_TYPE_NODE
00170 
00171 
00172 # define CREATE_SPEC_PARAM_NODE(name, TempParam, Type)          \
00173     TempParam                                                   \
00174     struct name ## Node<Type > : Node<Type >                    \
00175     {                                                           \
00176       void process(xercesc::DOMElement*, Type&,                 \
00177                    typename Node<Type >::map_t&,                \
00178                    typename Node<Type >::factory_t&) {};        \
00179       template <class U>                                        \
00180         void process(xercesc::DOMElement*, Type&, U &,          \
00181                      typename Node<Type >::map_t&,              \
00182                      typename Node<Type >::factory_t&);         \
00183       static Node<Type >* create() { return new name ## Node; } \
00184     };
00185 
00186 
00187     CREATE_SPEC_PARAM_NODE(semiring, TParm, TRANStype)
00188     CREATE_SPEC_PARAM_NODE(monoid, TParmFMP, FMPtype)
00189 
00190 # undef CREATE_SPEC_PARAM_NODE
00191 
00192 
00193   } // ! xml
00194 
00195 } // !vcsn
00196 
00197 
00198 // Macros used to declare the factory. It cannot be done using a
00199 // static attribute since the class is templated.
00200 # define register_in_factory(f, T, name)                        \
00201   factory_reg(f, std::string(#name), name ## Node<T>::create);
00202 
00203 # define register_all_factory(f, T)             \
00204   register_in_factory(f, T, automaton)          \
00205   register_in_factory(f, T, transducer)         \
00206   register_in_factory(f, T, labelType)          \
00207   register_in_factory(f, T, semiring)           \
00208   register_in_factory(f, T, monoid)             \
00209   register_in_factory(f, T, freemonoid)         \
00210   register_in_factory(f, T, generator)          \
00211   register_in_factory(f, T, content)            \
00212   register_in_factory(f, T, states)             \
00213   register_in_factory(f, T, transitions)        \
00214   register_in_factory(f, T, state)              \
00215   register_in_factory(f, T, transition)         \
00216   register_in_factory(f, T, initial)            \
00217   register_in_factory(f, T, final)
00218 
00219 
00220 # if !defined VCSN_USE_INTERFACE_ONLY || defined VCSN_USE_LIB
00221 #  include <vaucanson/xml/node.hxx>
00222 # endif // VCSN_USE_INTERFACE_ONLY
00223 
00224 # undef AUTtype
00225 # undef FMPtype
00226 # undef TParm
00227 # undef TParmFMP
00228 # undef TRANStype
00229 
00230 #endif // ! VCSN_XML_NODE_HH

Generated on Sun Jul 29 19:35:27 2007 for Vaucanson by  doxygen 1.5.2