13 #ifndef GIL_DYNAMIC_AT_C_HPP
14 #define GIL_DYNAMIC_AT_C_HPP
16 #include "../../gil_config.hpp"
19 #include <boost/mpl/at.hpp>
20 #include <boost/mpl/size.hpp>
32 namespace boost {
namespace gil {
34 #define GIL_AT_C_VALUE(z, N, text) mpl::at_c<IntTypes,S+N>::type::value,
35 #define GIL_DYNAMIC_AT_C_LIMIT 226 // size of the maximum vector to handle
37 #define GIL_AT_C_LOOKUP(z, NUM, text) \
38 template<std::size_t S> \
39 struct at_c_fn<S,NUM> { \
40 template <typename IntTypes, typename ValueType> inline \
41 static ValueType apply(std::size_t index) { \
42 static ValueType table[] = { \
43 BOOST_PP_REPEAT(NUM, GIL_AT_C_VALUE, BOOST_PP_EMPTY) \
45 return table[index]; \
51 template <std::
size_t START, std::
size_t NUM>
struct at_c_fn;
52 BOOST_PP_REPEAT(GIL_DYNAMIC_AT_C_LIMIT, GIL_AT_C_LOOKUP, BOOST_PP_EMPTY)
54 template <std::
size_t QUOT> struct at_c_impl;
58 template <
typename IntTypes,
typename ValueType>
inline
59 static ValueType apply(std::size_t index) {
60 return at_c_fn<0,mpl::size<IntTypes>::value>::template apply<IntTypes,ValueType>(index);
66 template <
typename IntTypes,
typename ValueType>
inline
67 static ValueType apply(std::size_t index) {
68 const std::size_t SIZE=mpl::size<IntTypes>::value;
69 const std::size_t REM = SIZE % GIL_DYNAMIC_AT_C_LIMIT;
70 switch (index / GIL_DYNAMIC_AT_C_LIMIT) {
71 case 0:
return at_c_fn<0 ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index);
72 case 1:
return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT ,REM >::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT);
80 template <
typename IntTypes,
typename ValueType>
inline
81 static ValueType apply(std::size_t index) {
82 const std::size_t SIZE=mpl::size<IntTypes>::value;
83 const std::size_t REM = SIZE % GIL_DYNAMIC_AT_C_LIMIT;
84 switch (index / GIL_DYNAMIC_AT_C_LIMIT) {
85 case 0:
return at_c_fn<0 ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index);
86 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);
87 case 2:
return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT*2,REM >::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT*2);
95 template <
typename IntTypes,
typename ValueType>
inline
96 static ValueType apply(std::size_t index) {
97 const std::size_t SIZE=mpl::size<IntTypes>::value;
98 const std::size_t REM = SIZE % GIL_DYNAMIC_AT_C_LIMIT;
99 switch (index / GIL_DYNAMIC_AT_C_LIMIT) {
100 case 0:
return at_c_fn<0 ,GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index);
101 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);
102 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);
103 case 3:
return at_c_fn<GIL_DYNAMIC_AT_C_LIMIT*3,REM >::template apply<IntTypes,ValueType>(index - GIL_DYNAMIC_AT_C_LIMIT*3);
118 template <
typename IntTypes,
typename ValueType>
inline
119 ValueType at_c(std::size_t index) {
120 const std::size_t Size=mpl::size<IntTypes>::value;
121 return detail::at_c::at_c_impl<Size/GIL_DYNAMIC_AT_C_LIMIT>::template apply<IntTypes,ValueType>(index);
124 #undef GIL_AT_C_VALUE
125 #undef GIL_DYNAMIC_AT_C_LIMIT
126 #undef GIL_AT_C_LOOKUP