Information
MediaSupport
RSSOther Adobe ProjectsOther Resources |
dynamic_at_c.hppGo to the documentation of this file.00001 /* 00002 Copyright 2005-2006 Adobe Systems Incorporated 00003 Distributed under the MIT License (see accompanying file LICENSE_1_0_0.txt 00004 or a copy at http://opensource.adobe.com/licenses.html) 00005 */ 00006 00007 /*************************************************************************************************/ 00008 00009 #ifndef GIL_DYNAMIC_AT_C_HPP 00010 #define GIL_DYNAMIC_AT_C_HPP 00011 00012 #include "../../core/gil_config.hpp" 00013 #include <cassert> 00014 #include <stdexcept> 00015 #include <boost/mpl/at.hpp> 00016 #include <boost/mpl/size.hpp> 00017 00018 00027 00028 ADOBE_GIL_NAMESPACE_BEGIN 00029 00030 #define GIL_AT_C_VALUE(z, N, text) boost::mpl::at_c<INT_TYPES,S+N>::type::value, 00031 #define DYNAMIC_AT_C_LIMIT 226 // size of the maximum vector to handle 00032 00033 #define GIL_AT_C_LOOKUP(z, NUM, text) \ 00034 template<std::size_t S> \ 00035 struct at_c_fn<S,NUM> { \ 00036 template <typename INT_TYPES, typename VALUE_TYPE> inline \ 00037 static VALUE_TYPE apply(std::size_t index) { \ 00038 static VALUE_TYPE table[] = { \ 00039 BOOST_PP_REPEAT(NUM, GIL_AT_C_VALUE, BOOST_PP_EMPTY) \ 00040 }; \ 00041 return table[index]; \ 00042 } \ 00043 }; 00044 00045 namespace detail { 00046 namespace at_c { 00047 template <std::size_t START, std::size_t NUM> struct at_c_fn; 00048 BOOST_PP_REPEAT(DYNAMIC_AT_C_LIMIT, GIL_AT_C_LOOKUP, BOOST_PP_EMPTY) 00049 /* 00050 template <std::size_t QUOT> struct at_c_impl; 00051 00052 template <> 00053 struct at_c_impl<0> { 00054 template <typename INT_TYPES, typename VALUE_TYPE> inline 00055 static VALUE_TYPE apply(std::size_t index) { 00056 return at_c_fn<0,boost::mpl::size<INT_TYPES>::value>::template apply<INT_TYPES,VALUE_TYPE>(index); 00057 } 00058 }; 00059 00060 template <> 00061 struct at_c_impl<1> { 00062 template <typename INT_TYPES, typename VALUE_TYPE> inline 00063 static VALUE_TYPE apply(std::size_t index) { 00064 const std::size_t SIZE=boost::mpl::size<INT_TYPES>::value; 00065 const std::size_t REM = SIZE % DYNAMIC_AT_C_LIMIT; 00066 switch (index / DYNAMIC_AT_C_LIMIT) { 00067 case 0: return at_c_fn<0 ,DYNAMIC_AT_C_LIMIT-1>::template apply<INT_TYPES,VALUE_TYPE>(index); 00068 case 1: return at_c_fn<DYNAMIC_AT_C_LIMIT ,REM >::template apply<INT_TYPES,VALUE_TYPE>(index - DYNAMIC_AT_C_LIMIT); 00069 }; 00070 throw; 00071 } 00072 }; 00073 00074 template <> 00075 struct at_c_impl<2> { 00076 template <typename INT_TYPES, typename VALUE_TYPE> inline 00077 static VALUE_TYPE apply(std::size_t index) { 00078 const std::size_t SIZE=boost::mpl::size<INT_TYPES>::value; 00079 const std::size_t REM = SIZE % DYNAMIC_AT_C_LIMIT; 00080 switch (index / DYNAMIC_AT_C_LIMIT) { 00081 case 0: return at_c_fn<0 ,DYNAMIC_AT_C_LIMIT-1>::template apply<INT_TYPES,VALUE_TYPE>(index); 00082 case 1: return at_c_fn<DYNAMIC_AT_C_LIMIT ,DYNAMIC_AT_C_LIMIT-1>::template apply<INT_TYPES,VALUE_TYPE>(index - DYNAMIC_AT_C_LIMIT); 00083 case 2: return at_c_fn<DYNAMIC_AT_C_LIMIT*2,REM >::template apply<INT_TYPES,VALUE_TYPE>(index - DYNAMIC_AT_C_LIMIT*2); 00084 }; 00085 throw; 00086 } 00087 }; 00088 00089 template <> 00090 struct at_c_impl<3> { 00091 template <typename INT_TYPES, typename VALUE_TYPE> inline 00092 static VALUE_TYPE apply(std::size_t index) { 00093 const std::size_t SIZE=boost::mpl::size<INT_TYPES>::value; 00094 const std::size_t REM = SIZE % DYNAMIC_AT_C_LIMIT; 00095 switch (index / DYNAMIC_AT_C_LIMIT) { 00096 case 0: return at_c_fn<0 ,DYNAMIC_AT_C_LIMIT-1>::template apply<INT_TYPES,VALUE_TYPE>(index); 00097 case 1: return at_c_fn<DYNAMIC_AT_C_LIMIT ,DYNAMIC_AT_C_LIMIT-1>::template apply<INT_TYPES,VALUE_TYPE>(index - DYNAMIC_AT_C_LIMIT); 00098 case 2: return at_c_fn<DYNAMIC_AT_C_LIMIT*2,DYNAMIC_AT_C_LIMIT-1>::template apply<INT_TYPES,VALUE_TYPE>(index - DYNAMIC_AT_C_LIMIT*2); 00099 case 3: return at_c_fn<DYNAMIC_AT_C_LIMIT*3,REM >::template apply<INT_TYPES,VALUE_TYPE>(index - DYNAMIC_AT_C_LIMIT*3); 00100 }; 00101 throw; 00102 } 00103 }; 00104 */ 00105 } 00106 } 00107 00114 00115 template <typename INT_TYPES, typename VALUE_TYPE> inline 00116 VALUE_TYPE at_c(std::size_t index) { 00117 return detail::at_c::at_c_fn<0,boost::mpl::size<INT_TYPES>::value>::template apply<INT_TYPES,VALUE_TYPE>(index); 00118 // const std::size_t SIZE=boost::mpl::size<INT_TYPES>::value; 00119 // return detail::at_c::at_c_impl<SIZE/DYNAMIC_AT_C_LIMIT>::template apply<INT_TYPES,VALUE_TYPE>(index); 00120 } 00121 00122 ADOBE_GIL_NAMESPACE_END 00123 00124 #endif |