OpenCores
URL https://opencores.org/ocsvn/scarts/scarts/trunk

Subversion Repositories scarts

[/] [scarts/] [trunk/] [toolchain/] [scarts-gcc/] [gcc-4.1.1/] [libstdc++-v3/] [testsuite/] [ext/] [pb_assoc/] [example/] [ds_traits.cc] - Blame information for rev 19

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jlechner
// -*- C++ -*-
2
 
3
// Copyright (C) 2005 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
7
// terms of the GNU General Public License as published by the
8
// Free Software Foundation; either version 2, or (at your option)
9
// any later version.
10
 
11
// This library is distributed in the hope that it will be useful,
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
// GNU General Public License for more details.
15
 
16
// You should have received a copy of the GNU General Public License along
17
// with this library; see the file COPYING.  If not, write to the Free
18
// Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
19
// USA.
20
 
21
// As a special exception, you may use this file as part of a free software
22
// library without restriction.  Specifically, if other files instantiate
23
// templates or use macros or inline functions from this file, or you compile
24
// this file and link it with other files to produce an executable, this
25
// file does not by itself cause the resulting executable to be covered by
26
// the GNU General Public License.  This exception does not however
27
// invalidate any other reasons why the executable file might be covered by
28
// the GNU General Public License.
29
 
30
// Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
31
 
32
// Permission to use, copy, modify, sell, and distribute this software
33
// is hereby granted without fee, provided that the above copyright
34
// notice appears in all copies, and that both that copyright notice and
35
// this permission notice appear in supporting documentation. None of
36
// the above authors, nor IBM Haifa Research Laboratories, make any
37
// representation about the suitability of this software for any
38
// purpose. It is provided "as is" without express or implied warranty.
39
 
40
/**
41
 * @file ds_traits_example.cpp
42
 * A basic example showing how to use ds_traits for querying container types
43
 *      for their behavior.
44
 */
45
 
46
// For various associative containers.
47
#include <ext/pb_assoc/assoc_cntnr.hpp>
48
// For ds_traits.
49
#include <ext/pb_assoc/ds_trait.hpp>
50
// For cout, endl.
51
#include <iostream>
52
 
53
template<class DS_Category>
54
void
55
print_ds_category(DS_Category);
56
 
57
template<>
58
void
59
print_ds_category(pb_assoc::cc_hash_ds_tag)
60
{
61
  std::cout << "Collision-chaining hash based associative-container:" <<
62
    std::endl;
63
}
64
 
65
template<>
66
void
67
print_ds_category(pb_assoc::gp_hash_ds_tag)
68
{
69
  std::cout << "Probing hash based associative-container:" <<
70
    std::endl;
71
}
72
 
73
template<>
74
void
75
print_ds_category(pb_assoc::rb_tree_ds_tag)
76
{
77
  std::cout << "Red-black tree associative-container:" <<
78
    std::endl;
79
}
80
 
81
template<>
82
void
83
print_ds_category(pb_assoc::splay_tree_ds_tag)
84
{
85
  std::cout << "Splay tree associative-container:" <<
86
    std::endl;
87
}
88
 
89
template<>
90
void
91
print_ds_category(pb_assoc::ov_tree_ds_tag)
92
{
93
  std::cout << "Ordered-vector tree associative-container:" <<
94
    std::endl;
95
}
96
 
97
template<>
98
void
99
print_ds_category(pb_assoc::lu_ds_tag)
100
{
101
  std::cout << "List-based associative-container:" <<
102
    std::endl;
103
}
104
 
105
void
106
print_erase_can_throw(bool can)
107
{
108
  if (can)
109
    {
110
      std::cout << "Erase can throw" << std::endl;
111
 
112
      return;
113
    }
114
 
115
  std::cout << "Erase cannot throw" << std::endl;
116
}
117
 
118
void
119
print_order_preserving(bool does)
120
{
121
  if (does)
122
    {
123
      std::cout << "Preserves order" << std::endl;
124
 
125
      return;
126
    }
127
 
128
  std::cout << "Does not preserve order" << std::endl;
129
}
130
 
131
void
132
print_erase_iterators(bool can)
133
{
134
  if (can)
135
    {
136
      std::cout << "Can erase iterators" << std::endl;
137
 
138
      return;
139
    }
140
 
141
  std::cout << "Cannot erase iterators" << std::endl;
142
}
143
 
144
template<class Invalidation_Guarantee>
145
void
146
print_invalidation_guarantee(Invalidation_Guarantee);
147
 
148
template<>
149
void
150
print_invalidation_guarantee(pb_assoc::basic_invalidation_guarantee)
151
{
152
  std::cout << "Guarantees only that found references, pointers, and "
153
    "iterators are valid as long as the container object is not "
154
    "modified" << std::endl;
155
}
156
 
157
template<>
158
void
159
print_invalidation_guarantee(pb_assoc::find_invalidation_guarantee)
160
{
161
  std::cout << "Guarantees that found references, pointers, and "
162
    "find_iterators are valid even if the container object "
163
    "is modified" << std::endl;
164
}
165
 
166
template<>
167
void
168
print_invalidation_guarantee(pb_assoc::range_invalidation_guarantee)
169
{
170
  std::cout << "Guarantees that iterators remain valid even if the "
171
    "container object is modified" << std::endl;
172
}
173
 
174
void
175
print_reverse_iteration(bool does)
176
{
177
  if (does)
178
    {
179
      std::cout << "Supports reverse iteration" << std::endl;
180
 
181
      return;
182
    }
183
 
184
  std::cout << "Does not support reverse iteration" << std::endl;
185
}
186
 
187
void
188
print_split_join(bool does)
189
{
190
  if (does)
191
    {
192
      std::cout << "Supports split and join" << std::endl;
193
 
194
      return;
195
    }
196
 
197
  std::cout << "Does not support split and join" << std::endl;
198
}
199
 
200
template<class Cntnr>
201
void
202
print_container_attributes()
203
{
204
  // First print out the data-structure category.
205
 
206
  print_ds_category(typename Cntnr::ds_category());
207
 
208
  // Next is the data-structure traits class of the container.
209
 
210
  typedef pb_assoc::ds_traits< Cntnr> traits;
211
 
212
  // Now print the attributes of the container.
213
 
214
  print_erase_can_throw(traits::erase_can_throw);
215
 
216
  print_order_preserving(traits::order_preserving);
217
 
218
  print_erase_iterators(traits::erase_iterators);
219
 
220
  print_invalidation_guarantee(typename traits::invalidation_guarantee());
221
 
222
  print_reverse_iteration(traits::reverse_iteration);
223
 
224
  print_split_join(traits::split_join);
225
 
226
  std::cout << std::endl << std::endl;
227
}
228
 
229
int
230
main()
231
{
232
  print_container_attributes<pb_assoc::cc_hash_assoc_cntnr<int, char> >();
233
 
234
  print_container_attributes<pb_assoc::gp_hash_assoc_cntnr<int, char> >();
235
 
236
  print_container_attributes<pb_assoc::tree_assoc_cntnr<int, char> >();
237
 
238
  print_container_attributes<pb_assoc::tree_assoc_cntnr<
239
    int,
240
    char,
241
    std::less<int>,
242
    pb_assoc::splay_tree_ds_tag> >();
243
 
244
  print_container_attributes<pb_assoc::tree_assoc_cntnr<
245
    int,
246
    char,
247
    std::less<int>,
248
    pb_assoc::ov_tree_ds_tag> >();
249
 
250
  print_container_attributes<pb_assoc::lu_assoc_cntnr<int, char> >();
251
 
252
  typedef
253
    pb_assoc::lu_assoc_cntnr<
254
    int,
255
    pb_assoc::compound_data_type<
256
    pb_assoc::gp_hash_assoc_cntnr<
257
    char,
258
    pb_assoc::null_data_type> > >
259
    mmap_t;
260
 
261
  print_container_attributes<mmap_t>();
262
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.