]>
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 | ||
5e11f978 | 60 | namespace __gnu_pbds |
4569a895 | 61 | { |
55a4c999 BK |
62 | namespace test |
63 | { | |
64 | namespace detail | |
65 | { | |
4569a895 | 66 | |
55a4c999 BK |
67 | #define PB_DS_CLASS_T_DEC \ |
68 | template<typename Cntnr> | |
4569a895 | 69 | |
55a4c999 BK |
70 | #define PB_DS_CLASS_C_DEC \ |
71 | regression_test_traits<Cntnr> | |
4569a895 | 72 | |
55a4c999 BK |
73 | #define PB_DS_TYPE_TRAITS_C_DEC \ |
74 | regression_test_type_traits<Cntnr> | |
4569a895 | 75 | |
55a4c999 BK |
76 | #define PB_DS_NATIVE_TYPE_TRAITS_C_DEC \ |
77 | native_type_traits<typename PB_DS_TYPE_TRAITS_C_DEC::key_type, \ | |
78 | typename PB_DS_TYPE_TRAITS_C_DEC::mapped_type, \ | |
79 | typename Cntnr::allocator> | |
4569a895 | 80 | |
55a4c999 BK |
81 | #define PB_DS_RESIZE_TRAITS_C_DEC \ |
82 | regression_test_resize_traits<Cntnr, typename Cntnr::container_category> | |
4569a895 | 83 | |
55a4c999 BK |
84 | #define PB_DS_SET_LOADS_TRAITS_C_DEC \ |
85 | regression_test_get_set_loacontainer_traits<Cntnr, \ | |
86 | typename Cntnr::container_category> | |
4569a895 | 87 | |
55a4c999 BK |
88 | #define PB_DS_SET_LOAD_TRAITS_C_DEC \ |
89 | regression_test_get_set_load_traits<Cntnr,typename Cntnr::container_category> | |
4569a895 | 90 | |
55a4c999 BK |
91 | #define PB_DS_NODE_UPDATOR_TRAITS_C_DEC \ |
92 | regression_test_node_update_traits<Cntnr, typename Cntnr::container_category> | |
4569a895 | 93 | |
55a4c999 BK |
94 | template<typename Cntnr> |
95 | struct regression_test_traits : private PB_DS_TYPE_TRAITS_C_DEC, | |
96 | private PB_DS_NATIVE_TYPE_TRAITS_C_DEC, | |
97 | private PB_DS_RESIZE_TRAITS_C_DEC, | |
98 | private PB_DS_NODE_UPDATOR_TRAITS_C_DEC, | |
99 | private PB_DS_SET_LOADS_TRAITS_C_DEC, | |
100 | private PB_DS_SET_LOAD_TRAITS_C_DEC | |
101 | { | |
102 | private: | |
103 | typedef PB_DS_NATIVE_TYPE_TRAITS_C_DEC native_type_traits_base; | |
55a4c999 | 104 | typedef PB_DS_TYPE_TRAITS_C_DEC type_traits_base; |
4569a895 | 105 | |
55a4c999 BK |
106 | public: |
107 | typedef typename Cntnr::key_type key_type; | |
55a4c999 | 108 | typedef typename Cntnr::const_key_reference const_key_reference; |
55a4c999 | 109 | typedef typename Cntnr::value_type value_type; |
55a4c999 | 110 | typedef typename Cntnr::const_reference const_reference; |
55a4c999 | 111 | typedef typename PB_DS_NATIVE_TYPE_TRAITS_C_DEC::type native_type; |
55a4c999 | 112 | typedef typename native_type::key_type native_key_type; |
55a4c999 BK |
113 | typedef typename native_type::value_type native_value_type; |
114 | ||
115 | enum | |
116 | { | |
117 | resize = PB_DS_RESIZE_TRAITS_C_DEC::value, | |
118 | get_set_loads = PB_DS_SET_LOADS_TRAITS_C_DEC::value, | |
119 | get_set_load = PB_DS_SET_LOAD_TRAITS_C_DEC::value, | |
120 | order_statistics = PB_DS_NODE_UPDATOR_TRAITS_C_DEC::order_statistics, | |
121 | prefix_search = PB_DS_NODE_UPDATOR_TRAITS_C_DEC::prefix_search | |
4569a895 AT |
122 | }; |
123 | ||
55a4c999 BK |
124 | template<typename T> |
125 | struct erase_if_fn : public regression_test_erase_if_fn<T> | |
126 | { }; | |
4569a895 | 127 | |
55a4c999 BK |
128 | static size_t |
129 | erase_if(native_type& r_native_c) | |
130 | { | |
131 | typedef regression_test_erase_if_fn<typename native_type::value_type> erase_if_fn; | |
4569a895 | 132 | |
55a4c999 BK |
133 | typename native_type::iterator it = r_native_c.begin(); |
134 | size_t num_ersd = 0; | |
135 | while (it != r_native_c.end()) | |
136 | if (erase_if_fn()(*it)) | |
137 | { | |
138 | ++num_ersd; | |
139 | r_native_c.erase(it); | |
140 | it = r_native_c.begin(); | |
141 | } | |
142 | else | |
143 | ++it; | |
144 | return num_ersd; | |
145 | } | |
146 | ||
147 | static void | |
148 | print_container(const Cntnr& r_c, std::ostream& r_os) | |
382a1351 | 149 | { PB_DS_TYPE_TRAITS_C_DEC::print_container(r_c, r_os); } |
4569a895 | 150 | |
55a4c999 BK |
151 | template<typename Gen> |
152 | static key_type | |
153 | generate_key(Gen& r_gen, size_t max) | |
382a1351 | 154 | { return PB_DS_TYPE_TRAITS_C_DEC::generate_key(r_gen, max); } |
4569a895 | 155 | |
55a4c999 BK |
156 | template<typename Gen> |
157 | static value_type | |
158 | generate_value(Gen& r_gen, size_t max) | |
382a1351 | 159 | { return PB_DS_TYPE_TRAITS_C_DEC::generate_value(r_gen, max); } |
4569a895 | 160 | |
55a4c999 BK |
161 | static const_key_reference |
162 | extract_key(const_reference r_val) | |
382a1351 | 163 | { return type_traits_base::extract_key(r_val); } |
4569a895 | 164 | |
55a4c999 BK |
165 | static native_key_type |
166 | native_key(const_key_reference r_key) | |
382a1351 | 167 | { return native_type_traits_base::native_key(r_key); } |
55a4c999 BK |
168 | |
169 | static native_value_type | |
170 | native_value(const_reference r_val) | |
382a1351 | 171 | { return native_type_traits_base::native_value(r_val); } |
4569a895 | 172 | |
55a4c999 BK |
173 | static const native_key_type& |
174 | extract_native_key(const native_value_type& r_val) | |
382a1351 | 175 | { return native_type_traits_base::extract_key(r_val); } |
4569a895 | 176 | |
55a4c999 BK |
177 | static bool |
178 | cmp(const_reference r_val, const native_value_type& r_native_val) | |
382a1351 | 179 | { return val_to_string(r_val) == native_val_to_string(r_native_val); } |
55a4c999 BK |
180 | |
181 | static std::string | |
182 | val_to_string(const_reference r_val) | |
382a1351 | 183 | { return to_string(r_val); } |
55a4c999 BK |
184 | |
185 | static std::string | |
186 | key_to_string(const_key_reference r_key) | |
382a1351 | 187 | { return to_string(r_key); } |
55a4c999 BK |
188 | |
189 | static std::string | |
190 | native_val_to_string(const native_value_type& r_native_val) | |
382a1351 | 191 | { return to_string(r_native_val); } |
55a4c999 BK |
192 | |
193 | static bool | |
194 | prefix_match(const_key_reference r_key, const std::string& r_native_key) | |
195 | { | |
196 | const size_t native_substr_len = std::min(r_key.length(), | |
197 | r_native_key.length()); | |
198 | ||
199 | const std::string native_substr = r_native_key.substr(0, | |
200 | native_substr_len); | |
201 | ||
202 | return native_substr == (const std::string&) r_key; | |
203 | } | |
55a4c999 BK |
204 | }; |
205 | ||
206 | #undef PB_DS_TYPE_TRAITS_C_DEC | |
207 | #undef PB_DS_NATIVE_TYPE_TRAITS_C_DEC | |
208 | #undef PB_DS_RESIZE_TRAITS_C_DEC | |
209 | #undef PB_DS_SET_LOADS_TRAITS_C_DEC | |
210 | #undef PB_DS_SET_LOAD_TRAITS_C_DEC | |
211 | #undef PB_DS_NODE_UPDATOR_TRAITS_C_DEC | |
212 | #undef PB_DS_CLASS_T_DEC | |
213 | #undef PB_DS_CLASS_C_DEC | |
4569a895 | 214 | |
55a4c999 BK |
215 | } // namespace detail |
216 | } // namespace test | |
5e11f978 | 217 | } // namespace __gnu_pbds |
4569a895 | 218 | |
55a4c999 | 219 | #endif |