13 #ifndef GIL_DYNAMIC_AT_C_HPP
14 #define GIL_DYNAMIC_AT_C_HPP
18 #include <boost/mpl/at.hpp>
19 #include <boost/mpl/size.hpp>
31 namespace boost {
namespace gil {
33 #define GIL_AT_C_VALUE(z, N, text) mpl::at_c<IntTypes,S+N>::type::value,
34 #define GIL_DYNAMIC_AT_C_LIMIT 226 // size of the maximum vector to handle
36 #define GIL_AT_C_LOOKUP(z, NUM, text) \
37 template<std::size_t S> \
38 struct at_c_fn<S,NUM> { \
39 template <typename IntTypes, typename ValueType> inline \
40 static ValueType apply(std::size_t index) { \
41 static ValueType table[] = { \
42 BOOST_PP_REPEAT(NUM, GIL_AT_C_VALUE, BOOST_PP_EMPTY) \
44 return table[index]; \
50 template <std::
size_t START, std::
size_t NUM>
struct at_c_fn;
51 BOOST_PP_REPEAT(GIL_DYNAMIC_AT_C_LIMIT, GIL_AT_C_LOOKUP, BOOST_PP_EMPTY)
53 template <std::
size_t QUOT> struct at_c_impl;
57 template <
typename IntTypes,
typename ValueType>
inline
58 static ValueType apply(std::size_t index) {
59 return at_c_fn<0,mpl::size<IntTypes>::value>::template apply<IntTypes,ValueType>(index);
65 template <
typename IntTypes,
typename ValueType>
inline
66 static ValueType apply(std::size_t index) {
67 const std::size_t SIZE=mpl::size<IntTypes>::value;
68 const std::size_t REM = SIZE % GIL_DYNAMIC_AT_C_LIMIT;
69 switch (index / GIL_DYNAMIC_AT_C_LIMIT) {
70 case 0:
return at_c_fn<0 ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index);
71 case 1:
return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT ,REM >::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT);
79 template <
typename IntTypes,
typename ValueType>
inline
80 static ValueType apply(std::size_t index) {
81 const std::size_t SIZE=mpl::size<IntTypes>::value;
82 const std::size_t REM = SIZE % GIL_DYNAMIC_AT_C_LIMIT;
83 switch (index / GIL_DYNAMIC_AT_C_LIMIT) {
84 case 0:
return at_c_fn<0 ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index);
85 case 1:
return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT);
86 case 2:
return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT*2,REM >::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT*2);
94 template <
typename IntTypes,
typename ValueType>
inline
95 static ValueType apply(std::size_t index) {
96 const std::size_t SIZE=mpl::size<IntTypes>::value;
97 const std::size_t REM = SIZE % GIL_DYNAMIC_AT_C_LIMIT;
98 switch (index / GIL_DYNAMIC_AT_C_LIMIT) {
99 case 0:
return at_c_fn<0 ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index);
100 case 1:
return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT);
101 case 2:
return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT*2,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT*2);
102 case 3:
return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT*3,REM >::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT*3);
117 template <
typename IntTypes,
typename ValueType>
inline
118 ValueType at_c(std::size_t index) {
119 const std::size_t Size=mpl::size<IntTypes>::value;
120 return detail::at_c::at_c_impl<Size/GIL_DYNAMIC_AT_C_LIMIT>::template apply<IntTypes,ValueType>(index);
123 #undef GIL_AT_C_VALUE
124 #undef GIL_DYNAMIC_AT_C_LIMIT
125 #undef GIL_AT_C_LOOKUP