Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r82882 - in trunk: boost/gil/extension/toolbox/metafunctions libs/gil/toolbox/test
From: chhenning_at_[hidden]
Date: 2013-02-14 11:00:09


Author: chhenning
Date: 2013-02-14 11:00:09 EST (Thu, 14 Feb 2013)
New Revision: 82882
URL: http://svn.boost.org/trac/boost/changeset/82882

Log:
Added more specializations for get_num_bits.
Text files modified:
   trunk/boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp | 60 ++++++++++++++++++++-------------------
   trunk/libs/gil/toolbox/test/get_num_bits.cpp | 9 ++++++
   trunk/libs/gil/toolbox/test/get_pixel_type.cpp | 6 ++-
   3 files changed, 44 insertions(+), 31 deletions(-)

Modified: trunk/boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp
==============================================================================
--- trunk/boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp (original)
+++ trunk/boost/gil/extension/toolbox/metafunctions/get_num_bits.hpp 2013-02-14 11:00:09 EST (Thu, 14 Feb 2013)
@@ -21,49 +21,51 @@
 
 #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>
+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 > >
-{
- BOOST_STATIC_CONSTANT( int, value = S );
-};
-
-template<typename B,int I, int S, bool M>
-struct get_num_bits< const packed_channel_reference< B, I, S, M > >
-{
- BOOST_STATIC_CONSTANT( int, value = S );
-};
+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 > >
-{
- BOOST_STATIC_CONSTANT( int, value = I );
-};
-
-template<typename b, int i, bool m>
-struct get_num_bits< const packed_dynamic_channel_reference< b, i, m > >
-{
- BOOST_STATIC_CONSTANT( int, value = i );
-};
+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 > >
-{
- BOOST_STATIC_CONSTANT( int, value = N );
-};
+struct get_num_bits< packed_channel_value< N > > : mpl::int_< N >
+{};
 
 template< int N >
-struct get_num_bits< const packed_channel_value< N > >
-{
- BOOST_STATIC_CONSTANT( int, value = 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

Modified: trunk/libs/gil/toolbox/test/get_num_bits.cpp
==============================================================================
--- trunk/libs/gil/toolbox/test/get_num_bits.cpp (original)
+++ trunk/libs/gil/toolbox/test/get_num_bits.cpp 2013-02-14 11:00:09 EST (Thu, 14 Feb 2013)
@@ -23,6 +23,15 @@
 
     typedef packed_channel_value< 23 > bits_t;
     BOOST_STATIC_ASSERT( get_num_bits< bits_t >::value == 23 );
+ BOOST_STATIC_ASSERT( get_num_bits< const bits_t >::value == 23 );
+
+ BOOST_STATIC_ASSERT( get_num_bits< unsigned char >::value == 8 );
+ BOOST_STATIC_ASSERT( get_num_bits< const unsigned char >::value == 8 );
+
+ BOOST_STATIC_ASSERT( get_num_bits< channel_type< gray8_image_t::view_t::value_type >::type >::value == 8 );
+ BOOST_STATIC_ASSERT( get_num_bits< channel_type< rgba32_image_t::view_t::value_type >::type >::value == 32 );
+
 }
 
 BOOST_AUTO_TEST_SUITE_END()
+

Modified: trunk/libs/gil/toolbox/test/get_pixel_type.cpp
==============================================================================
--- trunk/libs/gil/toolbox/test/get_pixel_type.cpp (original)
+++ trunk/libs/gil/toolbox/test/get_pixel_type.cpp 2013-02-14 11:00:09 EST (Thu, 14 Feb 2013)
@@ -15,14 +15,16 @@
     {
         typedef bit_aligned_image3_type< 4, 15, 4, rgb_layout_t >::type image_t;
         BOOST_STATIC_ASSERT(( is_same< get_pixel_type< image_t::view_t >::type
- , image_t::view_t::reference >::value
+ , image_t::view_t::reference
+ >::value
                            ));
     }
 
     {
         typedef rgb8_image_t image_t;
         BOOST_STATIC_ASSERT(( is_same< get_pixel_type< image_t::view_t >::type
- , image_t::view_t::value_type >::value
+ , image_t::view_t::value_type
+ >::value
                            ));
     }
 }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk