]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
3 | // Copyright (C) 2005, 2006 Free Software Foundation, Inc. | |
4 | // | |
5 | // This file is part of the GNU ISO C++ Library. This library is free | |
6 | // software; you can redistribute it and/or modify it under the terms | |
7 | // of the GNU General Public License as published by the Free Software | |
8 | // Foundation; either version 2, or (at your option) any later | |
9 | // version. | |
10 | ||
11 | // This library is distributed in the hope that it will be useful, but | |
12 | // WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | // General Public License for more details. | |
15 | ||
16 | // You should have received a copy of the GNU General Public License | |
17 | // along with this library; see the file COPYING. If not, write to | |
18 | // the Free Software Foundation, 59 Temple Place - Suite 330, Boston, | |
19 | // MA 02111-1307, USA. | |
20 | ||
21 | // As a special exception, you may use this file as part of a free | |
22 | // software library without restriction. Specifically, if other files | |
23 | // instantiate templates or use macros or inline functions from this | |
24 | // file, or you compile this file and link it with other files to | |
25 | // produce an executable, this file does not by itself cause the | |
26 | // resulting executable to be covered by the GNU General Public | |
27 | // License. This exception does not however invalidate any other | |
28 | // reasons why the executable file might be covered by the GNU General | |
29 | // Public License. | |
30 | ||
31 | // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. | |
32 | ||
33 | // Permission to use, copy, modify, sell, and distribute this software | |
34 | // is hereby granted without fee, provided that the above copyright | |
35 | // notice appears in all copies, and that both that copyright notice | |
36 | // and this permission notice appear in supporting documentation. None | |
37 | // of the above authors, nor IBM Haifa Research Laboratories, make any | |
38 | // representation about the suitability of this software for any | |
39 | // purpose. It is provided "as is" without express or implied | |
40 | // warranty. | |
41 | ||
42 | /** | |
43 | * @file trait.hpp | |
44 | * Containsert traits for a random regression test | |
45 | * for a specific container type. | |
46 | */ | |
47 | ||
48 | #ifndef PB_DS_REGRESSION_TEST_TRAIT_HPP | |
49 | #define PB_DS_REGRESSION_TEST_TRAIT_HPP | |
50 | ||
51 | #include <regression/trait/assoc/to_string.hpp> | |
52 | #include <regression/trait/assoc/type_trait.hpp> | |
53 | #include <regression/trait/assoc/native_type_trait.hpp> | |
54 | #include <regression/trait/assoc/resize_trait.hpp> | |
55 | #include <regression/trait/assoc/get_set_loads_trait.hpp> | |
56 | #include <regression/trait/assoc/get_set_load_trait.hpp> | |
57 | #include <regression/trait/assoc/node_update_trait.hpp> | |
58 | #include <regression/trait/erase_if_fn.hpp> | |
59 | ||
60 | namespace pb_ds | |
61 | { | |
62 | ||
63 | namespace test | |
64 | { | |
65 | ||
66 | namespace detail | |
67 | { | |
68 | ||
69 | #define PB_DS_CLASS_T_DEC \ | |
70 | template<typename Cntnr> | |
71 | ||
72 | #define PB_DS_CLASS_C_DEC \ | |
73 | regression_test_traits< \ | |
74 | Cntnr> | |
75 | ||
76 | #define PB_DS_TYPE_TRAITS_C_DEC \ | |
77 | regression_test_type_traits< \ | |
78 | Cntnr> | |
79 | ||
80 | #define PB_DS_NATIVE_TYPE_TRAITS_C_DEC \ | |
81 | native_type_traits< \ | |
82 | typename PB_DS_TYPE_TRAITS_C_DEC::key_type, \ | |
83 | typename PB_DS_TYPE_TRAITS_C_DEC::mapped_type, \ | |
84 | typename Cntnr::allocator> | |
85 | ||
86 | #define PB_DS_RESIZE_TRAITS_C_DEC \ | |
87 | regression_test_resize_traits< \ | |
88 | Cntnr, \ | |
89 | typename Cntnr::container_category> | |
90 | ||
91 | #define PB_DS_SET_LOADS_TRAITS_C_DEC \ | |
92 | regression_test_get_set_loacontainer_traits< \ | |
93 | Cntnr, \ | |
94 | typename Cntnr::container_category> | |
95 | ||
96 | #define PB_DS_SET_LOAD_TRAITS_C_DEC \ | |
97 | regression_test_get_set_load_traits< \ | |
98 | Cntnr, \ | |
99 | typename Cntnr::container_category> | |
100 | ||
101 | #define PB_DS_NODE_UPDATOR_TRAITS_C_DEC \ | |
102 | regression_test_node_update_traits< \ | |
103 | Cntnr, \ | |
104 | typename Cntnr::container_category> | |
105 | ||
106 | template<typename Cntnr> | |
107 | struct regression_test_traits : private PB_DS_TYPE_TRAITS_C_DEC, | |
108 | private PB_DS_NATIVE_TYPE_TRAITS_C_DEC, | |
109 | private PB_DS_RESIZE_TRAITS_C_DEC, | |
110 | private PB_DS_NODE_UPDATOR_TRAITS_C_DEC, | |
111 | private PB_DS_SET_LOADS_TRAITS_C_DEC, | |
112 | private PB_DS_SET_LOAD_TRAITS_C_DEC | |
113 | { | |
114 | ||
115 | private: | |
116 | typedef PB_DS_NATIVE_TYPE_TRAITS_C_DEC native_type_traits_base; | |
117 | ||
118 | typedef PB_DS_TYPE_TRAITS_C_DEC type_traits_base; | |
119 | ||
120 | public: | |
121 | ||
122 | typedef typename Cntnr::key_type key_type; | |
123 | ||
124 | typedef typename Cntnr::const_key_reference const_key_reference; | |
125 | ||
126 | typedef typename Cntnr::value_type value_type; | |
127 | ||
128 | typedef typename Cntnr::const_reference const_reference; | |
129 | ||
130 | typedef typename PB_DS_NATIVE_TYPE_TRAITS_C_DEC::type native_type; | |
131 | ||
132 | typedef typename native_type::key_type native_key_type; | |
133 | ||
134 | typedef typename native_type::value_type native_value_type; | |
135 | ||
136 | enum | |
137 | { | |
138 | resize = PB_DS_RESIZE_TRAITS_C_DEC::value, | |
139 | get_set_loads = PB_DS_SET_LOADS_TRAITS_C_DEC::value, | |
140 | get_set_load = PB_DS_SET_LOAD_TRAITS_C_DEC::value, | |
141 | order_statistics = | |
142 | PB_DS_NODE_UPDATOR_TRAITS_C_DEC::order_statistics, | |
143 | prefix_search = | |
144 | PB_DS_NODE_UPDATOR_TRAITS_C_DEC::prefix_search | |
145 | }; | |
146 | ||
147 | template<typename T> | |
148 | struct erase_if_fn : public regression_test_erase_if_fn< | |
149 | T> | |
150 | { | |
151 | ||
152 | }; | |
153 | ||
154 | static size_t | |
155 | erase_if(native_type& r_native_c) | |
156 | { | |
157 | typedef | |
158 | regression_test_erase_if_fn< | |
159 | typename native_type::value_type> | |
160 | erase_if_fn; | |
161 | ||
162 | typename native_type::iterator it = r_native_c.begin(); | |
163 | ||
164 | size_t num_ersd = 0; | |
165 | ||
166 | while (it != r_native_c.end()) | |
167 | if (erase_if_fn()(*it)) | |
168 | { | |
169 | ++num_ersd; | |
170 | ||
171 | r_native_c.erase(it); | |
172 | ||
173 | it = r_native_c.begin(); | |
174 | } | |
175 | else | |
176 | ++it; | |
177 | ||
178 | return (num_ersd); | |
179 | } | |
180 | ||
181 | static void | |
182 | print_container(const Cntnr& r_c, std::ostream& r_os) | |
183 | { | |
184 | PB_DS_TYPE_TRAITS_C_DEC::print_container(r_c, r_os); | |
185 | } | |
186 | ||
187 | public: | |
188 | ||
189 | template<typename Gen> | |
190 | static key_type | |
191 | generate_key(Gen& r_gen, size_t max) | |
192 | { | |
193 | return (PB_DS_TYPE_TRAITS_C_DEC::generate_key(r_gen, max)); | |
194 | } | |
195 | ||
196 | template<typename Gen> | |
197 | static value_type | |
198 | generate_value(Gen& r_gen, size_t max) | |
199 | { | |
200 | return (PB_DS_TYPE_TRAITS_C_DEC::generate_value(r_gen, max)); | |
201 | } | |
202 | ||
203 | static const_key_reference | |
204 | extract_key(const_reference r_val) | |
205 | { | |
206 | return type_traits_base::extract_key(r_val); | |
207 | } | |
208 | ||
209 | static native_key_type | |
210 | native_key(const_key_reference r_key) | |
211 | { | |
212 | return (native_type_traits_base::native_key(r_key)); | |
213 | } | |
214 | ||
215 | static native_value_type | |
216 | native_value(const_reference r_val) | |
217 | { | |
218 | return (native_type_traits_base::native_value(r_val)); | |
219 | } | |
220 | ||
221 | static const native_key_type& | |
222 | extract_native_key(const native_value_type& r_val) | |
223 | { | |
224 | return (native_type_traits_base::extract_key(r_val)); | |
225 | } | |
226 | ||
227 | static bool | |
228 | cmp(const_reference r_val, const native_value_type& r_native_val) | |
229 | { | |
230 | return (val_to_string(r_val) == | |
231 | native_val_to_string(r_native_val)); | |
232 | } | |
233 | ||
234 | static std::string | |
235 | val_to_string(const_reference r_val) | |
236 | { | |
237 | return (to_string(r_val)); | |
238 | } | |
239 | ||
240 | static std::string | |
241 | key_to_string(const_key_reference r_key) | |
242 | { | |
243 | return (to_string(r_key)); | |
244 | } | |
245 | ||
246 | static std::string | |
247 | native_val_to_string(const native_value_type& r_native_val) | |
248 | { | |
249 | return (to_string(r_native_val)); | |
250 | } | |
251 | ||
252 | static bool | |
253 | prefix_match(const_key_reference r_key, const std::string& r_native_key) | |
254 | { | |
255 | const size_t native_substr_len = std::min( | |
256 | r_key.length(), | |
257 | r_native_key.length()); | |
258 | ||
259 | const std::string native_substr = | |
260 | r_native_key.substr(0, native_substr_len); | |
261 | ||
262 | return (native_substr == (const std::string& )r_key); | |
263 | } | |
264 | ||
265 | }; | |
266 | ||
267 | #undef PB_DS_TYPE_TRAITS_C_DEC | |
268 | ||
269 | #undef PB_DS_NATIVE_TYPE_TRAITS_C_DEC | |
270 | ||
271 | #undef PB_DS_RESIZE_TRAITS_C_DEC | |
272 | ||
273 | #undef PB_DS_SET_LOADS_TRAITS_C_DEC | |
274 | ||
275 | #undef PB_DS_SET_LOAD_TRAITS_C_DEC | |
276 | ||
277 | #undef PB_DS_NODE_UPDATOR_TRAITS_C_DEC | |
278 | ||
279 | #undef PB_DS_CLASS_T_DEC | |
280 | ||
281 | #undef PB_DS_CLASS_C_DEC | |
282 | ||
283 | } // namespace detail | |
284 | ||
285 | } // namespace test | |
286 | ||
287 | } // namespace pb_ds | |
288 | ||
289 | #endif // #ifndef PB_DS_REGRESSION_TEST_TRAIT_HPP |