]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
818ab71a | 3 | // Copyright (C) 2005-2016 Free Software Foundation, Inc. |
4569a895 AT |
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 | |
748086b7 | 8 | // Foundation; either version 3, or (at your option) any later |
4569a895 AT |
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 | |
748086b7 JJ |
17 | // along with this library; see the file COPYING3. If not see |
18 | // <http://www.gnu.org/licenses/>. | |
4569a895 | 19 | |
4569a895 AT |
20 | |
21 | // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. | |
22 | ||
23 | // Permission to use, copy, modify, sell, and distribute this software | |
24 | // is hereby granted without fee, provided that the above copyright | |
25 | // notice appears in all copies, and that both that copyright notice | |
26 | // and this permission notice appear in supporting documentation. None | |
27 | // of the above authors, nor IBM Haifa Research Laboratories, make any | |
28 | // representation about the suitability of this software for any | |
29 | // purpose. It is provided "as is" without express or implied | |
30 | // warranty. | |
31 | ||
32 | /** | |
33 | * @file native_type_trait.hpp | |
2e3f9c21 | 34 | * Contains traits for a random regression test |
4569a895 AT |
35 | * for a specific container type. |
36 | */ | |
37 | ||
38 | #ifndef PB_DS_REGRESSION_TEST_NATIVE_TYPE_TRAIT_HPP | |
39 | #define PB_DS_REGRESSION_TEST_NATIVE_TYPE_TRAIT_HPP | |
40 | ||
5e11f978 | 41 | namespace __gnu_pbds |
4569a895 AT |
42 | { |
43 | ||
44 | namespace test | |
45 | { | |
46 | ||
47 | namespace detail | |
48 | { | |
49 | ||
a345e45d | 50 | template<typename Key, typename _Alloc> |
4569a895 AT |
51 | struct native_key_type; |
52 | ||
a345e45d | 53 | template<typename _Alloc> |
4569a895 AT |
54 | struct native_key_type< |
55 | basic_type, | |
a345e45d | 56 | _Alloc> |
4569a895 AT |
57 | { |
58 | typedef std::string type; | |
59 | ||
60 | static type | |
a345e45d | 61 | native_key(typename _Alloc::template rebind< |
4569a895 AT |
62 | basic_type>::other::const_reference r_key) |
63 | { | |
64 | return (std::string(r_key)); | |
65 | } | |
66 | }; | |
67 | ||
a345e45d | 68 | template<typename Hd, class Tl, typename _Alloc> |
4569a895 AT |
69 | struct native_key_type< |
70 | std::pair< | |
71 | Hd, | |
72 | Tl>, | |
a345e45d | 73 | _Alloc> |
4569a895 | 74 | { |
a345e45d | 75 | typedef typename native_key_type< Hd, _Alloc>::type hd_type; |
4569a895 | 76 | |
a345e45d | 77 | typedef typename native_key_type< Tl, _Alloc>::type tl_type; |
4569a895 AT |
78 | |
79 | typedef std::pair< hd_type, tl_type> type; | |
80 | ||
81 | static type | |
a345e45d | 82 | native_key(typename _Alloc::template rebind< std::pair<Hd, Tl> >::other::const_reference r_key) |
4569a895 AT |
83 | { |
84 | return (std::make_pair( | |
a345e45d BK |
85 | native_key_type<Hd, _Alloc>::native_key(r_key.first), |
86 | native_key_type<Tl, _Alloc>::native_key(r_key.second))); | |
4569a895 AT |
87 | } |
88 | }; | |
89 | ||
90 | template<typename Native_Key_Type, | |
91 | class Key_Type, | |
92 | class Data_Type, | |
a345e45d | 93 | typename _Alloc> |
4569a895 AT |
94 | struct native_type_traits_base; |
95 | ||
a345e45d | 96 | template<typename Native_Key_Type, class Key_Type, typename _Alloc> |
4569a895 AT |
97 | struct native_type_traits_base< |
98 | Native_Key_Type, | |
99 | Key_Type, | |
100 | basic_type, | |
a345e45d | 101 | _Alloc> |
4569a895 AT |
102 | { |
103 | public: | |
104 | typedef std::map< Native_Key_Type, std::string> type; | |
105 | ||
106 | public: | |
f92ab29f | 107 | static const typename type::key_type& |
4569a895 AT |
108 | extract_key(typename type::const_reference r_val) |
109 | { | |
110 | return (r_val.first); | |
111 | } | |
112 | ||
113 | static typename type::value_type | |
a345e45d | 114 | native_value(typename _Alloc::template rebind< std::pair<Key_Type, basic_type> >::other::const_reference r_val) |
4569a895 AT |
115 | { |
116 | return (std::make_pair( | |
a345e45d | 117 | native_key_type<Key_Type, _Alloc>::native_key(r_val.first), |
4569a895 AT |
118 | std::string(r_val.second))); |
119 | } | |
120 | }; | |
121 | ||
a345e45d | 122 | template<typename Native_Key_Type, class Key_Type, typename _Alloc> |
4569a895 AT |
123 | struct native_type_traits_base< |
124 | Native_Key_Type, | |
125 | Key_Type, | |
a345e45d BK |
126 | __gnu_pbds::null_type, |
127 | _Alloc> | |
4569a895 AT |
128 | { |
129 | public: | |
130 | typedef std::set< Native_Key_Type> type; | |
131 | ||
132 | public: | |
f92ab29f | 133 | static const typename type::key_type& |
4569a895 AT |
134 | extract_key(typename type::const_reference r_val) |
135 | { | |
136 | return (r_val); | |
137 | } | |
138 | ||
139 | static typename type::value_type | |
a345e45d | 140 | native_value(typename _Alloc::template rebind< |
4569a895 AT |
141 | Key_Type>::other::const_reference r_val) |
142 | { | |
a345e45d | 143 | return (native_key_type<Key_Type, _Alloc>::native_key( |
4569a895 AT |
144 | r_val)); |
145 | } | |
146 | }; | |
147 | ||
148 | #define PB_DS_NATIVE_KEY_TYPE_C_DEC \ | |
149 | native_key_type< \ | |
150 | Key_Type, \ | |
a345e45d | 151 | _Alloc> |
4569a895 AT |
152 | |
153 | #define PB_DS_BASE_C_DEC \ | |
154 | native_type_traits_base< \ | |
155 | typename PB_DS_NATIVE_KEY_TYPE_C_DEC::type, \ | |
156 | Key_Type, \ | |
157 | Data_Type, \ | |
a345e45d | 158 | _Alloc> |
4569a895 | 159 | |
a345e45d | 160 | template<typename Key_Type, class Data_Type, typename _Alloc> |
4569a895 AT |
161 | struct native_type_traits : public PB_DS_BASE_C_DEC |
162 | { | |
163 | typedef typename PB_DS_BASE_C_DEC::type type; | |
164 | ||
165 | typedef typename type::key_type key_type; | |
166 | ||
167 | static typename PB_DS_NATIVE_KEY_TYPE_C_DEC::type | |
a345e45d | 168 | native_key(typename _Alloc::template rebind< |
4569a895 AT |
169 | Key_Type>::other::const_reference r_key) |
170 | { | |
171 | return (PB_DS_NATIVE_KEY_TYPE_C_DEC::native_key(r_key)); | |
172 | } | |
173 | }; | |
174 | ||
175 | #undef PB_DS_BASE_C_DEC | |
176 | ||
177 | #undef PB_DS_NATIVE_KEY_TYPE_C_DEC | |
178 | ||
179 | } // namespace detail | |
180 | ||
181 | } // namespace test | |
182 | ||
5e11f978 | 183 | } // namespace __gnu_pbds |
4569a895 AT |
184 | |
185 | #endif // #ifndef PB_DS_REGRESSION_TEST_NATIVE_TYPE_TRAIT_HPP |