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 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*, T&, map_t&, factory_t&) = 0;
00073         virtual ~Node();
00074     };
00075 
00076 
00077 # define CREATE_CLASSNODE(name)                                 \
00078     template <class T>                                          \
00079     struct name ## Node : Node<T>                               \
00080     {                                                           \
00081       void process(xercesc::DOMElement*, T&,                    \
00082                    typename Node<T>::map_t&,                    \
00083                    typename Node<T>::factory_t&);               \
00084       static Node<T>* create() { return new name ## Node; }     \
00085     };
00086 
00087 # define CREATE_PARAM_CLASSNODE(name)                           \
00088     template <class T>                                          \
00089     struct name ## Node : Node<T>                               \
00090     {                                                           \
00091       void process(xercesc::DOMElement*, T&,                    \
00092                    typename Node<T>::map_t&,                    \
00093                    typename Node<T>::factory_t&) {};            \
00094                                                                 \
00095       template <class U>                                        \
00096         void process(xercesc::DOMElement*, T&, U &,             \
00097                      typename Node<T>::map_t&,                  \
00098                      typename Node<T>::factory_t&);             \
00099       static Node<T>* create() { return new name ## Node; }     \
00100     };
00101 
00102 
00103     CREATE_CLASSNODE(automaton)
00104     CREATE_CLASSNODE(transducer)
00105     CREATE_CLASSNODE(labelType)
00106     CREATE_CLASSNODE(content)
00107     CREATE_CLASSNODE(states)
00108     CREATE_CLASSNODE(transitions)
00109     CREATE_CLASSNODE(state)
00110     CREATE_CLASSNODE(transition)
00111     CREATE_CLASSNODE(initial)
00112     CREATE_CLASSNODE(final)
00113     CREATE_PARAM_CLASSNODE(semiring)
00114     CREATE_PARAM_CLASSNODE(monoid)
00115     CREATE_PARAM_CLASSNODE(freemonoid)
00116     CREATE_PARAM_CLASSNODE(generator)
00117     CREATE_PARAM_CLASSNODE(geometry)
00118     CREATE_PARAM_CLASSNODE(drawing)
00119 
00120 
00121 # define TParm                                  \
00122     template <class S, class T>
00123 # define TParmFMP                                       \
00124     template <class S, class T, class M1, class M2>
00125 # define AUTtype                                \
00126     Element<Automata<S>, T>
00127 # define TRANStype                              \
00128     Element<Transducer<S>, T>
00129 
00130 # define FMPtype                                                        \
00131     Element<                                                            \
00132       Automata<                                                         \
00133         vcsn::algebra::Series<S, vcsn::algebra::FreeMonoidProduct<M1, M2> > \
00134         >,                                                              \
00135       T>
00136 
00137 # define CREATE_SPEC_TYPE_NODE(TempParam, Type)                         \
00138     TempParam                                                           \
00139     struct labelTypeNode<Type > : Node<Type >                           \
00140     {                                                                   \
00141       void process(xercesc::DOMElement*, Type&,                         \
00142                    typename Node<Type >::map_t&,                        \
00143                    typename Node<Type >::factory_t&);                   \
00144       static Node<Type >* create() { return new labelTypeNode; }        \
00145     };
00146 
00147 
00148 # define CREATE_SPEC_PARAM_NODE(name, TempParam, Type)          \
00149     TempParam                                                   \
00150     struct name ## Node<Type > : Node<Type >                    \
00151     {                                                           \
00152       void process(xercesc::DOMElement*, Type&,                 \
00153                    typename Node<Type >::map_t&,                \
00154                    typename Node<Type >::factory_t&) {};        \
00155       template <class U>                                        \
00156         void process(xercesc::DOMElement*, Type&, U &,          \
00157                      typename Node<Type >::map_t&,              \
00158                      typename Node<Type >::factory_t&);         \
00159       static Node<Type >* create() { return new name ## Node; } \
00160     };
00161 
00162 
00163     CREATE_SPEC_TYPE_NODE(TParm, AUTtype)
00164     CREATE_SPEC_TYPE_NODE(TParm, TRANStype)
00165     CREATE_SPEC_TYPE_NODE(TParmFMP, FMPtype)
00166     CREATE_SPEC_PARAM_NODE(semiring, TParm, TRANStype)
00167     CREATE_SPEC_PARAM_NODE(monoid, TParmFMP, FMPtype)
00168 
00169 
00170   } // ! xml
00171 
00172 } // !vcsn
00173 
00174 
00175 // Macros used to declare the factory. It cannot be done using a
00176 // static attribute since the class is templated.
00177 # define register_in_factory(f, T, name)                        \
00178   factory_reg(f, std::string(#name), name ## Node<T>::create);
00179 
00180 # define register_all_factory(f, T)             \
00181   register_in_factory(f, T, automaton)          \
00182   register_in_factory(f, T, transducer)         \
00183   register_in_factory(f, T, labelType)          \
00184   register_in_factory(f, T, semiring)           \
00185   register_in_factory(f, T, monoid)             \
00186   register_in_factory(f, T, freemonoid)         \
00187   register_in_factory(f, T, generator)          \
00188   register_in_factory(f, T, content)            \
00189   register_in_factory(f, T, states)             \
00190   register_in_factory(f, T, transitions)        \
00191   register_in_factory(f, T, state)              \
00192   register_in_factory(f, T, transition)         \
00193   register_in_factory(f, T, initial)            \
00194   register_in_factory(f, T, final)
00195 
00196 
00197 # ifndef VCSN_USE_INTERFACE_ONLY
00198 #  include <vaucanson/xml/node.hxx>
00199 # endif // VCSN_USE_INTERFACE_ONLY
00200 
00201 #endif // ! VCSN_XML_NODE_HH

Generated on Sat Jul 29 17:13:09 2006 for Vaucanson by  doxygen 1.4.6