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, 2007 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 
00024 # define IMPORT_TYPEDEF_TYPENAME(From, Qual, Type, Typename) \
00025   typedef Typename From::Type Qual ## Type
00026 
00027 
00029 # define IMPORT_QUALIFIED_TYPEDEF(From, Qual, Type)             \
00030   IMPORT_TYPEDEF_TYPENAME(From, Qual, Type,)
00031 
00033 # define IMPORT_QUALIFIED_TYPEDEF_(From, Qual, Type)                    \
00034   IMPORT_TYPEDEF_TYPENAME(From, Qual, Type, typename)
00035 
00036 
00038 # define IMPORT_TYPEDEF_(From, Type)            \
00039   IMPORT_QUALIFIED_TYPEDEF_(From, ,Type)
00040 
00042 # define IMPORT_TYPEDEF(From, Type)             \
00043   IMPORT_QUALIFIED_TYPEDEF(From, ,Type)
00044 
00045 
00046 
00047 
00048 # define AUTOMATON_TYPES_MAYBE_TYPENAME(AutoType, Prefix, Typename)     \
00049   typedef AutoType                                              Prefix##automaton_t; \
00050   typedef Typename AutoType::set_t                              Prefix##automata_set_t; \
00051   typedef Typename AutoType::states_t                           Prefix##states_t; \
00052   typedef Typename AutoType::state_iterator                     Prefix##state_iterator; \
00053   typedef Typename AutoType::transitions_t                      Prefix##transitions_t; \
00054   typedef Typename AutoType::transition_iterator                Prefix##transition_iterator; \
00055   typedef Typename AutoType::initial_iterator                   Prefix##initial_iterator; \
00056   typedef Typename AutoType::final_iterator                     Prefix##final_iterator; \
00057   typedef Typename AutoType::monoid_t                           Prefix##monoid_t; \
00058   typedef Typename AutoType::monoid_elt_t                       Prefix##monoid_elt_t; \
00059   typedef Typename Prefix##monoid_elt_t::value_t                Prefix##monoid_elt_value_t; \
00060   typedef Typename AutoType::semiring_t                         Prefix##semiring_t; \
00061   typedef Typename AutoType::series_set_t                       Prefix##series_set_t; \
00062   typedef Typename AutoType::series_set_elt_value_t             Prefix##series_set_elt_value_t; \
00063   typedef Typename AutoType::series_set_elt_t                   Prefix##series_set_elt_t; \
00064   typedef Typename Prefix##series_set_elt_t::semiring_elt_t     Prefix##semiring_elt_t; \
00065   typedef Typename Prefix##semiring_elt_t::value_t              Prefix##semiring_elt_value_t; \
00066   typedef Typename AutoType::label_t                            Prefix##label_t; \
00067   typedef Typename AutoType::tag_t                              Prefix##tag_t;
00068 
00069 # define AUTOMATON_TYPES_(AutoType,Prefix)                      \
00070   AUTOMATON_TYPES_MAYBE_TYPENAME(AutoType, Prefix, typename)
00071 
00072 # define AUTOMATON_TYPES_EXACT_(AutoType,Prefix)        \
00073   AUTOMATON_TYPES_MAYBE_TYPENAME(AutoType, Prefix, )
00074 
00075 # define AUTOMATON_TYPES(AutoType)          AUTOMATON_TYPES_(AutoType,)
00076 # define AUTOMATON_TYPES_EXACT(AutoType)    AUTOMATON_TYPES_EXACT_(AutoType,)
00077 
00078 
00079 // The following macros assume you have used a macro AUTOMATON_TYPES*
00080 // previously.
00081 
00082 # define AUTOMATON_FREEMONOID_TYPES_(Autotype, Prefix)                  \
00083   typedef typename Prefix##monoid_t::alphabets_elt_t            Prefix##alphabets_elt_t; \
00084   typedef typename Prefix##monoid_t::alphabet_t                 Prefix##alphabet_t; \
00085   typedef typename Prefix##alphabet_t::const_iterator           Prefix##alphabet_iterator; \
00086   typedef typename Prefix##alphabet_t::letter_t                 Prefix##letter_t;
00087 
00088 # define AUTOMATON_FREEMONOID_TYPES_EXACT_(Autotype, Prefix)            \
00089   typedef Prefix##monoid_t::alphabets_elt_t             Prefix##alphabets_elt_t; \
00090   typedef Prefix##monoid_t::alphabet_t                  Prefix##alphabet_t; \
00091   typedef Prefix##alphabet_t::const_iterator            Prefix##alphabet_iterator; \
00092   typedef Prefix##alphabet_t::letter_t                  Prefix##letter_t;
00093 
00094 
00095 # define AUTOMATON_FREEMONOID_TYPES(Autotype)   \
00096   AUTOMATON_FREEMONOID_TYPES_(Autotype,)
00097 # define AUTOMATON_FREEMONOID_TYPES_EXACT(Autotype)     \
00098   AUTOMATON_FREEMONOID_TYPES_EXACT_(Autotype,)
00099 
00100 
00101 
00102 # define AUTOMATA_SET_TYPES(AutoSet)                            \
00103   typedef AutoSet                               automata_set_t; \
00104   typedef typename automata_set_t::series_set_t series_set_t;   \
00105   typedef typename series_set_t::monoid_t       monoid_t;       \
00106   typedef typename series_set_t::semiring_t     semiring_t;     \
00107   typedef typename monoid_t::alphabet_t         alphabet_t;     \
00108   typedef typename alphabet_t::letter_t         letter_t;
00109 
00110 
00111 
00112 /*------------.
00113 | Iterating.  |
00114 `------------*/
00115 
00117 # define for_all_iterator(IteratorType, I, C)           \
00118   for (IteratorType I = (C).begin(), I ## _end = (C).end(); I != I ## _end; ++I)
00119 
00120 
00122 # define for_all_const(T, I, C)                         \
00123   for_all_iterator(T::const_iterator, I, C)
00124 
00125 # define for_all(T, I, C)                               \
00126   for_all_iterator(T::iterator, I, C)
00127 
00128 
00130 # define for_all_const_(T, I, C)                        \
00131   for_all_iterator(typename T::const_iterator, I, C)
00132 
00133 # define for_all_(T, I, C)                              \
00134   for_all_iterator(typename T::iterator, I, C)
00135 
00136 
00137 // The following macros assume you have used a macro AUTOMATON_TYPES*
00138 // previously.
00139 
00140 # define for_all_letters(I, A)                  \
00141   for_all_iterator (alphabet_iterator, I, A)
00142 
00143 # define for_all_states(I, A)                   \
00144   for_all_iterator (state_iterator, I, (A).states())
00145 
00146 # define for_all_transitions(I, A)                      \
00147   for_all_iterator (transition_iterator, I, (A).transitions())
00148 
00149 # define for_all_initial_states(I, A)                   \
00150   for_all_iterator (initial_iterator, I, (A).initial())
00151 
00152 # define for_all_final_states(I, A)                     \
00153   for_all_iterator (final_iterator, I, (A).final())
00154 
00155 
00156 
00157 
00158 # define remove_in(S, V)                                \
00159   S.erase(std::remove(S.begin(), S.end(), V), S.end())
00160 
00161 # define RAND___(Max)                                           \
00162   ((unsigned) int(((float) rand() / (float) RAND_MAX) * Max));
00163 
00164 // Some useful macros for XML.
00165 # ifndef VCSN_NDEBUG
00166 #  define XML_FAIL(S)                                                   \
00167   do {                                                                  \
00168     std::cerr << "Implement for " << typeid(S).name() << std::endl;     \
00169     exit(1);                                                            \
00170   } while (0)
00171 # else
00172 #  define XML_FAIL(S)
00173 # endif
00174 # define FAIL(S) { std::cerr << (S) << std::endl; exit(1); }
00175 
00176 // These macros can be use instead of some method calls.
00177 // This is really tricky and dirty but so useful !
00178 // !! * must be well documented * !!
00179 # define zero_  zero(SELECT(typename series_set_elt_t::value_t))
00180 # define one_   identity(SELECT(typename series_set_elt_t::value_t))
00181 # define vcsn_empty     identity(SELECT(typename monoid_elt_t::value_t))
00182 # define wzero_ zero(SELECT(typename semiring_elt_t::value_t))
00183 # define wone_  identity(SELECT(typename semiring_elt_t::value_t))
00184 
00185 # include <vaucanson/misc/global_timer.hh>
00186 
00187 #endif // ! VCSN_MISC_USUAL_MACROS_HH

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