usual_macros.hh

00001 // usual_macros.hh: this file is part of the Vaucanson project.
00002 //
00003 // Vaucanson, a generic library for finite state machines.
00004 //
00005 // Copyright (C) 2001, 2002, 2003, 2004, 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 #ifndef VCSN_MISC_USUAL_MACROS_HH
00018 # define VCSN_MISC_USUAL_MACROS_HH
00019 
00020 # include <fstream>
00021 # include <vaucanson/config/system.hh>
00022 
00023 # define INHERIT_TYPEDEF_(From, Type)           \
00024   typedef typename From::Type Type;
00025 
00026 # define AUTOMATON_TYPES_MAYBE_TYPENAME(AutoType, Prefix, Typename)     \
00027   typedef AutoType                                              Prefix##automaton_t; \
00028   typedef Typename AutoType::set_t                              Prefix##automata_set_t; \
00029   typedef Typename AutoType::states_t                           Prefix##states_t; \
00030   typedef Typename AutoType::state_iterator                     Prefix##state_iterator; \
00031   typedef Typename AutoType::transitions_t                      Prefix##transitions_t; \
00032   typedef Typename AutoType::transition_iterator                Prefix##transition_iterator; \
00033   typedef Typename AutoType::initial_t                          Prefix##initial_t; \
00034   typedef Typename AutoType::final_t                            Prefix##final_t; \
00035   typedef Typename AutoType::initial_iterator                   Prefix##initial_iterator; \
00036   typedef Typename AutoType::final_iterator                     Prefix##final_iterator; \
00037   typedef Typename AutoType::monoid_t                           Prefix##monoid_t; \
00038   typedef Typename AutoType::monoid_elt_t                       Prefix##monoid_elt_t; \
00039   typedef Typename Prefix##monoid_elt_t::value_t                Prefix##monoid_elt_value_t; \
00040   typedef Typename AutoType::semiring_t                         Prefix##semiring_t; \
00041   typedef Typename AutoType::series_set_t                       Prefix##series_set_t; \
00042   typedef Typename AutoType::series_set_elt_value_t             Prefix##series_set_elt_value_t; \
00043   typedef Typename AutoType::series_set_elt_t                   Prefix##series_set_elt_t; \
00044   typedef Typename Prefix##series_set_elt_t::semiring_elt_t     Prefix##semiring_elt_t; \
00045   typedef Typename Prefix##semiring_elt_t::value_t              Prefix##semiring_elt_value_t; \
00046   typedef Typename AutoType::label_t                            Prefix##label_t; \
00047   typedef Typename AutoType::tag_t                              Prefix##tag_t;
00048 
00049 # define AUTOMATON_TYPES_(AutoType,Prefix)                      \
00050   AUTOMATON_TYPES_MAYBE_TYPENAME(AutoType, Prefix, typename)
00051 
00052 # define AUTOMATON_TYPES_EXACT_(AutoType,Prefix)        \
00053   AUTOMATON_TYPES_MAYBE_TYPENAME(AutoType, Prefix, )
00054 
00055 # define AUTOMATON_TYPES(AutoType)          AUTOMATON_TYPES_(AutoType,)
00056 # define AUTOMATON_TYPES_EXACT(AutoType)    AUTOMATON_TYPES_EXACT_(AutoType,)
00057 
00058 
00059 // The following macros assume you have used a macro AUTOMATON_TYPES*
00060 // previously.
00061 
00062 # define AUTOMATON_FREEMONOID_TYPES_(Autotype, Prefix)                  \
00063   typedef typename Prefix##monoid_t::alphabets_elt_t            Prefix##alphabets_elt_t; \
00064   typedef typename Prefix##monoid_t::alphabet_t                 Prefix##alphabet_t; \
00065   typedef typename Prefix##alphabet_t::const_iterator           Prefix##alphabet_iterator; \
00066   typedef typename Prefix##alphabet_t::letter_t                 Prefix##letter_t;
00067 
00068 # define AUTOMATON_FREEMONOID_TYPES_EXACT_(Autotype, Prefix)            \
00069   typedef Prefix##monoid_t::alphabets_elt_t             Prefix##alphabets_elt_t; \
00070   typedef Prefix##monoid_t::alphabet_t                  Prefix##alphabet_t; \
00071   typedef Prefix##alphabet_t::const_iterator            Prefix##alphabet_iterator; \
00072   typedef Prefix##alphabet_t::letter_t                  Prefix##letter_t;
00073 
00074 
00075 # define AUTOMATON_FREEMONOID_TYPES(Autotype)   \
00076   AUTOMATON_FREEMONOID_TYPES_(Autotype,)
00077 # define AUTOMATON_FREEMONOID_TYPES_EXACT(Autotype)     \
00078   AUTOMATON_FREEMONOID_TYPES_EXACT_(Autotype,)
00079 
00080 
00081 
00082 # define AUTOMATA_SET_TYPES(AutoSet)                            \
00083   typedef AutoSet                               automata_set_t; \
00084   typedef typename automata_set_t::series_set_t series_set_t;   \
00085   typedef typename series_set_t::monoid_t       monoid_t;       \
00086   typedef typename series_set_t::semiring_t     semiring_t;     \
00087   typedef typename monoid_t::alphabet_t         alphabet_t;     \
00088   typedef typename alphabet_t::letter_t         letter_t;
00089 
00090 
00091 # define for_all_const(T, I, C)                         \
00092   for (T::const_iterator I = (C).begin(),               \
00093          I ## _end = (C).end(); I != I ## _end; ++I)
00094 
00095 # define for_all(T, I, C)                               \
00096   for (T::iterator I = (C).begin(),                     \
00097          I ## _end = (C).end(); I != I ## _end; ++I)
00098 
00099 # define for_all_const_(T, I, C)                        \
00100   for (typename T::const_iterator I = (C).begin(),      \
00101          I ## _end = (C).end(); I != I ## _end; ++I)
00102 
00103 # define for_all_(T, I, C)                              \
00104   for (typename T::iterator I = (C).begin(),            \
00105          I ## _end = (C).end(); I != I ## _end; ++I)
00106 
00107 // The following macros assume you have used a macro AUTOMATON_TYPES*
00108 // previously.
00109 
00110 # define for_all_letters(I, A)                          \
00111   for (alphabet_iterator I = (A).begin(),               \
00112          I ## _end = (A).end(); I != I ## _end; ++I)
00113 
00114 # define for_all_states(I, A)                                   \
00115   for (state_iterator I = (A).states().begin(),                 \
00116          I ## _end = (A).states().end(); I != I ## _end; ++I)
00117 
00118 # define for_all_transitions(I, A)                                      \
00119   for (transition_iterator I = (A).transitions().begin(),               \
00120          I ## _end = (A).transitions().end(); I != I ## _end; ++I)
00121 
00122 # define for_all_final_states(I, A)                             \
00123   for (final_iterator I = (A).final().begin(),                  \
00124          I ## _end = (A).final().end(); I != I ## _end; ++I)
00125 
00126 # define for_all_initial_states(I, A)                           \
00127   for (initial_iterator I = (A).initial().begin(),              \
00128          I ## _end = (A).initial().end(); I != I ## _end; ++I)
00129 
00130 # define remove_in(S, V)                                \
00131   S.erase(std::remove(S.begin(), S.end(), V), S.end())
00132 
00133 # define RAND___(Max)                                           \
00134   ((unsigned) int(((float) rand() / (float) RAND_MAX) * Max));
00135 
00136 // Some useful macros for XML.
00137 # ifndef VCSN_NDEBUG
00138 #  define XML_FAIL(S)                                                   \
00139   do {                                                                  \
00140     std::cerr << "Implement for " << typeid(S).name() << std::endl;     \
00141     exit(1);                                                            \
00142   } while (0)
00143 # else
00144 #  define XML_FAIL(S)
00145 # endif
00146 # define FAIL(S) { std::cerr << (S) << std::endl; exit(1); }
00147 
00148 // These macros can be use instead of some method calls.
00149 // This is really tricky and dirty but so useful !
00150 // !! * must be well documented * !!
00151 # define zero_  zero(SELECT(typename series_set_elt_t::value_t))
00152 # define one_   identity(SELECT(typename series_set_elt_t::value_t))
00153 # define empty_ identity(SELECT(typename monoid_elt_t::value_t))
00154 # define wzero_ zero(SELECT(typename semiring_elt_t::value_t))
00155 
00156 #endif // ! VCSN_MISC_USUAL_MACROS_HH

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