TypeList.h

Go to the documentation of this file.
00001 /*
00002  *  BEEN: Benchmarking Environment
00003  *  ==============================
00004  *
00005  *  File author: Branislav Repcek
00006  *
00007  *  GNU Lesser General Public License Version 2.1
00008  *  ---------------------------------------------
00009  *  Copyright (C) 2004-2006 Distributed Systems Research Group,
00010  *  Faculty of Mathematics and Physics, Charles University in Prague
00011  *
00012  *  This library is free software; you can redistribute it and/or
00013  *  modify it under the terms of the GNU Lesser General Public
00014  *  License version 2.1, as published by the Free Software Foundation.
00015  *
00016  *  This library is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00019  *  Lesser General Public License for more details.
00020  *
00021  *  You should have received a copy of the GNU Lesser General Public
00022  *  License along with this library; if not, write to the Free Software
00023  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024  *  MA  02111-1307  USA
00025  */
00026 
00034 #ifndef TYPE_LIST_INCLUDED
00035 #define TYPE_LIST_INCLUDED
00036 
00038 namespace tl
00039 {
00040 
00043     class NullType
00044     {
00045     };
00046 
00052     template< typename H, class T >
00053     class TypeList
00054     {
00055     public:
00057         typedef H Head;
00058 
00060         typedef T Tail;
00061     };
00062 
00063     /*
00064      * ListLength - calculate length of the list.
00065      */
00066 
00071     template< class List >
00072     class ListLength;
00073 
00076     template< class H, class T >
00077     class ListLength< TypeList< H, T > >
00078     {
00079     public:
00080         enum
00081         {
00083             Length = 1 + ListLength< T >::Length
00084         };
00085     };
00086 
00089     template< >
00090     class ListLength< NullType >
00091     {
00092     public:
00093         enum
00094         {
00096             Length = 0
00097         };
00098     };
00099 
00100     /*
00101      * Get - Select element from TypeList based on its index.
00102      */
00103 
00107     template< class List, size_t i > 
00108     class Get;
00109 
00112     template< class H, class T >
00113     class Get< TypeList< H, T >, 0 >
00114     {
00115     public:
00117         typedef H Result;
00118     };
00119 
00122     template< class H, class T, size_t i >
00123     class Get< TypeList< H, T >, i >
00124     {
00125     public:
00127         typedef typename Get< T, i - 1 >::Result Result;
00128     };
00129 
00130     /*
00131      * IndexOf - Find if given type is in TypeList and return its index.
00132      */
00133 
00138     template< class Tlist, class T > class IndexOf;
00139 
00144     template< class T >
00145     struct IndexOf< NullType, T >
00146     {
00147         enum
00148         {
00150             value = -1 
00151         };
00152     };
00153 
00158     template< class T, class Tail >
00159     struct IndexOf< TypeList< T, Tail >, T >
00160     {
00161         enum
00162         {
00164             value = 0
00165         };
00166     };
00167 
00172     template< class Head, class Tail, class T >
00173     struct IndexOf< TypeList< Head, Tail >, T >
00174     {
00175     private:
00176         enum
00177         {
00179             temp = IndexOf< Tail, T >::value
00180         };
00181 
00182     public:
00183         enum
00184         {
00186             value = (temp == - 1) ? -1 : temp + 1
00187         };
00188     };
00189 
00190 } // namespace tl
00191 
00193 #define CREATE_TYPE_LIST_01(T01) ::tl::TypeList< T01, ::tl::NullType >
00194 
00196 #define CREATE_TYPE_LIST_02(T01, T02) ::tl::TypeList< T01, CREATE_TYPE_LIST_01(T02) >
00197 
00199 #define CREATE_TYPE_LIST_03(T01, T02, T03) ::tl::TypeList< T01, CREATE_TYPE_LIST_02(T02, T03) >
00200 
00202 #define CREATE_TYPE_LIST_04(T01, T02, T03, T04) ::tl::TypeList< T01, CREATE_TYPE_LIST_03(T02, T03, T04) >
00203 
00205 #define CREATE_TYPE_LIST_05(T01, T02, T03, T04, T05) \
00206             ::tl::TypeList< T01, CREATE_TYPE_LIST_04(T02, T03, T04, T05) >
00207 
00209 #define CREATE_TYPE_LIST_06(T01, T02, T03, T04, T05, T06) \
00210             ::tl::TypeList< T01, CREATE_TYPE_LIST_05(T02, T03, T04, T05, T06) >
00211 
00213 #define CREATE_TYPE_LIST_07(T01, T02, T03, T04, T05, T06, T07) \
00214             ::tl::TypeList< T01, CREATE_TYPE_LIST_06(T02, T03, T04, T05, T06, T07) >
00215 
00217 #define CREATE_TYPE_LIST_08(T01, T02, T03, T04, T05, T06, T07, T08) \
00218             ::tl::TypeList< T01, CREATE_TYPE_LIST_07(T02, T03, T04, T05, T06, T07, T08) >
00219 
00221 #define CREATE_TYPE_LIST_09(T01, T02, T03, T04, T05, T06, T07, T08, T09) \
00222             ::tl::TypeList< T01, CREATE_TYPE_LIST_08(T02, T03, T04, T05, T06, T07, T08, T09) >
00223 
00225 #define CREATE_TYPE_LIST_10(T01, T02, T03, T04, T05, T06, T07, T08, T09, T10) \
00226             ::tl::TypeList< T01, CREATE_TYPE_LIST_09(T02, T03, T04, T05, T06, T07, T08, T09, T10) >
00227 
00229 #define CREATE_TYPE_LIST_11(T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11) \
00230     ::tl::TypeList< T01, CREATE_TYPE_LIST_10(T02, T03, T04, T05, T06, T07, T08, T09, T10, T11) >
00231 
00233 #define CREATE_TYPE_LIST_12(T01, T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12) \
00234     ::tl::TypeList< T01, CREATE_TYPE_LIST_11(T02, T03, T04, T05, T06, T07, T08, T09, T10, T11, T12) >
00235 
00236 #endif

Generated on Tue Dec 19 17:43:49 2006 for Load Monitor for Windows by  doxygen 1.4.7