summaryrefslogtreecommitdiff
path: root/boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp
blob: 9cec37eac4cf2659450631a21f7995e6941f193f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
    Copyright 2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
    Use, modification and distribution are subject to the Boost Software License,
    Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
    http://www.boost.org/LICENSE_1_0.txt).
*/

/*************************************************************************************************/

#ifndef BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_GET_NUM_BITS_HPP
#define BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_GET_NUM_BITS_HPP

////////////////////////////////////////////////////////////////////////////////////////
/// \file get_num_bits.hpp
/// \brief get_num_bits metafunction.
/// \author Christian Henning, Andreas Pokorny, Lubomir Bourdev \n
///
/// \date 2012 \n
///
////////////////////////////////////////////////////////////////////////////////////////

#include <boost/gil/channel.hpp>

#include <boost/mpl/int.hpp>
#include <boost/type_traits/is_integral.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/utility/enable_if.hpp>

namespace boost{ namespace gil {

/// get_num_bits metafunctions
/// \brief Determines the numbers of bits for the given channel type.

template <typename T, class = void >
struct get_num_bits;

template< typename B, int I, int S, bool M >
struct get_num_bits< packed_channel_reference< B, I, S, M > > : mpl::int_< S >
{};

template< typename B, int I, int S, bool M >
struct get_num_bits< const packed_channel_reference< B, I, S, M > > : mpl::int_< S >
{};

template<typename B, int I, bool M>
struct get_num_bits< packed_dynamic_channel_reference< B, I, M > > : mpl::int_< I >
{};

template<typename B, int I, bool M>
struct get_num_bits< const packed_dynamic_channel_reference< B, I, M > > : mpl::int_< I >
{};

template< int N >
struct get_num_bits< packed_channel_value< N > > : mpl::int_< N >
{};

template< int N >
struct get_num_bits< const packed_channel_value< N > > : mpl::int_< N >
{};

template< typename T >
struct get_num_bits< T
                   , typename enable_if< mpl::and_< is_integral< T > 
                                                  , mpl::not_< is_class< T > >
                                                  >
                                       >::type
                   > : mpl::int_< sizeof(T) * 8 >
{};

} // namespace gil
} // namespace boost

#endif // BOOST_GIL_EXTENSION_TOOLBOX_METAFUNCTIONS_GET_NUM_BITS_HPP