OSDN Git Service

f97609781a090745048b361bd0e7f4a2fe2a151b
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / testsuite / util / regression / trait / assoc / native_type_trait.hpp
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 native_type_trait.hpp
44  * Contains traits for a random regression test
45  *    for a specific container type.
46  */
47
48 #ifndef PB_DS_REGRESSION_TEST_NATIVE_TYPE_TRAIT_HPP
49 #define PB_DS_REGRESSION_TEST_NATIVE_TYPE_TRAIT_HPP
50
51 namespace __gnu_pbds
52 {
53
54   namespace test
55   {
56
57     namespace detail
58     {
59
60       template<typename Key, class Allocator>
61       struct native_key_type;
62
63       template<typename Allocator>
64       struct native_key_type<
65         basic_type,
66         Allocator>
67       {
68         typedef std::string type;
69
70         static type
71         native_key(typename Allocator::template rebind<
72                    basic_type>::other::const_reference r_key)
73         {
74           return (std::string(r_key));
75         }
76       };
77
78       template<typename Hd, class Tl, class Allocator>
79       struct native_key_type<
80         std::pair<
81         Hd,
82         Tl>,
83         Allocator>
84       {
85         typedef typename native_key_type< Hd, Allocator>::type hd_type;
86
87         typedef typename native_key_type< Tl, Allocator>::type tl_type;
88
89         typedef std::pair< hd_type, tl_type> type;
90
91         static type
92         native_key(typename Allocator::template rebind<            std::pair<Hd, Tl> >::other::const_reference r_key)
93         {
94           return (std::make_pair(
95                                  native_key_type<Hd, Allocator>::native_key(r_key.first),
96                                  native_key_type<Tl, Allocator>::native_key(r_key.second)));
97         }
98       };
99
100       template<typename Native_Key_Type,
101                class Key_Type,
102                class Data_Type,
103                class Allocator>
104       struct native_type_traits_base;
105
106       template<typename Native_Key_Type, class Key_Type, class Allocator>
107       struct native_type_traits_base<
108         Native_Key_Type,
109         Key_Type,
110         basic_type,
111         Allocator>
112       {
113       public:
114         typedef std::map< Native_Key_Type, std::string> type;
115
116       public:
117         static const typename type::key_type& 
118         extract_key(typename type::const_reference r_val)
119         {
120           return (r_val.first);
121         }
122
123         static typename type::value_type
124         native_value(typename Allocator::template rebind<            std::pair<Key_Type, basic_type> >::other::const_reference r_val)
125         {
126           return (std::make_pair(
127                                  native_key_type<Key_Type, Allocator>::native_key(r_val.first),
128                                  std::string(r_val.second)));
129         }
130       };
131
132       template<typename Native_Key_Type, class Key_Type, class Allocator>
133       struct native_type_traits_base<
134         Native_Key_Type,
135         Key_Type,
136         __gnu_pbds::null_mapped_type,
137         Allocator>
138       {
139       public:
140         typedef std::set< Native_Key_Type> type;
141
142       public:
143         static const typename type::key_type& 
144         extract_key(typename type::const_reference r_val)
145         {
146           return (r_val);
147         }
148
149         static typename type::value_type
150         native_value(typename Allocator::template rebind<
151                      Key_Type>::other::const_reference r_val)
152         {
153           return (native_key_type<Key_Type, Allocator>::native_key(
154                                                                    r_val));
155         }
156       };
157
158 #define PB_DS_NATIVE_KEY_TYPE_C_DEC                             \
159       native_key_type<                                          \
160                                                 Key_Type,       \
161                                                 Allocator>
162
163 #define PB_DS_BASE_C_DEC                                                \
164       native_type_traits_base<                                          \
165                                                                         typename PB_DS_NATIVE_KEY_TYPE_C_DEC::type, \
166                                                                         Key_Type, \
167                                                                         Data_Type, \
168                                                                         Allocator>
169
170       template<typename Key_Type, class Data_Type, class Allocator>
171       struct native_type_traits : public PB_DS_BASE_C_DEC
172       {
173         typedef typename PB_DS_BASE_C_DEC::type type;
174
175         typedef typename type::key_type key_type;
176
177         static typename PB_DS_NATIVE_KEY_TYPE_C_DEC::type
178         native_key(typename Allocator::template rebind<
179                    Key_Type>::other::const_reference r_key)
180         {
181           return (PB_DS_NATIVE_KEY_TYPE_C_DEC::native_key(r_key));
182         }
183       };
184
185 #undef PB_DS_BASE_C_DEC
186
187 #undef PB_DS_NATIVE_KEY_TYPE_C_DEC
188
189     } // namespace detail
190
191   } // namespace test
192
193 } // namespace __gnu_pbds
194
195 #endif // #ifndef PB_DS_REGRESSION_TEST_NATIVE_TYPE_TRAIT_HPP