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