2 // typelist for the C++ library testsuite.
4 // Copyright (C) 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the
8 // terms of the GNU General Public License as published by the
9 // Free Software Foundation; either version 2, or (at your option)
12 // This library is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License along
18 // with this library; see the file COPYING. If not, write to the Free
19 // Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 // As a special exception, you may use this file as part of a free software
23 // library without restriction. Specifically, if other files instantiate
24 // templates or use macros or inline functions from this file, or you compile
25 // this file and link it with other files to produce an executable, this
26 // file does not by itself cause the resulting executable to be covered by
27 // the GNU General Public License. This exception does not however
28 // invalidate any other reasons why the executable file might be covered by
29 // the GNU General Public License.
31 #ifndef _TESTSUITE_COMMON_TYPES_H
32 #define _TESTSUITE_COMMON_TYPES_H 1
34 #include <testsuite_visualization.h>
35 #include <ext/typelist.h>
37 #include <ext/new_allocator.h>
38 #include <ext/malloc_allocator.h>
39 #include <ext/mt_allocator.h>
40 #include <ext/bitmap_allocator.h>
41 #include <ext/pool_allocator.h>
52 #include <tr1/functional>
53 #include <tr1/unordered_map>
54 #include <tr1/unordered_set>
58 using __gnu_cxx::typelist::node
;
59 using __gnu_cxx::typelist::transform
;
60 using __gnu_cxx::typelist::append
;
62 // All the allocators to test.
63 template<typename Tp
, bool Thread
>
64 struct allocator_policies
66 typedef Tp value_type
;
67 typedef __gnu_cxx::new_allocator
<Tp
> a1
;
68 typedef __gnu_cxx::malloc_allocator
<Tp
> a2
;
69 typedef __gnu_cxx::__common_pool_policy
<__gnu_cxx::__pool
, Thread
> pool_policy
;
70 typedef __gnu_cxx::__mt_alloc
<Tp
, pool_policy
> a3
;
71 typedef __gnu_cxx::bitmap_allocator
<Tp
> a4
;
72 typedef __gnu_cxx::__pool_alloc
<Tp
> a5
;
73 typedef node
<_GLIBCXX_TYPELIST_CHAIN5(a1
, a2
, a3
, a4
, a5
)> type
;
76 // Typelists for vector, string, list, deque.
77 // XXX should just use template templates
78 template<typename Tp
, bool Thread
>
81 typedef Tp value_type
;
86 typedef Tl allocator_type
;
87 typedef std::vector
<value_type
, allocator_type
> type
;
90 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
91 typedef typename
allocator_types::type allocator_typelist
;
92 typedef typename transform
<allocator_typelist
, vector_shell
>::type type
;
95 template<typename Tp
, bool Thread
>
98 typedef Tp value_type
;
100 template<typename Tl
>
103 typedef Tl allocator_type
;
104 typedef std::list
<value_type
, allocator_type
> type
;
107 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
108 typedef typename
allocator_types::type allocator_typelist
;
109 typedef typename transform
<allocator_typelist
, list_shell
>::type type
;
112 template<typename Tp
, bool Thread
>
115 typedef Tp value_type
;
117 template<typename Tl
>
120 typedef Tl allocator_type
;
121 typedef std::deque
<value_type
, allocator_type
> type
;
124 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
125 typedef typename
allocator_types::type allocator_typelist
;
126 typedef typename transform
<allocator_typelist
, deque_shell
>::type type
;
129 template<typename Tp
, bool Thread
>
132 typedef Tp value_type
;
134 template<typename Tl
>
137 typedef Tl allocator_type
;
138 typedef std::char_traits
<value_type
> traits_type
;
139 typedef std::basic_string
<value_type
, traits_type
, allocator_type
> type
;
142 typedef allocator_policies
<value_type
, Thread
> allocator_types
;
143 typedef typename
allocator_types::type allocator_typelist
;
144 typedef typename transform
<allocator_typelist
, string_shell
>::type type
;
147 // A typelist of vector, list, deque, and string all instantiated
148 // with each of the allocator policies.
149 template<typename Tp
, bool Thread
>
150 struct sequence_containers
152 typedef Tp value_type
;
154 typedef typename vectors
<value_type
, Thread
>::type vector_typelist
;
155 typedef typename lists
<value_type
, Thread
>::type list_typelist
;
156 typedef typename deques
<value_type
, Thread
>::type deque_typelist
;
157 typedef typename strings
<value_type
, Thread
>::type string_typelist
;
159 typedef typename append
<vector_typelist
, list_typelist
>::type a1
;
160 typedef typename append
<deque_typelist
, string_typelist
>::type a2
;
161 typedef typename append
<a1
, a2
>::type type
;
164 // Typelists for map, set, unordered_set, unordered_map.
165 template<typename Tp
, bool Thread
>
168 typedef Tp value_type
;
170 typedef std::pair
<const key_type
, value_type
> pair_type
;
171 typedef std::less
<key_type
> compare_function
;
173 template<typename Tl
>
176 typedef Tl allocator_type
;
177 typedef std::map
<key_type
, value_type
, compare_function
, allocator_type
> type
;
180 typedef allocator_policies
<pair_type
, Thread
> allocator_types
;
181 typedef typename
allocator_types::type allocator_typelist
;
182 typedef typename transform
<allocator_typelist
, container
>::type type
;
185 template<typename Tp
, bool Thread
>
186 struct unordered_maps
188 typedef Tp value_type
;
190 typedef std::pair
<const key_type
, value_type
> pair_type
;
191 typedef std::tr1::hash
<key_type
> hash_function
;
192 typedef std::equal_to
<key_type
> equality_function
;
194 template<typename Tl
>
197 typedef Tl allocator_type
;
198 typedef std::tr1::unordered_map
<key_type
, value_type
, hash_function
, equality_function
, allocator_type
> type
;
201 typedef allocator_policies
<pair_type
, Thread
> allocator_types
;
202 typedef typename
allocator_types::type allocator_typelist
;
203 typedef typename transform
<allocator_typelist
, container
>::type type
;
206 template<typename Tp
, bool Thread
>
209 typedef Tp value_type
;
211 typedef std::less
<key_type
> compare_function
;
213 template<typename Tl
>
216 typedef Tl allocator_type
;
217 typedef std::set
<key_type
, compare_function
, allocator_type
> type
;
220 typedef allocator_policies
<key_type
, Thread
> allocator_types
;
221 typedef typename
allocator_types::type allocator_typelist
;
222 typedef typename transform
<allocator_typelist
, container
>::type type
;
225 template<typename Tp
, bool Thread
>
226 struct unordered_sets
228 typedef Tp value_type
;
230 typedef std::tr1::hash
<key_type
> hash_function
;
231 typedef std::equal_to
<key_type
> equality_function
;
233 template<typename Tl
>
236 typedef Tl allocator_type
;
237 typedef std::tr1::unordered_set
<key_type
, hash_function
, equality_function
, allocator_type
> type
;
240 typedef allocator_policies
<key_type
, Thread
> allocator_types
;
241 typedef typename
allocator_types::type allocator_typelist
;
242 typedef typename transform
<allocator_typelist
, container
>::type type
;
246 // A typelist of all associated container types, with each of the
247 // allocator policies.
248 template<typename Tp
, bool Thread
>
249 struct associative_containers
251 typedef Tp value_type
;
253 typedef typename maps
<value_type
, Thread
>::type map_typelist
;
254 typedef typename sets
<value_type
, Thread
>::type set_typelist
;
255 typedef typename unordered_maps
<value_type
, Thread
>::type unordered_map_typelist
;
256 typedef typename unordered_sets
<value_type
, Thread
>::type unordered_set_typelist
;
258 typedef typename append
<map_typelist
, unordered_map_typelist
>::type a1
;
259 typedef typename append
<set_typelist
, unordered_set_typelist
>::type a2
;
260 typedef typename append
<a1
, a2
>::type type
;
263 } // namespace __gnu_test
266 // Function template, function objects for the tests.
267 template<typename TestType
>
268 struct value_type
: public std::pair
<const TestType
, TestType
>
270 inline value_type
& operator++()
276 inline operator TestType() const { return this->second
; }
279 template<typename Container
, int Iter
>
283 template<typename Container
, int Iter
>
285 do_thread(void* p
= NULL
)
287 do_loop
<Container
, Iter
>();
291 template<typename Container
, int Iter
, bool Thread
>
293 test_container(const char* filename
)
295 using namespace __gnu_test
;
297 resource_counter resource
;
299 start_counters(time
, resource
);
302 // No threads, so run 4x.
303 do_loop
<Container
, Iter
* 4>();
307 #if defined (_GLIBCXX_GCC_GTHR_POSIX_H) && !defined (NOTHREAD)
308 pthread_t t1
, t2
, t3
, t4
;
309 pthread_create(&t1
, 0, &do_thread
<Container
, Iter
>, 0);
310 pthread_create(&t2
, 0, &do_thread
<Container
, Iter
>, 0);
311 pthread_create(&t3
, 0, &do_thread
<Container
, Iter
>, 0);
312 pthread_create(&t4
, 0, &do_thread
<Container
, Iter
>, 0);
314 pthread_join(t1
, NULL
);
315 pthread_join(t2
, NULL
);
316 pthread_join(t3
, NULL
);
317 pthread_join(t4
, NULL
);
320 stop_counters(time
, resource
);
322 // Detailed text data.
325 std::ostringstream comment
;
326 comment
<< "type: " << abi::__cxa_demangle(typeid(obj
).name(),
328 report_header(filename
, comment
.str());
329 report_performance("", "", time
, resource
);
331 // Detailed data for visualization.
332 std::string
vizfilename(filename
);
333 vizfilename
+= ".dat";
334 write_viz_data(time
, vizfilename
.c_str());
338 template<bool Thread
>
341 test_sequence(const char* filename
) : _M_filename(filename
) { }
343 template<class Container
>
345 operator()(Container
)
348 test_container
<Container
, i
, Thread
>(_M_filename
);
352 const char* _M_filename
;
356 inline std::string::size_type
357 sequence_find_container(std::string
& type
)
359 const std::string::size_type npos
= std::string::npos
;
360 std::string::size_type n1
= type
.find("vector");
361 std::string::size_type n2
= type
.find("list");
362 std::string::size_type n3
= type
.find("deque");
363 std::string::size_type n4
= type
.find("string");
365 if (n1
!= npos
|| n2
!= npos
|| n3
!= npos
|| n4
!= npos
)
366 return std::min(std::min(n1
, n2
), std::min(n3
, n4
));
368 throw std::runtime_error("sequence_find_container not found");
371 inline std::string::size_type
372 associative_find_container(std::string
& type
)
375 string::size_type n1
= type
.find("map");
376 string::size_type n2
= type
.find("set");
377 if (n1
!= string::npos
|| n2
!= string::npos
)
378 return std::min(n1
, n2
);
380 throw std::runtime_error("associative_find_container not found");