]>
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 string_form.hpp | |
44 | * Transforms containers into string form. | |
45 | */ | |
46 | ||
47 | #ifndef PB_DS_STRING_FORM_HPP | |
48 | #define PB_DS_STRING_FORM_HPP | |
49 | ||
50 | #include <string> | |
51 | #include <sstream> | |
52 | #include <ext/pb_ds/detail/type_utils.hpp> | |
53 | #include <ext/pb_ds/tag_and_trait.hpp> | |
54 | #include <native_type/assoc/native_hash_map.hpp> | |
55 | #include <native_type/assoc/native_hash_set.hpp> | |
56 | #include <native_type/assoc/native_multimap.hpp> | |
57 | #include <native_type/assoc/native_hash_multimap.hpp> | |
58 | #include <native_type/assoc/native_set.hpp> | |
59 | #include <common_type/assoc/template_policy.hpp> | |
60 | #include <common_type/assoc/detail/ds_string_form.hpp> | |
61 | #include <regression/basic_type.hpp> | |
62 | #include <io/xml.hpp> | |
63 | ||
64 | namespace pb_ds | |
65 | { | |
66 | ||
67 | namespace test | |
68 | { | |
69 | ||
70 | namespace detail | |
71 | { | |
72 | ||
73 | template<typename Cntnr> | |
74 | struct pb_ds_string_form | |
75 | { | |
76 | private: | |
77 | typedef typename Cntnr::mapped_type mapped_type; | |
78 | ||
79 | struct mapped_string_form | |
80 | { | |
81 | private: | |
82 | template<typename D_Cntnr> | |
83 | static std::string | |
84 | name(pb_ds::detail::type_to_type<D_Cntnr>) | |
85 | { | |
86 | return ("mmap_" + pb_ds_string_form<D_Cntnr>::name()); | |
87 | } | |
88 | ||
89 | template<typename D_Cntnr> | |
90 | static std::string | |
91 | desc(pb_ds::detail::type_to_type<D_Cntnr>) | |
92 | { | |
93 | return (pb_ds_string_form<D_Cntnr>::desc()); | |
94 | } | |
95 | ||
96 | static std::string | |
97 | name(pb_ds::detail::type_to_type<size_t>) | |
98 | { | |
99 | return ("map"); | |
100 | } | |
101 | ||
102 | static std::string | |
103 | desc(pb_ds::detail::type_to_type<size_t>) | |
104 | { | |
105 | return (""); | |
106 | } | |
107 | ||
108 | static std::string | |
109 | name(pb_ds::detail::type_to_type<basic_type>) | |
110 | { | |
111 | return ("map"); | |
112 | } | |
113 | ||
114 | static std::string | |
115 | desc(pb_ds::detail::type_to_type<basic_type>) | |
116 | { | |
117 | return (""); | |
118 | } | |
119 | ||
120 | static std::string | |
121 | name(pb_ds::detail::type_to_type<int>) | |
122 | { | |
123 | return ("map"); | |
124 | } | |
125 | ||
126 | static std::string | |
127 | desc(pb_ds::detail::type_to_type<int>) | |
128 | { | |
129 | return (""); | |
130 | } | |
131 | ||
132 | static std::string | |
133 | name(pb_ds::detail::type_to_type<char>) | |
134 | { | |
135 | return ("map"); | |
136 | } | |
137 | ||
138 | static std::string | |
139 | desc(pb_ds::detail::type_to_type<char>) | |
140 | { | |
141 | return (""); | |
142 | } | |
143 | ||
144 | static std::string | |
145 | name(pb_ds::detail::type_to_type<pb_ds::null_mapped_type>) | |
146 | { | |
147 | return ("set"); | |
148 | } | |
149 | ||
150 | static std::string | |
151 | desc(pb_ds::detail::type_to_type<pb_ds::null_mapped_type>) | |
152 | { | |
153 | return (""); | |
154 | } | |
155 | ||
156 | public: | |
157 | static std::string | |
158 | name() | |
159 | { | |
160 | return (name(pb_ds::detail::type_to_type<mapped_type>())); | |
161 | } | |
162 | ||
163 | static std::string | |
164 | desc() | |
165 | { | |
166 | return (desc(pb_ds::detail::type_to_type<mapped_type>())); | |
167 | } | |
168 | }; | |
169 | ||
170 | typedef | |
171 | detail::ds_string_form< | |
172 | Cntnr, | |
173 | typename Cntnr::container_category> | |
174 | ds_string_form_t; | |
175 | ||
176 | public: | |
177 | static std::string | |
178 | name() | |
179 | { | |
180 | return (ds_string_form_t::name() + mapped_string_form::name()); | |
181 | } | |
182 | ||
183 | static std::string | |
184 | desc() | |
185 | { | |
186 | return (ds_string_form_t::desc() + mapped_string_form::desc()); | |
187 | } | |
188 | }; | |
189 | ||
190 | template<typename Cntnr> | |
191 | struct native_string_form | |
192 | { | |
193 | static std::string | |
194 | name() | |
195 | { | |
196 | return (Cntnr::name()); | |
197 | } | |
198 | ||
199 | static std::string | |
200 | desc() | |
201 | { | |
202 | return (Cntnr::desc()); | |
203 | } | |
204 | }; | |
205 | ||
206 | template<typename Cntnr, class Tag> | |
207 | struct tag_select_string_form : public pb_ds_string_form< | |
208 | Cntnr> | |
209 | { }; | |
210 | ||
211 | template<typename Cntnr> | |
212 | struct tag_select_string_form< | |
213 | Cntnr, | |
214 | native_hash_tag> : public native_string_form< | |
215 | Cntnr> | |
216 | { }; | |
217 | ||
218 | template<typename Cntnr> | |
219 | struct tag_select_string_form< | |
220 | Cntnr, | |
221 | native_tree_tag> : public native_string_form< | |
222 | Cntnr> | |
223 | { }; | |
224 | ||
225 | } // namespace detail | |
226 | ||
227 | template<typename Cntnr> | |
228 | struct string_form : public detail::tag_select_string_form< | |
229 | Cntnr, | |
230 | typename Cntnr::container_category> | |
231 | { }; | |
232 | ||
233 | } // namespace test | |
234 | ||
235 | } // namespace pb_ds | |
236 | ||
237 | #endif // #ifndef PB_DS_STRING_FORM_HPP | |
238 |