00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef VCSN_TOOLS_USUAL_MACROS_HH
00018 # define VCSN_TOOLS_USUAL_MACROS_HH
00019
00020 # include <fstream>
00021 # include <vaucanson/config/system.hh>
00022
00023 #define for_all_const(T, I, C) \
00024 for (T::const_iterator I = (C).begin(); I != (C).end(); ++I)
00025
00026 #define for_all(T, I, C) \
00027 for (T::iterator I = (C).begin(); I != (C).end(); ++I)
00028
00029 #define for_all_const_(T, I, C) \
00030 for (typename T::const_iterator I = (C).begin(); I != (C).end(); ++I)
00031
00032 #define for_all_(T, I, C) \
00033 for (typename T::iterator I = (C).begin(); I != (C).end(); ++I)
00034
00035
00036 #define INHERIT_TYPEDEF_(From, Type) \
00037 typedef typename From::Type Type;
00038
00039 #define AUTOMATON_TYPES_(AutoType,Prefix) \
00040 typedef AutoType Prefix##automaton_t; \
00041 typedef typename AutoType::set_t Prefix##automata_set_t; \
00042 typedef typename AutoType::states_t Prefix##states_t; \
00043 typedef typename AutoType::state_iterator Prefix##state_iterator; \
00044 typedef typename AutoType::transitions_t Prefix##transitions_t; \
00045 typedef typename AutoType::transition_iterator Prefix##transition_iterator; \
00046 typedef typename AutoType::initial_t Prefix##initial_t; \
00047 typedef typename AutoType::final_t Prefix##final_t; \
00048 typedef typename AutoType::initial_iterator Prefix##initial_iterator; \
00049 typedef typename AutoType::final_iterator Prefix##final_iterator; \
00050 typedef typename AutoType::monoid_t Prefix##monoid_t; \
00051 typedef typename AutoType::monoid_elt_t Prefix##monoid_elt_t; \
00052 typedef typename Prefix##monoid_elt_t::value_t Prefix##monoid_elt_value_t; \
00053 typedef typename AutoType::semiring_t Prefix##semiring_t; \
00054 typedef typename AutoType::series_set_t Prefix##series_set_t; \
00055 typedef typename AutoType::series_set_elt_value_t Prefix##series_set_elt_value_t; \
00056 typedef typename AutoType::series_set_elt_t Prefix##series_set_elt_t; \
00057 typedef typename Prefix##series_set_elt_t::semiring_elt_t Prefix##semiring_elt_t; \
00058 typedef typename Prefix##semiring_elt_t::value_t Prefix##semiring_elt_value_t; \
00059 typedef typename AutoType::label_t Prefix##label_t; \
00060 typedef typename AutoType::tag_t Prefix##tag_t;
00061
00062 #define AUTOMATON_TYPES_EXACT_(AutoType,Prefix) \
00063 typedef AutoType Prefix##automaton_t; \
00064 typedef AutoType::set_t Prefix##automata_set_t; \
00065 typedef AutoType::states_t Prefix##states_t; \
00066 typedef AutoType::state_iterator Prefix##state_iterator; \
00067 typedef AutoType::transitions_t Prefix##transitions_t; \
00068 typedef AutoType::transition_iterator Prefix##transition_iterator; \
00069 typedef AutoType::initial_t Prefix##initial_t; \
00070 typedef AutoType::final_t Prefix##final_t; \
00071 typedef AutoType::initial_iterator Prefix##initial_iterator; \
00072 typedef AutoType::final_iterator Prefix##final_iterator; \
00073 typedef AutoType::monoid_t Prefix##monoid_t; \
00074 typedef AutoType::monoid_elt_t Prefix##monoid_elt_t; \
00075 typedef Prefix##monoid_elt_t::value_t Prefix##monoid_elt_value_t; \
00076 typedef AutoType::semiring_t Prefix##semiring_t; \
00077 typedef AutoType::series_set_t Prefix##series_set_t; \
00078 typedef AutoType::series_set_elt_value_t Prefix##series_set_elt_value_t; \
00079 typedef AutoType::series_set_elt_t Prefix##series_set_elt_t; \
00080 typedef Prefix##series_set_elt_t::semiring_elt_t Prefix##semiring_elt_t; \
00081 typedef Prefix##semiring_elt_t::value_t Prefix##semiring_elt_value_t; \
00082 typedef AutoType::label_t Prefix##label_t; \
00083 typedef AutoType::tag_t Prefix##tag_t;
00084
00085 #define AUTOMATON_TYPES(AutoType) AUTOMATON_TYPES_(AutoType,)
00086 #define AUTOMATON_TYPES_EXACT(AutoType) AUTOMATON_TYPES_EXACT_(AutoType,)
00087
00088
00089
00090
00091
00092 #define AUTOMATON_FREEMONOID_TYPES_(Autotype, Prefix) \
00093 typedef typename Prefix##monoid_t::alphabets_elt_t Prefix##alphabets_elt_t; \
00094 typedef typename Prefix##monoid_t::alphabet_t Prefix##alphabet_t; \
00095 typedef typename Prefix##alphabet_t::const_iterator Prefix##alphabet_iterator; \
00096 typedef typename Prefix##alphabet_t::letter_t Prefix##letter_t;
00097
00098 #define AUTOMATON_FREEMONOID_TYPES_EXACT_(Autotype, Prefix) \
00099 typedef Prefix##monoid_t::alphabets_elt_t Prefix##alphabets_elt_t; \
00100 typedef Prefix##monoid_t::alphabet_t Prefix##alphabet_t; \
00101 typedef Prefix##alphabet_t::const_iterator Prefix##alphabet_iterator; \
00102 typedef Prefix##alphabet_t::letter_t Prefix##letter_t;
00103
00104
00105 #define AUTOMATON_FREEMONOID_TYPES(Autotype) \
00106 AUTOMATON_FREEMONOID_TYPES_(Autotype,)
00107 #define AUTOMATON_FREEMONOID_TYPES_EXACT(Autotype) \
00108 AUTOMATON_FREEMONOID_TYPES_EXACT_(Autotype,)
00109
00110
00111
00112 # define AUTOMATA_SET_TYPES(AutoSet) \
00113 typedef AutoSet automata_set_t; \
00114 typedef typename automata_set_t::series_set_t series_set_t; \
00115 typedef typename series_set_t::monoid_t monoid_t; \
00116 typedef typename series_set_t::semiring_t semiring_t; \
00117 typedef typename monoid_t::alphabet_t alphabet_t; \
00118 typedef typename alphabet_t::letter_t letter_t;
00119
00120
00121
00122
00123
00124 #define for_each_letter(E, A) \
00125 for (alphabet_iterator E = A.begin(); E != A.end(); ++E)
00126
00127 #define for_each_state(S, A) \
00128 for (state_iterator S = A.states().begin(); \
00129 S != A.states().end(); \
00130 ++S)
00131
00132 #define for_each_transition(E, A) \
00133 for (transition_iterator E = A.transitions().begin(); \
00134 E != A.transitions().end(); \
00135 ++E)
00136
00137 #define for_each_final_state(S, A) \
00138 for (final_iterator S = A.final().begin(); \
00139 S != A.final().end(); \
00140 ++S)
00141
00142 #define for_each_initial_state(S, A) \
00143 for (initial_iterator S = A.initial().begin(); \
00144 S != A.initial().end(); \
00145 ++S)
00146
00147 #define for_each_const_(T, S, C) \
00148 for (typename T::const_iterator S = C.begin(); \
00149 S != C.end(); \
00150 ++S)
00151
00152 #define for_each_(T, S, C) \
00153 for (typename T::iterator S = C.begin(); \
00154 S != C.end(); \
00155 ++S)
00156
00157 #define remove_in(S, V) \
00158 S.erase(std::remove(S.begin(), S.end(), V), S.end())
00159
00160 #define SAVE_AUTOMATON_DOT(Dir, Name, Auto, Index) \
00161 { \
00162 std::ostringstream s; \
00163 s << Dir << "/" << Name << "_" << Index << ".dot"; \
00164 std::ofstream f(s.str().c_str()); \
00165 vcsn::tools::dot_dump(f, Auto, Name); \
00166 }
00167
00168 #define SAVE_AUTOMATON_DOT_SIMPLE(Name, Auto) \
00169 { \
00170 std::ostringstream s; \
00171 s << Name << ".dot"; \
00172 std::ofstream f(s.str().c_str()); \
00173 vcsn::tools::dot_dump(f, Auto, Name); \
00174 }
00175
00176 #define RAND___(Max) \
00177 ((unsigned) int(((float) rand() / (float) RAND_MAX) * Max));
00178
00179
00180 #ifndef VCSN_NDEBUG
00181 # define XML_FAIL(S) \
00182 std::cerr << "Implement for " << typeid(S).name() << std::endl; \
00183 exit(1)
00184 #else
00185 # define XML_FAIL(S)
00186 #endif
00187 #define FAIL(S) { std::cerr << (S) << std::endl; exit(1); }
00188
00189 #ifdef VCSN_USE_XML
00190 # define STR2XML(S) xercesc::XMLString::transcode(S)
00191 #endif
00192
00193
00194
00195
00196
00197
00198 #define zero_ zero(SELECT(typename series_set_elt_t::value_t))
00199 #define one_ identity(SELECT(typename series_set_elt_t::value_t))
00200 #define empty_ identity(SELECT(typename monoid_elt_t::value_t))
00201 #define wzero_ zero(SELECT(typename semiring_elt_t::value_t))
00202
00203 #endif // ! VCSN_TOOLS_USUAL_MACROS_HH