Vaucanson  1.4.1
usual_macros.hh
1 // usual_macros.hh: this file is part of the Vaucanson project.
2 //
3 // Vaucanson, a generic library for finite state machines.
4 //
5 // Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 The
6 // Vaucanson Group.
7 //
8 // This program is free software; you can redistribute it and/or
9 // modify it under the terms of the GNU General Public License
10 // as published by the Free Software Foundation; either version 2
11 // of the License, or (at your option) any later version.
12 //
13 // The complete GNU General Public Licence Notice can be found as the
14 // `COPYING' file in the root directory.
15 //
16 // The Vaucanson Group consists of people listed in the `AUTHORS' file.
17 //
18 #ifndef VCSN_MISC_USUAL_MACROS_HH
19 # define VCSN_MISC_USUAL_MACROS_HH
20 
21 # include <fstream>
23 # include <boost/preprocessor/cat.hpp>
24 
26 # define IMPORT_TYPEDEF_TYPENAME(From, Qual, Type, Typename) \
27  typedef Typename From::Type Qual ## Type
28 
29 
31 # define IMPORT_QUALIFIED_TYPEDEF(From, Qual, Type) \
32  IMPORT_TYPEDEF_TYPENAME(From, Qual, Type,)
33 
35 # define IMPORT_QUALIFIED_TYPEDEF_(From, Qual, Type) \
36  IMPORT_TYPEDEF_TYPENAME(From, Qual, Type, typename)
37 
38 
40 # define IMPORT_TYPEDEF_(From, Type) \
41  IMPORT_QUALIFIED_TYPEDEF_(From, ,Type)
42 
44 # define IMPORT_TYPEDEF(From, Type) \
45  IMPORT_QUALIFIED_TYPEDEF(From, ,Type)
46 
47 
48 
49 
50 # define AUTOMATON_TYPES_MAYBE_TYPENAME(AutoType, Prefix, Typename) \
51  typedef AutoType Prefix##automaton_t; \
52  typedef Typename AutoType::set_t Prefix##automata_set_t; \
53  typedef Typename AutoType::states_t Prefix##states_t; \
54  typedef Typename AutoType::state_iterator Prefix##state_iterator; \
55  typedef Typename AutoType::transitions_t Prefix##transitions_t; \
56  typedef Typename AutoType::transition_iterator Prefix##transition_iterator; \
57  typedef Typename AutoType::initial_iterator Prefix##initial_iterator; \
58  typedef Typename AutoType::final_iterator Prefix##final_iterator; \
59  typedef Typename AutoType::monoid_t Prefix##monoid_t; \
60  typedef Typename AutoType::monoid_elt_t Prefix##monoid_elt_t; \
61  typedef Typename Prefix##monoid_elt_t::value_t Prefix##monoid_elt_value_t; \
62  typedef Typename AutoType::semiring_t Prefix##semiring_t; \
63  typedef Typename AutoType::series_set_t Prefix##series_set_t; \
64  typedef Typename AutoType::series_set_elt_value_t Prefix##series_set_elt_value_t; \
65  typedef Typename AutoType::series_set_elt_t Prefix##series_set_elt_t; \
66  typedef Typename Prefix##series_set_elt_t::semiring_elt_t Prefix##semiring_elt_t; \
67  typedef Typename Prefix##semiring_elt_t::value_t Prefix##semiring_elt_value_t; \
68  typedef Typename AutoType::kind_t Prefix##kind_t; \
69  typedef Typename AutoType::label_t Prefix##label_t; \
70  typedef Typename AutoType::tag_t Prefix##tag_t; \
71  typedef Typename AutoType::hstate_t Prefix##hstate_t; \
72  typedef Typename AutoType::htransition_t Prefix##htransition_t; \
73  typedef Typename AutoType::delta_iterator Prefix##delta_iterator; \
74  typedef Typename AutoType::rdelta_iterator Prefix##rdelta_iterator; \
75  typedef Typename AutoType::series_set_t::series_rep_t Prefix##series_rep_t; \
76  typedef Typename AutoType::monoid_t::monoid_rep_t Prefix##monoid_rep_t;
77 
78 # define AUTOMATON_TYPES_(AutoType,Prefix) \
79  AUTOMATON_TYPES_MAYBE_TYPENAME(AutoType, Prefix, typename)
80 
81 # define AUTOMATON_TYPES_EXACT_(AutoType,Prefix) \
82  AUTOMATON_TYPES_MAYBE_TYPENAME(AutoType, Prefix, )
83 
84 # define AUTOMATON_TYPES(AutoType) AUTOMATON_TYPES_(AutoType,)
85 # define AUTOMATON_TYPES_EXACT(AutoType) AUTOMATON_TYPES_EXACT_(AutoType,)
86 
87 
88 // The following macros assume you have used a macro AUTOMATON_TYPES*
89 // previously.
90 
91 # define AUTOMATON_FREEMONOID_TYPES_(Autotype, Prefix) \
92  typedef typename Prefix##monoid_t::alphabets_elt_t Prefix##alphabets_elt_t; \
93  typedef typename Prefix##monoid_t::alphabet_t Prefix##alphabet_t; \
94  typedef typename Prefix##alphabet_t::const_iterator Prefix##alphabet_iterator; \
95  typedef typename Prefix##alphabet_t::letter_t Prefix##letter_t;
96 
97 # define AUTOMATON_FREEMONOID_TYPES_EXACT_(Autotype, Prefix) \
98  typedef Prefix##monoid_t::alphabets_elt_t Prefix##alphabets_elt_t; \
99  typedef Prefix##monoid_t::alphabet_t Prefix##alphabet_t; \
100  typedef Prefix##alphabet_t::const_iterator Prefix##alphabet_iterator; \
101  typedef Prefix##alphabet_t::letter_t Prefix##letter_t;
102 
103 
104 # define AUTOMATON_FREEMONOID_TYPES(Autotype) \
105  AUTOMATON_FREEMONOID_TYPES_(Autotype,)
106 # define AUTOMATON_FREEMONOID_TYPES_EXACT(Autotype) \
107  AUTOMATON_FREEMONOID_TYPES_EXACT_(Autotype,)
108 
109 
110 
111 # define AUTOMATA_SET_TYPES(AutoSet) \
112  typedef AutoSet automata_set_t; \
113  typedef typename automata_set_t::series_set_t series_set_t; \
114  typedef typename series_set_t::monoid_t monoid_t; \
115  typedef typename series_set_t::semiring_t semiring_t; \
116  typedef typename monoid_t::alphabet_t alphabet_t; \
117  typedef typename alphabet_t::letter_t letter_t;
118 
119 
120 
121 /*------------.
122 | Iterating. |
123 `------------*/
124 
126 # define for_all_const_iterator(IteratorType, I, C) \
127  for (IteratorType I = (C).begin(), I##_end = (C).end(); I##_end != I; ++I)
128 
129 # define for_all_iterator(ConstIteratorType, I, C) \
130  for (ConstIteratorType I = (C).begin(); I != (C).end(); ++I)
131 
132 
134 # define for_all_const(T, I, C) \
135  for_all_iterator(T::const_iterator, I, C)
136 
137 # define for_all(T, I, C) \
138  for_all_iterator(T::iterator, I, C)
139 
140 
142 # define for_all_const_(T, I, C) \
143  for_all_const_iterator(typename T::const_iterator, I, C)
144 
145 # define for_all_(T, I, C) \
146  for_all_iterator(typename T::iterator, I, C)
147 
148 
149 // The following macros assume you have used a macro AUTOMATON_TYPES*
150 // previously.
151 
152 # define for_all_letters(I, A) \
153  for_all_iterator (alphabet_iterator, I, A)
154 
155 # define for_all_states(I, A) \
156  for_all_iterator (state_iterator, I, (A).states())
157 
158 # define for_all_transitions(I, A) \
159  for_all_iterator (transition_iterator, I, (A).transitions())
160 
161 # define for_all_initial_states(I, A) \
162  for_all_iterator (initial_iterator, I, (A).initial())
163 
164 # define for_all_final_states(I, A) \
165  for_all_iterator (final_iterator, I, (A).final())
166 
167 # define for_all_letters_(Prefix, I, A) \
168  for_all_iterator (Prefix##alphabet_iterator, I, A)
169 
170 # define for_all_states_(Prefix, I, A) \
171  for_all_iterator (Prefix##state_iterator, I, (A).states())
172 
173 # define for_all_transitions_(Prefix, I, A) \
174  for_all_iterator (Prefix##transition_iterator, I, (A).transitions())
175 
176 # define for_all_initial_states_(Prefix, I, A) \
177  for_all_iterator (Prefix##initial_iterator, I, (A).initial())
178 
179 # define for_all_final_states_(Prefix, I, A) \
180  for_all_iterator (Prefix##final_iterator, I, (A).final())
181 
182 
183 //Const versions of the previous macros.
184 //You should always use these macros unless you need to erase over iteration.
185 // FIXME: Currently, these do not ensure const-ness. See Trac #190.
186 # define for_all_const_letters(I, A) \
187  for_all_const_iterator (alphabet_iterator, I, A)
188 
189 # define for_all_const_states(I, A) \
190  for_all_const_iterator (state_iterator, I, (A).states())
191 
192 # define for_all_const_transitions(I, A) \
193  for_all_const_iterator (transition_iterator, I, (A).transitions())
194 
195 # define for_all_const_initial_states(I, A) \
196  for_all_const_iterator (initial_iterator, I, (A).initial())
197 
198 # define for_all_const_final_states(I, A) \
199  for_all_const_iterator (final_iterator, I, (A).final())
200 
201 # define for_all_const_letters_(Prefix, I, A) \
202  for_all_const_iterator (Prefix##alphabet_iterator, I, A)
203 
204 # define for_all_const_states_(Prefix, I, A) \
205  for_all_const_iterator (Prefix##state_iterator, I, (A).states())
206 
207 # define for_all_const_transitions_(Prefix, I, A) \
208  for_all_const_iterator (Prefix##transition_iterator, I, (A).transitions())
209 
210 # define for_all_const_initial_states_(Prefix, I, A) \
211  for_all_const_iterator (Prefix##initial_iterator, I, (A).initial())
212 
213 # define for_all_const_final_states_(Prefix, I, A) \
214  for_all_const_iterator (Prefix##final_iterator, I, (A).final())
215 
216 
217 
218 # define RAND___(Max) \
219  ((unsigned) int(((float) rand() / (float) RAND_MAX) * Max));
220 
221 # define FAIL(S) { std::cerr << (S) << std::endl; exit(1); }
222 
223 // These macros can be use instead of some method calls.
224 // This is really tricky and dirty but so useful !
225 // !! * must be well documented * !!
226 # define zero_ zero(SELECT(typename series_set_elt_t::value_t))
227 # define one_ identity(SELECT(typename series_set_elt_t::value_t))
228 # define VCSN_EMPTY_ identity(SELECT(typename monoid_elt_t::value_t))
229 # define wzero_ zero(SELECT(typename semiring_elt_t::value_t))
230 # define wone_ identity(SELECT(typename semiring_elt_t::value_t))
231 
232 
233 # define VARIANT_INCLUDE_FILE(PATH, FILE, SUFFIX) \
234  <PATH/BOOST_PP_CAT(FILE, SUFFIX)>
235 
236 # define GRAPH_IMPL_HEADER \
237  VARIANT_INCLUDE_FILE(VCSN_GRAPH_IMPL_INCLUDE_PATH,VCSN_GRAPH_IMPL,_graph_impl.hh)
238 
239 # define GRAPH_DEFAULT_IMPL_HEADER \
240  VARIANT_INCLUDE_FILE(VCSN_GRAPH_IMPL_INCLUDE_PATH,VCSN_DEFAULT_GRAPH_IMPL,_graph_impl.hh)
241 
242 # define GRAPH_CONTEXT_HEADER(Impl, Context) \
243  VARIANT_INCLUDE_FILE(VCSN_CONTEXT_INCLUDE_PATH,Impl,/Context)
244 
245 # define GRAPH_CONTEXT_HEADER_(Context) \
246  <VCSN_CONTEXT_INCLUDE_PATH/VCSN_GRAPH_IMPL/Context>
247 
248 # include <vaucanson/misc/global_bencher.hh>
249 # include <cbs/bench/bench_macros.hh>
250 
251 #endif // ! VCSN_MISC_USUAL_MACROS_HH