Stxxl  1.3.2
choose.h
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_H_
15 #define STXXL_STREAM__CHOOSE_H_
16 
17 #include <stxxl/bits/namespace.h>
18 
19 
20 __STXXL_BEGIN_NAMESPACE
21 
23 namespace stream
24 {
26  // CHOOSE //
28 
29  template <class Input_, int Which>
30  class choose
31  { };
32 
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:
47  typedef typename tuple_type::first_type value_type;
48 
50  choose(Input_ & in_) : in(in_)
51  { }
52 
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 
65  choose & operator ++ ()
66  {
67  ++in;
68  return *this;
69  }
70 
72  bool empty() const
73  {
74  return in.empty();
75  }
76  };
77 
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:
92  typedef typename tuple_type::second_type value_type;
93 
95  choose(Input_ & in_) : in(in_)
96  { }
97 
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 
110  choose & operator ++ ()
111  {
112  ++in;
113  return *this;
114  }
115 
117  bool empty() const
118  {
119  return in.empty();
120  }
121  };
122 
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:
137  typedef typename tuple_type::third_type value_type;
138 
140  choose(Input_ & in_) : in(in_)
141  { }
142 
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 
155  choose & operator ++ ()
156  {
157  ++in;
158  return *this;
159  }
160 
162  bool empty() const
163  {
164  return in.empty();
165  }
166  };
167 
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:
182  typedef typename tuple_type::fourth_type value_type;
183 
185  choose(Input_ & in_) : in(in_)
186  { }
187 
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 
200  choose & operator ++ ()
201  {
202  ++in;
203  return *this;
204  }
205 
207  bool empty() const
208  {
209  return in.empty();
210  }
211  };
212 
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:
227  typedef typename tuple_type::fifth_type value_type;
228 
230  choose(Input_ & in_) : in(in_)
231  { }
232 
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 
245  choose & operator ++ ()
246  {
247  ++in;
248  return *this;
249  }
250 
252  bool empty() const
253  {
254  return in.empty();
255  }
256  };
257 
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:
272  typedef typename tuple_type::sixth_type value_type;
273 
275  choose(Input_ & in_) : in(in_)
276  { }
277 
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 
290  choose & operator ++ ()
291  {
292  ++in;
293  return *this;
294  }
295 
297  bool empty() const
298  {
299  return in.empty();
300  }
301  };
302 
303 
305 }
306 
307 __STXXL_END_NAMESPACE
308 
309 
310 #include <stxxl/bits/stream/unique.h>
311 
312 
313 #endif // !STXXL_STREAM__CHOOSE_H_
314 // vim: et:ts=4:sw=4
choose(Input_ &in_)
Construction.
Definition: choose.h:230
bool empty() const
Standard stream method.
Definition: choose.h:72
choose(Input_ &in_)
Construction.
Definition: choose.h:50
choose(Input_ &in_)
Construction.
Definition: choose.h:95
bool empty() const
Standard stream method.
Definition: choose.h:207
tuple_type::third_type value_type
Standard stream typedef.
Definition: choose.h:137
choose(Input_ &in_)
Construction.
Definition: choose.h:185
tuple_type::fourth_type value_type
Standard stream typedef.
Definition: choose.h:182
tuple_type::second_type value_type
Standard stream typedef.
Definition: choose.h:92
bool empty() const
Standard stream method.
Definition: choose.h:117
tuple_type::fifth_type value_type
Standard stream typedef.
Definition: choose.h:227
choose(Input_ &in_)
Construction.
Definition: choose.h:140
choose(Input_ &in_)
Construction.
Definition: choose.h:275
bool empty() const
Standard stream method.
Definition: choose.h:162
bool empty() const
Standard stream method.
Definition: choose.h:297
bool empty() const
Standard stream method.
Definition: choose.h:252
tuple_type::first_type value_type
Standard stream typedef.
Definition: choose.h:47
tuple_type::sixth_type value_type
Standard stream typedef.
Definition: choose.h:272