File indexing completed on 2025-01-18 09:36:55
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_DYNAMIC_AT_C_HPP
0009 #define BOOST_GIL_EXTENSION_DYNAMIC_IMAGE_DYNAMIC_AT_C_HPP
0010
0011 #include <boost/gil/detail/mp11.hpp>
0012
0013 #include <boost/preprocessor/facilities/empty.hpp>
0014 #include <boost/preprocessor/repetition/repeat.hpp>
0015
0016 #include <stdexcept>
0017
0018 namespace boost { namespace gil {
0019
0020
0021
0022 #define BOOST_GIL_AT_C_VALUE(z, N, text) mp11::mp_at_c<IntTypes, S+N>::value,
0023 #define BOOST_GIL_DYNAMIC_AT_C_LIMIT 226
0024
0025 #define BOOST_GIL_AT_C_LOOKUP(z, NUM, text) \
0026 template<std::size_t S> \
0027 struct at_c_fn<S,NUM> { \
0028 template <typename IntTypes, typename ValueType> inline \
0029 static ValueType apply(std::size_t index) { \
0030 static ValueType table[] = { \
0031 BOOST_PP_REPEAT(NUM, BOOST_GIL_AT_C_VALUE, BOOST_PP_EMPTY) \
0032 }; \
0033 return table[index]; \
0034 } \
0035 };
0036
0037 namespace detail {
0038 namespace at_c {
0039 template <std::size_t START, std::size_t NUM> struct at_c_fn;
0040 BOOST_PP_REPEAT(BOOST_GIL_DYNAMIC_AT_C_LIMIT, BOOST_GIL_AT_C_LOOKUP, BOOST_PP_EMPTY)
0041
0042 template <std::size_t QUOT> struct at_c_impl;
0043
0044 template <>
0045 struct at_c_impl<0> {
0046 template <typename IntTypes, typename ValueType> inline
0047 static ValueType apply(std::size_t index) {
0048 return at_c_fn<0, mp11::mp_size<IntTypes>::value>::template apply<IntTypes,ValueType>(index);
0049 }
0050 };
0051
0052 template <>
0053 struct at_c_impl<1> {
0054 template <typename IntTypes, typename ValueType> inline
0055 static ValueType apply(std::size_t index) {
0056 const std::size_t SIZE = mp11::mp_size<IntTypes>::value;
0057 const std::size_t REM = SIZE % BOOST_GIL_DYNAMIC_AT_C_LIMIT;
0058 switch (index / BOOST_GIL_DYNAMIC_AT_C_LIMIT) {
0059 case 0: return at_c_fn<0 ,BOOST_GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index);
0060 case 1: return at_c_fn<BOOST_GIL_DYNAMIC_AT_C_LIMIT ,REM >::template apply<IntTypes,ValueType>(index - BOOST_GIL_DYNAMIC_AT_C_LIMIT);
0061 };
0062 throw;
0063 }
0064 };
0065
0066 template <>
0067 struct at_c_impl<2> {
0068 template <typename IntTypes, typename ValueType> inline
0069 static ValueType apply(std::size_t index) {
0070 const std::size_t SIZE = mp11::mp_size<IntTypes>::value;
0071 const std::size_t REM = SIZE % BOOST_GIL_DYNAMIC_AT_C_LIMIT;
0072 switch (index / BOOST_GIL_DYNAMIC_AT_C_LIMIT) {
0073 case 0: return at_c_fn<0 ,BOOST_GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index);
0074 case 1: return at_c_fn<BOOST_GIL_DYNAMIC_AT_C_LIMIT ,BOOST_GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index - BOOST_GIL_DYNAMIC_AT_C_LIMIT);
0075 case 2: return at_c_fn<BOOST_GIL_DYNAMIC_AT_C_LIMIT*2,REM >::template apply<IntTypes,ValueType>(index - BOOST_GIL_DYNAMIC_AT_C_LIMIT*2);
0076 };
0077 throw;
0078 }
0079 };
0080
0081 template <>
0082 struct at_c_impl<3> {
0083 template <typename IntTypes, typename ValueType> inline
0084 static ValueType apply(std::size_t index) {
0085 const std::size_t SIZE = mp11::mp_size<IntTypes>::value;
0086 const std::size_t REM = SIZE % BOOST_GIL_DYNAMIC_AT_C_LIMIT;
0087 switch (index / BOOST_GIL_DYNAMIC_AT_C_LIMIT) {
0088 case 0: return at_c_fn<0 ,BOOST_GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index);
0089 case 1: return at_c_fn<BOOST_GIL_DYNAMIC_AT_C_LIMIT ,BOOST_GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index - BOOST_GIL_DYNAMIC_AT_C_LIMIT);
0090 case 2: return at_c_fn<BOOST_GIL_DYNAMIC_AT_C_LIMIT*2,BOOST_GIL_DYNAMIC_AT_C_LIMIT-1>::template apply<IntTypes,ValueType>(index - BOOST_GIL_DYNAMIC_AT_C_LIMIT*2);
0091 case 3: return at_c_fn<BOOST_GIL_DYNAMIC_AT_C_LIMIT*3,REM >::template apply<IntTypes,ValueType>(index - BOOST_GIL_DYNAMIC_AT_C_LIMIT*3);
0092 };
0093 throw;
0094 }
0095 };
0096 }
0097 }
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107 template <typename IntTypes, typename ValueType> inline
0108 ValueType at_c(std::size_t index) {
0109 const std::size_t Size=mp11::mp_size<IntTypes>::value;
0110 return detail::at_c::at_c_impl<Size/BOOST_GIL_DYNAMIC_AT_C_LIMIT>::template apply<IntTypes,ValueType>(index);
0111 }
0112
0113 #undef BOOST_GIL_AT_C_VALUE
0114 #undef BOOST_GIL_DYNAMIC_AT_C_LIMIT
0115 #undef BOOST_GIL_AT_C_LOOKUP
0116
0117 }}
0118
0119 #endif