00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
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
00060
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
00108
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
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
00149
00150
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