get_num_bits.hpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // Copyright 2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
  3. //
  4. // Distributed under the Boost Software License, Version 1.0
  5. // See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt
  7. //
  8. #ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_GET_NUM_BITS_HPP
  9. #define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_GET_NUM_BITS_HPP
  10. #include <boost/gil/channel.hpp>
  11. #include <boost/gil/detail/is_channel_integral.hpp>
  12. #include <boost/gil/detail/mp11.hpp>
  13. #include <type_traits>
  14. namespace boost{ namespace gil {
  15. /// get_num_bits metafunctions
  16. /// \brief Determines the numbers of bits for the given channel type.
  17. template <typename T, class = void>
  18. struct get_num_bits;
  19. template<typename B, int I, int S, bool M>
  20. struct get_num_bits<packed_channel_reference<B, I, S, M>>
  21. : std::integral_constant<int, S>
  22. {};
  23. template<typename B, int I, int S, bool M>
  24. struct get_num_bits<packed_channel_reference<B, I, S, M> const>
  25. : std::integral_constant<int, S>
  26. {};
  27. template<typename B, int I, bool M>
  28. struct get_num_bits<packed_dynamic_channel_reference<B, I, M>>
  29. : std::integral_constant<int, I>
  30. {};
  31. template<typename B, int I, bool M>
  32. struct get_num_bits<packed_dynamic_channel_reference<B, I, M> const>
  33. : std::integral_constant<int, I>
  34. {};
  35. template<int N>
  36. struct get_num_bits<packed_channel_value<N>> : std::integral_constant<int, N>
  37. {};
  38. template<int N>
  39. struct get_num_bits<packed_channel_value<N> const> : std::integral_constant<int, N>
  40. {};
  41. template <typename T>
  42. struct get_num_bits
  43. <
  44. T,
  45. typename std::enable_if
  46. <
  47. mp11::mp_and
  48. <
  49. detail::is_channel_integral<T>,
  50. mp11::mp_not<std::is_class<T>>
  51. >::value
  52. >::type
  53. >
  54. : std::integral_constant<std::size_t, sizeof(T) * 8>
  55. {};
  56. }} // namespace boost::gil
  57. #endif