Stxxl
1.4.0
|
00001 /*************************************************************************** 00002 * include/stxxl/bits/common/tuple.h 00003 * 00004 * Part of the STXXL. See http://stxxl.sourceforge.net 00005 * 00006 * Copyright (C) 2003 Roman Dementiev <dementiev@mpi-sb.mpg.de> 00007 * 00008 * Distributed under the Boost Software License, Version 1.0. 00009 * (See accompanying file LICENSE_1_0.txt or copy at 00010 * http://www.boost.org/LICENSE_1_0.txt) 00011 **************************************************************************/ 00012 00013 #ifndef STXXL_TUPLE_HEADER 00014 #define STXXL_TUPLE_HEADER 00015 00016 #include <stxxl/bits/namespace.h> 00017 #include <stxxl/bits/common/tmeta.h> 00018 00019 00020 __STXXL_BEGIN_NAMESPACE 00021 00022 struct Plug { }; 00023 00024 00025 template <class T1, 00026 class T2, 00027 class T3, 00028 class T4, 00029 class T5, 00030 class T6 00031 > 00032 struct tuple_base 00033 { 00034 typedef T1 first_type; 00035 typedef T2 second_type; 00036 typedef T3 third_type; 00037 typedef T4 fourth_type; 00038 typedef T5 fifth_type; 00039 typedef T6 sixth_type; 00040 00041 template <int I> 00042 struct item_type 00043 { 00044 /* 00045 typedef typename SWITCH<I, CASE<1,first_type, 00046 CASE<2,second_type, 00047 CASE<3,third_type, 00048 CASE<4,fourth_type, 00049 CASE<5,fifth_type, 00050 CASE<6,sixth_type, 00051 CASE<DEFAULT,void 00052 > > > > > > > >::result result; 00053 */ 00054 }; 00055 }; 00056 00057 00058 //! \brief k-Tuple data type 00059 //! 00060 //! (defined for k < 7) 00061 template <class T1, 00062 class T2 = Plug, 00063 class T3 = Plug, 00064 class T4 = Plug, 00065 class T5 = Plug, 00066 class T6 = Plug 00067 > 00068 struct tuple 00069 { 00070 typedef T1 first_type; 00071 typedef T2 second_type; 00072 typedef T3 third_type; 00073 typedef T4 fourth_type; 00074 typedef T5 fifth_type; 00075 typedef T6 sixth_type; 00076 00077 template <int I> 00078 struct item_type 00079 { 00080 typedef typename SWITCH<I, CASE<1, first_type, 00081 CASE<2, second_type, 00082 CASE<3, third_type, 00083 CASE<4, fourth_type, 00084 CASE<5, fifth_type, 00085 CASE<6, sixth_type, 00086 CASE<DEFAULT, void 00087 > > > > > > > >::result result; 00088 }; 00089 00090 //! \brief First tuple component 00091 first_type first; 00092 //! \brief Second tuple component 00093 second_type second; 00094 //! \brief Third tuple component 00095 third_type third; 00096 //! \brief Fourth tuple component 00097 fourth_type fourth; 00098 //! \brief Fifth tuple component 00099 fifth_type fifth; 00100 //! \brief Sixth tuple component 00101 sixth_type sixth; 00102 00103 tuple() { } 00104 tuple(first_type fir, 00105 second_type sec, 00106 third_type thi, 00107 fourth_type fou, 00108 fifth_type fif, 00109 sixth_type six 00110 ) : 00111 first(fir), 00112 second(sec), 00113 third(thi), 00114 fourth(fou), 00115 fifth(fif), 00116 sixth(six) 00117 { } 00118 }; 00119 00120 //! \brief Partial specialization for 1- \c tuple 00121 template <class T1> 00122 struct tuple<T1, Plug, Plug, Plug, Plug> 00123 { 00124 typedef T1 first_type; 00125 00126 first_type first; 00127 00128 template <int I> 00129 struct item_type 00130 { 00131 typedef typename IF<I == 1, first_type, void>::result result; 00132 }; 00133 00134 tuple() { } 00135 tuple(first_type fi) : 00136 first(fi) 00137 { } 00138 }; 00139 00140 //! \brief Partial specialization for 2- \c tuple (equivalent to std::pair) 00141 template <class T1, class T2> 00142 struct tuple<T1, T2, Plug, Plug, Plug, Plug> 00143 { 00144 typedef T1 first_type; 00145 typedef T2 second_type; 00146 00147 template <int I> 00148 struct item_type 00149 { 00150 typedef typename SWITCH<I, CASE<1, first_type, 00151 CASE<2, second_type, 00152 CASE<DEFAULT, void> 00153 > > >::result result; 00154 }; 00155 00156 first_type first; 00157 second_type second; 00158 00159 tuple() { } 00160 tuple(first_type fi, 00161 second_type se 00162 ) : 00163 first(fi), 00164 second(se) 00165 { } 00166 }; 00167 00168 00169 //! \brief Partial specialization for 3- \c tuple (triple) 00170 template <class T1, 00171 class T2, 00172 class T3 00173 > 00174 struct tuple<T1, T2, T3, Plug, Plug, Plug> 00175 { 00176 typedef T1 first_type; 00177 typedef T2 second_type; 00178 typedef T3 third_type; 00179 00180 template <int I> 00181 struct item_type 00182 { 00183 typedef typename SWITCH<I, CASE<1, first_type, 00184 CASE<2, second_type, 00185 CASE<3, second_type, 00186 CASE<DEFAULT, void> 00187 > > > >::result result; 00188 }; 00189 00190 00191 first_type first; 00192 second_type second; 00193 third_type third; 00194 00195 tuple() { } 00196 tuple(first_type fir, 00197 second_type sec, 00198 third_type thi 00199 ) : 00200 first(fir), 00201 second(sec), 00202 third(thi) 00203 { } 00204 }; 00205 00206 //! \brief Partial specialization for 4- \c tuple 00207 template <class T1, 00208 class T2, 00209 class T3, 00210 class T4 00211 > 00212 struct tuple<T1, T2, T3, T4, Plug, Plug> 00213 { 00214 typedef T1 first_type; 00215 typedef T2 second_type; 00216 typedef T3 third_type; 00217 typedef T4 fourth_type; 00218 00219 template <int I> 00220 struct item_type 00221 { 00222 typedef typename SWITCH<I, CASE<1, first_type, 00223 CASE<2, second_type, 00224 CASE<3, third_type, 00225 CASE<4, fourth_type, 00226 CASE<DEFAULT, void 00227 > > > > > >::result result; 00228 }; 00229 00230 00231 first_type first; 00232 second_type second; 00233 third_type third; 00234 fourth_type fourth; 00235 00236 tuple() { } 00237 tuple(first_type fir, 00238 second_type sec, 00239 third_type thi, 00240 fourth_type fou 00241 ) : 00242 first(fir), 00243 second(sec), 00244 third(thi), 00245 fourth(fou) 00246 { } 00247 }; 00248 00249 //! \brief Partial specialization for 5- \c tuple 00250 template <class T1, 00251 class T2, 00252 class T3, 00253 class T4, 00254 class T5 00255 > 00256 struct tuple<T1, T2, T3, T4, T5, Plug> 00257 { 00258 typedef T1 first_type; 00259 typedef T2 second_type; 00260 typedef T3 third_type; 00261 typedef T4 fourth_type; 00262 typedef T5 fifth_type; 00263 00264 00265 template <int I> 00266 struct item_type 00267 { 00268 typedef typename SWITCH<I, CASE<1, first_type, 00269 CASE<2, second_type, 00270 CASE<3, third_type, 00271 CASE<4, fourth_type, 00272 CASE<5, fifth_type, 00273 CASE<DEFAULT, void 00274 > > > > > > >::result result; 00275 }; 00276 00277 first_type first; 00278 second_type second; 00279 third_type third; 00280 fourth_type fourth; 00281 fifth_type fifth; 00282 00283 tuple() { } 00284 tuple(first_type fir, 00285 second_type sec, 00286 third_type thi, 00287 fourth_type fou, 00288 fifth_type fif 00289 ) : 00290 first(fir), 00291 second(sec), 00292 third(thi), 00293 fourth(fou), 00294 fifth(fif) 00295 { } 00296 }; 00297 00298 /* 00299 template <class tuple_type,int I> 00300 typename tuple_type::item_type<I>::result get(const tuple_type & t) 00301 { 00302 return NULL; 00303 } 00304 */ 00305 00306 __STXXL_END_NAMESPACE 00307 00308 #endif // !STXXL_TUPLE_HEADER