Stxxl
1.4.0
|
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 <dementiev@mpi-sb.mpg.de> 00007 * Copyright (C) 2010 Andreas Beckmann <beckmann@cs.uni-frankfurt.de> 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 00022 //! \brief Stream package subnamespace 00023 namespace stream 00024 { 00025 //////////////////////////////////////////////////////////////////////// 00026 // CHOOSE // 00027 //////////////////////////////////////////////////////////////////////// 00028 00029 template <class Input_, int Which> 00030 class choose 00031 { }; 00032 00033 //! \brief Creates stream from a tuple stream taking the first component of each tuple 00034 //! 00035 //! \tparam Input_ type of the input tuple stream 00036 //! 00037 //! \remark Tuple stream is a stream which \c value_type is \c stxxl::tuple . 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: 00046 //! \brief Standard stream typedef 00047 typedef typename tuple_type::first_type value_type; 00048 00049 //! \brief Construction 00050 choose(Input_ & in_) : in(in_) 00051 { } 00052 00053 //! \brief Standard stream method 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 00064 //! \brief Standard stream method 00065 choose & operator ++ () 00066 { 00067 ++in; 00068 return *this; 00069 } 00070 00071 //! \brief Standard stream method 00072 bool empty() const 00073 { 00074 return in.empty(); 00075 } 00076 }; 00077 00078 //! \brief Creates stream from a tuple stream taking the second component of each tuple 00079 //! 00080 //! \tparam Input_ type of the input tuple stream 00081 //! 00082 //! \remark Tuple stream is a stream which \c value_type is \c stxxl::tuple . 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: 00091 //! \brief Standard stream typedef 00092 typedef typename tuple_type::second_type value_type; 00093 00094 //! \brief Construction 00095 choose(Input_ & in_) : in(in_) 00096 { } 00097 00098 //! \brief Standard stream method 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 00109 //! \brief Standard stream method 00110 choose & operator ++ () 00111 { 00112 ++in; 00113 return *this; 00114 } 00115 00116 //! \brief Standard stream method 00117 bool empty() const 00118 { 00119 return in.empty(); 00120 } 00121 }; 00122 00123 //! \brief Creates stream from a tuple stream taking the third component of each tuple 00124 //! 00125 //! \tparam Input_ type of the input tuple stream 00126 //! 00127 //! \remark Tuple stream is a stream which \c value_type is \c stxxl::tuple . 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: 00136 //! \brief Standard stream typedef 00137 typedef typename tuple_type::third_type value_type; 00138 00139 //! \brief Construction 00140 choose(Input_ & in_) : in(in_) 00141 { } 00142 00143 //! \brief Standard stream method 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 00154 //! \brief Standard stream method 00155 choose & operator ++ () 00156 { 00157 ++in; 00158 return *this; 00159 } 00160 00161 //! \brief Standard stream method 00162 bool empty() const 00163 { 00164 return in.empty(); 00165 } 00166 }; 00167 00168 //! \brief Creates stream from a tuple stream taking the fourth component of each tuple 00169 //! 00170 //! \tparam Input_ type of the input tuple stream 00171 //! 00172 //! \remark Tuple stream is a stream which \c value_type is \c stxxl::tuple . 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: 00181 //! \brief Standard stream typedef 00182 typedef typename tuple_type::fourth_type value_type; 00183 00184 //! \brief Construction 00185 choose(Input_ & in_) : in(in_) 00186 { } 00187 00188 //! \brief Standard stream method 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 00199 //! \brief Standard stream method 00200 choose & operator ++ () 00201 { 00202 ++in; 00203 return *this; 00204 } 00205 00206 //! \brief Standard stream method 00207 bool empty() const 00208 { 00209 return in.empty(); 00210 } 00211 }; 00212 00213 //! \brief Creates stream from a tuple stream taking the fifth component of each tuple 00214 //! 00215 //! \tparam Input_ type of the input tuple stream 00216 //! 00217 //! \remark Tuple stream is a stream which \c value_type is \c stxxl::tuple . 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: 00226 //! \brief Standard stream typedef 00227 typedef typename tuple_type::fifth_type value_type; 00228 00229 //! \brief Construction 00230 choose(Input_ & in_) : in(in_) 00231 { } 00232 00233 //! \brief Standard stream method 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 00244 //! \brief Standard stream method 00245 choose & operator ++ () 00246 { 00247 ++in; 00248 return *this; 00249 } 00250 00251 //! \brief Standard stream method 00252 bool empty() const 00253 { 00254 return in.empty(); 00255 } 00256 }; 00257 00258 //! \brief Creates stream from a tuple stream taking the sixth component of each tuple 00259 //! 00260 //! \tparam Input_ type of the input tuple stream 00261 //! 00262 //! \remark Tuple stream is a stream which \c value_type is \c stxxl::tuple . 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: 00271 //! \brief Standard stream typedef 00272 typedef typename tuple_type::sixth_type value_type; 00273 00274 //! \brief Construction 00275 choose(Input_ & in_) : in(in_) 00276 { } 00277 00278 //! \brief Standard stream method 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 00289 //! \brief Standard stream method 00290 choose & operator ++ () 00291 { 00292 ++in; 00293 return *this; 00294 } 00295 00296 //! \brief Standard stream method 00297 bool empty() const 00298 { 00299 return in.empty(); 00300 } 00301 }; 00302 00303 00304 //! \} 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