STXXL  1.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
choose.h
Go to the documentation of this file.
1 /***************************************************************************
2  * include/stxxl/bits/stream/choose.h
3  *
4  * Part of the STXXL. See http://stxxl.sourceforge.net
5  *
6  * Copyright (C) 2003-2005 Roman Dementiev <[email protected]>
7  * Copyright (C) 2010 Andreas Beckmann <[email protected]>
8  *
9  * Distributed under the Boost Software License, Version 1.0.
10  * (See accompanying file LICENSE_1_0.txt or copy at
11  * http://www.boost.org/LICENSE_1_0.txt)
12  **************************************************************************/
13 
14 #ifndef STXXL_STREAM_CHOOSE_HEADER
15 #define STXXL_STREAM_CHOOSE_HEADER
16 
17 #include <stxxl/bits/namespace.h>
18 
19 
21 
22 //! Stream package subnamespace.
23 namespace stream {
24 
25 ////////////////////////////////////////////////////////////////////////
26 // CHOOSE //
27 ////////////////////////////////////////////////////////////////////////
28 
29 template <class Input_, int Which>
30 class choose
31 { };
32 
33 //! Creates stream from a tuple stream taking the first component of each tuple.
34 //!
35 //! \tparam Input_ type of the input tuple stream
36 //!
37 //! \remark Tuple stream is a stream which \c value_type is \c stxxl::tuple .
38 template <class Input_>
39 class choose<Input_, 1>
40 {
41  Input_& in;
42 
43  typedef typename Input_::value_type tuple_type;
44 
45 public:
46  //! Standard stream typedef.
47  typedef typename tuple_type::first_type value_type;
48 
49  //! Construction.
50  choose(Input_& in_) : in(in_)
51  { }
52 
53  //! Standard stream method.
54  const value_type& operator * () const
55  {
56  return (*in).first;
57  }
58 
59  const value_type* operator -> () const
60  {
61  return &(*in).first;
62  }
63 
64  //! Standard stream method.
66  {
67  ++in;
68  return *this;
69  }
70 
71  //! Standard stream method.
72  bool empty() const
73  {
74  return in.empty();
75  }
76 };
77 
78 //! Creates stream from a tuple stream taking the second component of each tuple.
79 //!
80 //! \tparam Input_ type of the input tuple stream
81 //!
82 //! \remark Tuple stream is a stream which \c value_type is \c stxxl::tuple .
83 template <class Input_>
84 class choose<Input_, 2>
85 {
86  Input_& in;
87 
88  typedef typename Input_::value_type tuple_type;
89 
90 public:
91  //! Standard stream typedef.
92  typedef typename tuple_type::second_type value_type;
93 
94  //! Construction.
95  choose(Input_& in_) : in(in_)
96  { }
97 
98  //! Standard stream method.
99  const value_type& operator * () const
100  {
101  return (*in).second;
102  }
103 
104  const value_type* operator -> () const
105  {
106  return &(*in).second;
107  }
108 
109  //! Standard stream method.
111  {
112  ++in;
113  return *this;
114  }
115 
116  //! Standard stream method.
117  bool empty() const
118  {
119  return in.empty();
120  }
121 };
122 
123 //! Creates stream from a tuple stream taking the third component of each tuple.
124 //!
125 //! \tparam Input_ type of the input tuple stream
126 //!
127 //! \remark Tuple stream is a stream which \c value_type is \c stxxl::tuple .
128 template <class Input_>
129 class choose<Input_, 3>
130 {
131  Input_& in;
132 
133  typedef typename Input_::value_type tuple_type;
134 
135 public:
136  //! Standard stream typedef.
137  typedef typename tuple_type::third_type value_type;
138 
139  //! Construction.
140  choose(Input_& in_) : in(in_)
141  { }
142 
143  //! Standard stream method.
144  const value_type& operator * () const
145  {
146  return (*in).third;
147  }
148 
149  const value_type* operator -> () const
150  {
151  return &(*in).third;
152  }
153 
154  //! Standard stream method.
156  {
157  ++in;
158  return *this;
159  }
160 
161  //! Standard stream method.
162  bool empty() const
163  {
164  return in.empty();
165  }
166 };
167 
168 //! Creates stream from a tuple stream taking the fourth component of each tuple.
169 //!
170 //! \tparam Input_ type of the input tuple stream
171 //!
172 //! \remark Tuple stream is a stream which \c value_type is \c stxxl::tuple .
173 template <class Input_>
174 class choose<Input_, 4>
175 {
176  Input_& in;
177 
178  typedef typename Input_::value_type tuple_type;
179 
180 public:
181  //! Standard stream typedef.
182  typedef typename tuple_type::fourth_type value_type;
183 
184  //! Construction.
185  choose(Input_& in_) : in(in_)
186  { }
187 
188  //! Standard stream method.
189  const value_type& operator * () const
190  {
191  return (*in).fourth;
192  }
193 
194  const value_type* operator -> () const
195  {
196  return &(*in).fourth;
197  }
198 
199  //! Standard stream method.
201  {
202  ++in;
203  return *this;
204  }
205 
206  //! Standard stream method.
207  bool empty() const
208  {
209  return in.empty();
210  }
211 };
212 
213 //! Creates stream from a tuple stream taking the fifth component of each tuple.
214 //!
215 //! \tparam Input_ type of the input tuple stream
216 //!
217 //! \remark Tuple stream is a stream which \c value_type is \c stxxl::tuple .
218 template <class Input_>
219 class choose<Input_, 5>
220 {
221  Input_& in;
222 
223  typedef typename Input_::value_type tuple_type;
224 
225 public:
226  //! Standard stream typedef.
227  typedef typename tuple_type::fifth_type value_type;
228 
229  //! Construction.
230  choose(Input_& in_) : in(in_)
231  { }
232 
233  //! Standard stream method.
234  const value_type& operator * () const
235  {
236  return (*in).fifth;
237  }
238 
239  const value_type* operator -> () const
240  {
241  return &(*in).fifth;
242  }
243 
244  //! Standard stream method.
246  {
247  ++in;
248  return *this;
249  }
250 
251  //! Standard stream method.
252  bool empty() const
253  {
254  return in.empty();
255  }
256 };
257 
258 //! Creates stream from a tuple stream taking the sixth component of each tuple.
259 //!
260 //! \tparam Input_ type of the input tuple stream
261 //!
262 //! \remark Tuple stream is a stream which \c value_type is \c stxxl::tuple .
263 template <class Input_>
264 class choose<Input_, 6>
265 {
266  Input_& in;
267 
268  typedef typename Input_::value_type tuple_type;
269 
270 public:
271  //! Standard stream typedef.
272  typedef typename tuple_type::sixth_type value_type;
273 
274  //! Construction.
275  choose(Input_& in_) : in(in_)
276  { }
277 
278  //! Standard stream method.
279  const value_type& operator * () const
280  {
281  return (*in).sixth;
282  }
283 
284  const value_type* operator -> () const
285  {
286  return &(*in).sixth;
287  }
288 
289  //! Standard stream method.
291  {
292  ++in;
293  return *this;
294  }
295 
296  //! Standard stream method.
297  bool empty() const
298  {
299  return in.empty();
300  }
301 };
302 
303 //! \}
304 
305 } // namespace stream
306 
308 
309 
311 
312 
313 #endif // !STXXL_STREAM_CHOOSE_HEADER
314 // vim: et:ts=4:sw=4
tuple_type::first_type value_type
Standard stream typedef.
Definition: choose.h:47
bool empty() const
Standard stream method.
Definition: choose.h:162
bool empty() const
Standard stream method.
Definition: choose.h:297
tuple_type::fifth_type value_type
Standard stream typedef.
Definition: choose.h:227
Input_::value_type tuple_type
Definition: choose.h:133
tuple_type::third_type value_type
Standard stream typedef.
Definition: choose.h:137
choose(Input_ &in_)
Construction.
Definition: choose.h:95
Input_::value_type tuple_type
Definition: choose.h:43
choose(Input_ &in_)
Construction.
Definition: choose.h:50
uint_pair & operator++()
prefix increment operator (directly manipulates the integer parts)
Definition: uint_types.h:166
choose(Input_ &in_)
Construction.
Definition: choose.h:185
bool empty() const
Standard stream method.
Definition: choose.h:72
Input_::value_type tuple_type
Definition: choose.h:88
choose(Input_ &in_)
Construction.
Definition: choose.h:230
#define STXXL_BEGIN_NAMESPACE
Definition: namespace.h:16
tuple_type::sixth_type value_type
Standard stream typedef.
Definition: choose.h:272
bool empty() const
Standard stream method.
Definition: choose.h:117
Input_::value_type tuple_type
Definition: choose.h:223
bool empty() const
Standard stream method.
Definition: choose.h:252
tuple_type::second_type value_type
Standard stream typedef.
Definition: choose.h:92
choose(Input_ &in_)
Construction.
Definition: choose.h:140
tuple_type::fourth_type value_type
Standard stream typedef.
Definition: choose.h:182
bool empty() const
Standard stream method.
Definition: choose.h:207
Input_::value_type tuple_type
Definition: choose.h:268
Input_::value_type tuple_type
Definition: choose.h:178
choose(Input_ &in_)
Construction.
Definition: choose.h:275
#define STXXL_END_NAMESPACE
Definition: namespace.h:17