• Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List

choose.h

00001 /***************************************************************************
00002  *  include/stxxl/bits/stream/choose.h
00003  *
00004  *  Part of the STXXL. See http://stxxl.sourceforge.net
00005  *
00006  *  Copyright (C) 2003-2005 Roman Dementiev <[email protected]>
00007  *  Copyright (C) 2010 Andreas Beckmann <[email protected]>
00008  *
00009  *  Distributed under the Boost Software License, Version 1.0.
00010  *  (See accompanying file LICENSE_1_0.txt or copy at
00011  *  http://www.boost.org/LICENSE_1_0.txt)
00012  **************************************************************************/
00013 
00014 #ifndef STXXL_STREAM__CHOOSE_H_
00015 #define STXXL_STREAM__CHOOSE_H_
00016 
00017 #include <stxxl/bits/namespace.h>
00018 
00019 
00020 __STXXL_BEGIN_NAMESPACE
00021 
00023 namespace stream
00024 {
00026     //     CHOOSE                                                         //
00028 
00029     template <class Input_, int Which>
00030     class choose
00031     { };
00032 
00038     template <class Input_>
00039     class choose<Input_, 1>
00040     {
00041         Input_ & in;
00042 
00043         typedef typename Input_::value_type tuple_type;
00044 
00045     public:
00047         typedef typename tuple_type::first_type value_type;
00048 
00050         choose(Input_ & in_) : in(in_)
00051         { }
00052 
00054         const value_type & operator * () const
00055         {
00056             return (*in).first;
00057         }
00058 
00059         const value_type * operator -> () const
00060         {
00061             return &(*in).first;
00062         }
00063 
00065         choose & operator ++ ()
00066         {
00067             ++in;
00068             return *this;
00069         }
00070 
00072         bool empty() const
00073         {
00074             return in.empty();
00075         }
00076     };
00077 
00083     template <class Input_>
00084     class choose<Input_, 2>
00085     {
00086         Input_ & in;
00087 
00088         typedef typename Input_::value_type tuple_type;
00089 
00090     public:
00092         typedef typename tuple_type::second_type value_type;
00093 
00095         choose(Input_ & in_) : in(in_)
00096         { }
00097 
00099         const value_type & operator * () const
00100         {
00101             return (*in).second;
00102         }
00103 
00104         const value_type * operator -> () const
00105         {
00106             return &(*in).second;
00107         }
00108 
00110         choose & operator ++ ()
00111         {
00112             ++in;
00113             return *this;
00114         }
00115 
00117         bool empty() const
00118         {
00119             return in.empty();
00120         }
00121     };
00122 
00128     template <class Input_>
00129     class choose<Input_, 3>
00130     {
00131         Input_ & in;
00132 
00133         typedef typename Input_::value_type tuple_type;
00134 
00135     public:
00137         typedef typename tuple_type::third_type value_type;
00138 
00140         choose(Input_ & in_) : in(in_)
00141         { }
00142 
00144         const value_type & operator * () const
00145         {
00146             return (*in).third;
00147         }
00148 
00149         const value_type * operator -> () const
00150         {
00151             return &(*in).third;
00152         }
00153 
00155         choose & operator ++ ()
00156         {
00157             ++in;
00158             return *this;
00159         }
00160 
00162         bool empty() const
00163         {
00164             return in.empty();
00165         }
00166     };
00167 
00173     template <class Input_>
00174     class choose<Input_, 4>
00175     {
00176         Input_ & in;
00177 
00178         typedef typename Input_::value_type tuple_type;
00179 
00180     public:
00182         typedef typename tuple_type::fourth_type value_type;
00183 
00185         choose(Input_ & in_) : in(in_)
00186         { }
00187 
00189         const value_type & operator * () const
00190         {
00191             return (*in).fourth;
00192         }
00193 
00194         const value_type * operator -> () const
00195         {
00196             return &(*in).fourth;
00197         }
00198 
00200         choose & operator ++ ()
00201         {
00202             ++in;
00203             return *this;
00204         }
00205 
00207         bool empty() const
00208         {
00209             return in.empty();
00210         }
00211     };
00212 
00218     template <class Input_>
00219     class choose<Input_, 5>
00220     {
00221         Input_ & in;
00222 
00223         typedef typename Input_::value_type tuple_type;
00224 
00225     public:
00227         typedef typename tuple_type::fifth_type value_type;
00228 
00230         choose(Input_ & in_) : in(in_)
00231         { }
00232 
00234         const value_type & operator * () const
00235         {
00236             return (*in).fifth;
00237         }
00238 
00239         const value_type * operator -> () const
00240         {
00241             return &(*in).fifth;
00242         }
00243 
00245         choose & operator ++ ()
00246         {
00247             ++in;
00248             return *this;
00249         }
00250 
00252         bool empty() const
00253         {
00254             return in.empty();
00255         }
00256     };
00257 
00263     template <class Input_>
00264     class choose<Input_, 6>
00265     {
00266         Input_ & in;
00267 
00268         typedef typename Input_::value_type tuple_type;
00269 
00270     public:
00272         typedef typename tuple_type::sixth_type value_type;
00273 
00275         choose(Input_ & in_) : in(in_)
00276         { }
00277 
00279         const value_type & operator * () const
00280         {
00281             return (*in).sixth;
00282         }
00283 
00284         const value_type * operator -> () const
00285         {
00286             return &(*in).sixth;
00287         }
00288 
00290         choose & operator ++ ()
00291         {
00292             ++in;
00293             return *this;
00294         }
00295 
00297         bool empty() const
00298         {
00299             return in.empty();
00300         }
00301     };
00302 
00303 
00305 }
00306 
00307 __STXXL_END_NAMESPACE
00308 
00309 
00310 #include <stxxl/bits/stream/unique.h>
00311 
00312 
00313 #endif // !STXXL_STREAM__CHOOSE_H_
00314 // vim: et:ts=4:sw=4

Generated by  doxygen 1.7.1