Vaucanson 1.4
|
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, 2008 The 00006 // Vaucanson Group. 00007 // 00008 // This program is free software; you can redistribute it and/or 00009 // modify it under the terms of the GNU General Public License 00010 // as published by the Free Software Foundation; either version 2 00011 // of the License, or (at your option) any later version. 00012 // 00013 // The complete GNU General Public Licence Notice can be found as the 00014 // `COPYING' file in the root directory. 00015 // 00016 // The Vaucanson Group consists of people listed in the `AUTHORS' file. 00017 // 00018 #ifndef VCSN_MISC_USUAL_MACROS_HH 00019 # define VCSN_MISC_USUAL_MACROS_HH 00020 00021 # include <fstream> 00022 # include <vaucanson/config/system.hh> 00023 # include <boost/preprocessor/cat.hpp> 00024 00026 # define IMPORT_TYPEDEF_TYPENAME(From, Qual, Type, Typename) \ 00027 typedef Typename From::Type Qual ## Type 00028 00029 00031 # define IMPORT_QUALIFIED_TYPEDEF(From, Qual, Type) \ 00032 IMPORT_TYPEDEF_TYPENAME(From, Qual, Type,) 00033 00035 # define IMPORT_QUALIFIED_TYPEDEF_(From, Qual, Type) \ 00036 IMPORT_TYPEDEF_TYPENAME(From, Qual, Type, typename) 00037 00038 00040 # define IMPORT_TYPEDEF_(From, Type) \ 00041 IMPORT_QUALIFIED_TYPEDEF_(From, ,Type) 00042 00044 # define IMPORT_TYPEDEF(From, Type) \ 00045 IMPORT_QUALIFIED_TYPEDEF(From, ,Type) 00046 00047 00048 00049 00050 # define AUTOMATON_TYPES_MAYBE_TYPENAME(AutoType, Prefix, Typename) \ 00051 typedef AutoType Prefix##automaton_t; \ 00052 typedef Typename AutoType::set_t Prefix##automata_set_t; \ 00053 typedef Typename AutoType::states_t Prefix##states_t; \ 00054 typedef Typename AutoType::state_iterator Prefix##state_iterator; \ 00055 typedef Typename AutoType::transitions_t Prefix##transitions_t; \ 00056 typedef Typename AutoType::transition_iterator Prefix##transition_iterator; \ 00057 typedef Typename AutoType::initial_iterator Prefix##initial_iterator; \ 00058 typedef Typename AutoType::final_iterator Prefix##final_iterator; \ 00059 typedef Typename AutoType::monoid_t Prefix##monoid_t; \ 00060 typedef Typename AutoType::monoid_elt_t Prefix##monoid_elt_t; \ 00061 typedef Typename Prefix##monoid_elt_t::value_t Prefix##monoid_elt_value_t; \ 00062 typedef Typename AutoType::semiring_t Prefix##semiring_t; \ 00063 typedef Typename AutoType::series_set_t Prefix##series_set_t; \ 00064 typedef Typename AutoType::series_set_elt_value_t Prefix##series_set_elt_value_t; \ 00065 typedef Typename AutoType::series_set_elt_t Prefix##series_set_elt_t; \ 00066 typedef Typename Prefix##series_set_elt_t::semiring_elt_t Prefix##semiring_elt_t; \ 00067 typedef Typename Prefix##semiring_elt_t::value_t Prefix##semiring_elt_value_t; \ 00068 typedef Typename AutoType::kind_t Prefix##kind_t; \ 00069 typedef Typename AutoType::label_t Prefix##label_t; \ 00070 typedef Typename AutoType::tag_t Prefix##tag_t; \ 00071 typedef Typename AutoType::hstate_t Prefix##hstate_t; \ 00072 typedef Typename AutoType::htransition_t Prefix##htransition_t; \ 00073 typedef Typename AutoType::delta_iterator Prefix##delta_iterator; \ 00074 typedef Typename AutoType::rdelta_iterator Prefix##rdelta_iterator; \ 00075 typedef Typename AutoType::series_set_t::series_rep_t Prefix##series_rep_t; \ 00076 typedef Typename AutoType::monoid_t::monoid_rep_t Prefix##monoid_rep_t; 00077 00078 # define AUTOMATON_TYPES_(AutoType,Prefix) \ 00079 AUTOMATON_TYPES_MAYBE_TYPENAME(AutoType, Prefix, typename) 00080 00081 # define AUTOMATON_TYPES_EXACT_(AutoType,Prefix) \ 00082 AUTOMATON_TYPES_MAYBE_TYPENAME(AutoType, Prefix, ) 00083 00084 # define AUTOMATON_TYPES(AutoType) AUTOMATON_TYPES_(AutoType,) 00085 # define AUTOMATON_TYPES_EXACT(AutoType) AUTOMATON_TYPES_EXACT_(AutoType,) 00086 00087 00088 // The following macros assume you have used a macro AUTOMATON_TYPES* 00089 // previously. 00090 00091 # define AUTOMATON_FREEMONOID_TYPES_(Autotype, Prefix) \ 00092 typedef typename Prefix##monoid_t::alphabets_elt_t Prefix##alphabets_elt_t; \ 00093 typedef typename Prefix##monoid_t::alphabet_t Prefix##alphabet_t; \ 00094 typedef typename Prefix##alphabet_t::const_iterator Prefix##alphabet_iterator; \ 00095 typedef typename Prefix##alphabet_t::letter_t Prefix##letter_t; 00096 00097 # define AUTOMATON_FREEMONOID_TYPES_EXACT_(Autotype, Prefix) \ 00098 typedef Prefix##monoid_t::alphabets_elt_t Prefix##alphabets_elt_t; \ 00099 typedef Prefix##monoid_t::alphabet_t Prefix##alphabet_t; \ 00100 typedef Prefix##alphabet_t::const_iterator Prefix##alphabet_iterator; \ 00101 typedef Prefix##alphabet_t::letter_t Prefix##letter_t; 00102 00103 00104 # define AUTOMATON_FREEMONOID_TYPES(Autotype) \ 00105 AUTOMATON_FREEMONOID_TYPES_(Autotype,) 00106 # define AUTOMATON_FREEMONOID_TYPES_EXACT(Autotype) \ 00107 AUTOMATON_FREEMONOID_TYPES_EXACT_(Autotype,) 00108 00109 00110 00111 # define AUTOMATA_SET_TYPES(AutoSet) \ 00112 typedef AutoSet automata_set_t; \ 00113 typedef typename automata_set_t::series_set_t series_set_t; \ 00114 typedef typename series_set_t::monoid_t monoid_t; \ 00115 typedef typename series_set_t::semiring_t semiring_t; \ 00116 typedef typename monoid_t::alphabet_t alphabet_t; \ 00117 typedef typename alphabet_t::letter_t letter_t; 00118 00119 00120 00121 /*------------. 00122 | Iterating. | 00123 `------------*/ 00124 00126 # define for_all_const_iterator(IteratorType, I, C) \ 00127 for (IteratorType I = (C).begin(), I##_end = (C).end(); I##_end != I; ++I) 00128 00129 # define for_all_iterator(ConstIteratorType, I, C) \ 00130 for (ConstIteratorType I = (C).begin(); I != (C).end(); ++I) 00131 00132 00134 # define for_all_const(T, I, C) \ 00135 for_all_iterator(T::const_iterator, I, C) 00136 00137 # define for_all(T, I, C) \ 00138 for_all_iterator(T::iterator, I, C) 00139 00140 00142 # define for_all_const_(T, I, C) \ 00143 for_all_const_iterator(typename T::const_iterator, I, C) 00144 00145 # define for_all_(T, I, C) \ 00146 for_all_iterator(typename T::iterator, I, C) 00147 00148 00149 // The following macros assume you have used a macro AUTOMATON_TYPES* 00150 // previously. 00151 00152 # define for_all_letters(I, A) \ 00153 for_all_iterator (alphabet_iterator, I, A) 00154 00155 # define for_all_states(I, A) \ 00156 for_all_iterator (state_iterator, I, (A).states()) 00157 00158 # define for_all_transitions(I, A) \ 00159 for_all_iterator (transition_iterator, I, (A).transitions()) 00160 00161 # define for_all_initial_states(I, A) \ 00162 for_all_iterator (initial_iterator, I, (A).initial()) 00163 00164 # define for_all_final_states(I, A) \ 00165 for_all_iterator (final_iterator, I, (A).final()) 00166 00167 # define for_all_letters_(Prefix, I, A) \ 00168 for_all_iterator (Prefix##alphabet_iterator, I, A) 00169 00170 # define for_all_states_(Prefix, I, A) \ 00171 for_all_iterator (Prefix##state_iterator, I, (A).states()) 00172 00173 # define for_all_transitions_(Prefix, I, A) \ 00174 for_all_iterator (Prefix##transition_iterator, I, (A).transitions()) 00175 00176 # define for_all_initial_states_(Prefix, I, A) \ 00177 for_all_iterator (Prefix##initial_iterator, I, (A).initial()) 00178 00179 # define for_all_final_states_(Prefix, I, A) \ 00180 for_all_iterator (Prefix##final_iterator, I, (A).final()) 00181 00182 00183 //Const versions of the previous macros. 00184 //You should always use these macros unless you need to erase over iteration. 00185 // FIXME: Currently, these do not ensure const-ness. See Trac #190. 00186 # define for_all_const_letters(I, A) \ 00187 for_all_const_iterator (alphabet_iterator, I, A) 00188 00189 # define for_all_const_states(I, A) \ 00190 for_all_const_iterator (state_iterator, I, (A).states()) 00191 00192 # define for_all_const_transitions(I, A) \ 00193 for_all_const_iterator (transition_iterator, I, (A).transitions()) 00194 00195 # define for_all_const_initial_states(I, A) \ 00196 for_all_const_iterator (initial_iterator, I, (A).initial()) 00197 00198 # define for_all_const_final_states(I, A) \ 00199 for_all_const_iterator (final_iterator, I, (A).final()) 00200 00201 # define for_all_const_letters_(Prefix, I, A) \ 00202 for_all_const_iterator (Prefix##alphabet_iterator, I, A) 00203 00204 # define for_all_const_states_(Prefix, I, A) \ 00205 for_all_const_iterator (Prefix##state_iterator, I, (A).states()) 00206 00207 # define for_all_const_transitions_(Prefix, I, A) \ 00208 for_all_const_iterator (Prefix##transition_iterator, I, (A).transitions()) 00209 00210 # define for_all_const_initial_states_(Prefix, I, A) \ 00211 for_all_const_iterator (Prefix##initial_iterator, I, (A).initial()) 00212 00213 # define for_all_const_final_states_(Prefix, I, A) \ 00214 for_all_const_iterator (Prefix##final_iterator, I, (A).final()) 00215 00216 00217 00218 # define RAND___(Max) \ 00219 ((unsigned) int(((float) rand() / (float) RAND_MAX) * Max)); 00220 00221 # define FAIL(S) { std::cerr << (S) << std::endl; exit(1); } 00222 00223 // These macros can be use instead of some method calls. 00224 // This is really tricky and dirty but so useful ! 00225 // !! * must be well documented * !! 00226 # define zero_ zero(SELECT(typename series_set_elt_t::value_t)) 00227 # define one_ identity(SELECT(typename series_set_elt_t::value_t)) 00228 # define VCSN_EMPTY_ identity(SELECT(typename monoid_elt_t::value_t)) 00229 # define wzero_ zero(SELECT(typename semiring_elt_t::value_t)) 00230 # define wone_ identity(SELECT(typename semiring_elt_t::value_t)) 00231 00232 00233 # define VARIANT_INCLUDE_FILE(PATH, FILE, SUFFIX) \ 00234 <PATH/BOOST_PP_CAT(FILE, SUFFIX)> 00235 00236 # define GRAPH_IMPL_HEADER \ 00237 VARIANT_INCLUDE_FILE(VCSN_GRAPH_IMPL_INCLUDE_PATH,VCSN_GRAPH_IMPL,_graph_impl.hh) 00238 00239 # define GRAPH_DEFAULT_IMPL_HEADER \ 00240 VARIANT_INCLUDE_FILE(VCSN_GRAPH_IMPL_INCLUDE_PATH,VCSN_DEFAULT_GRAPH_IMPL,_graph_impl.hh) 00241 00242 # define GRAPH_CONTEXT_HEADER(Impl, Context) \ 00243 VARIANT_INCLUDE_FILE(VCSN_CONTEXT_INCLUDE_PATH,Impl,/Context) 00244 00245 # define GRAPH_CONTEXT_HEADER_(Context) \ 00246 <VCSN_CONTEXT_INCLUDE_PATH/VCSN_GRAPH_IMPL/Context> 00247 00248 # include <vaucanson/misc/global_bencher.hh> 00249 # include <cbs/bench/bench_macros.hh> 00250 00251 #endif // ! VCSN_MISC_USUAL_MACROS_HH