os/ossrv/ossrv_pub/boost_apis/boost/detail/dynamic_bitset.hpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/detail/dynamic_bitset.hpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,168 @@
     1.4 +// --------------------------------------------------
     1.5 +//
     1.6 +// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
     1.7 +// (C) Copyright Gennaro Prota                 2003 - 2004.
     1.8 +//
     1.9 +// Distributed under the Boost Software License, Version 1.0.
    1.10 +//    (See accompanying file LICENSE_1_0.txt or copy at
    1.11 +//          http://www.boost.org/LICENSE_1_0.txt)
    1.12 +//
    1.13 +// -----------------------------------------------------------
    1.14 +
    1.15 +//  See http://www.boost.org/libs/dynamic_bitset for documentation.
    1.16 +
    1.17 +
    1.18 +#ifndef BOOST_DETAIL_DYNAMIC_BITSET_HPP
    1.19 +#define BOOST_DETAIL_DYNAMIC_BITSET_HPP
    1.20 +
    1.21 +#include <cstddef> // for std::size_t
    1.22 +#include "boost/config.hpp"
    1.23 +#include "boost/detail/workaround.hpp"
    1.24 +//#include "boost/static_assert.hpp" // gps
    1.25 +
    1.26 +
    1.27 +namespace boost {
    1.28 +
    1.29 +  namespace detail {
    1.30 +
    1.31 +    // Gives (read-)access to the object representation
    1.32 +    // of an object of type T (3.9p4). CANNOT be used
    1.33 +    // on a base sub-object
    1.34 +    //
    1.35 +    template <typename T>
    1.36 +    inline const unsigned char * object_representation (T* p)
    1.37 +    {
    1.38 +        return static_cast<const unsigned char *>(static_cast<const void *>(p));
    1.39 +    }
    1.40 +
    1.41 +
    1.42 +    // ------- count function implementation --------------
    1.43 +
    1.44 +    namespace dynamic_bitset_count_impl {
    1.45 +
    1.46 +    typedef unsigned char byte_type;
    1.47 +
    1.48 +    enum mode { access_by_bytes, access_by_blocks };
    1.49 +
    1.50 +    template <mode> struct mode_to_type {};
    1.51 +
    1.52 +    // the table: wrapped in a class template, so
    1.53 +    // that it is only instantiated if/when needed
    1.54 +    //
    1.55 +    template <bool dummy_name = true>
    1.56 +    struct count_table { static const byte_type table[]; };
    1.57 +
    1.58 +    template <>
    1.59 +    struct count_table<false> { /* no table */ };
    1.60 +
    1.61 +
    1.62 +     const unsigned int table_width = 8;
    1.63 +     template <bool b>
    1.64 +     const byte_type count_table<b>::table[] =
    1.65 +     {
    1.66 +       // Automatically generated by GPTableGen.exe v.1.0
    1.67 +       //
    1.68 +     0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5,
    1.69 +     1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
    1.70 +     1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
    1.71 +     2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
    1.72 +     1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6,
    1.73 +     2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
    1.74 +     2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7,
    1.75 +     3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8
    1.76 +     };
    1.77 +
    1.78 +
    1.79 +     // overload for access by bytes
    1.80 +     //
    1.81 +
    1.82 +     template <typename Iterator>
    1.83 +     inline std::size_t do_count(Iterator first, std::size_t length,
    1.84 +                                 int /*dummy param*/,
    1.85 +                                 mode_to_type<access_by_bytes>* )
    1.86 +     {
    1.87 +         std::size_t num = 0;
    1.88 +         if (length)
    1.89 +         {
    1.90 +             const byte_type * p = object_representation(&*first);
    1.91 +             length *= sizeof(*first);
    1.92 +
    1.93 +              do {
    1.94 +                 num += count_table<>::table[*p];
    1.95 +                 ++p;
    1.96 +                 --length;
    1.97 +
    1.98 +             } while (length);
    1.99 +         }
   1.100 +
   1.101 +         return num;
   1.102 +     }
   1.103 +
   1.104 +
   1.105 +     // overload for access by blocks
   1.106 +     //
   1.107 +     template <typename Iterator, typename ValueType>
   1.108 +     inline std::size_t do_count(Iterator first, std::size_t length, ValueType,
   1.109 +                                 mode_to_type<access_by_blocks>*)
   1.110 +     {
   1.111 +         std::size_t num = 0;
   1.112 +         while (length){
   1.113 +
   1.114 +             ValueType value = *first;
   1.115 +             while (value) {
   1.116 +                 num += count_table<>::table[value & ((1u<<table_width) - 1)];
   1.117 +                 value >>= table_width;
   1.118 +             }
   1.119 +
   1.120 +             ++first;
   1.121 +             --length;
   1.122 +         }
   1.123 +
   1.124 +         return num;
   1.125 +     }
   1.126 +
   1.127 +
   1.128 +    } // dynamic_bitset_count_impl
   1.129 +    // -------------------------------------------------------
   1.130 +
   1.131 +
   1.132 +    // Some library implementations simply return a dummy
   1.133 +    // value such as
   1.134 +    //
   1.135 +    //   size_type(-1) / sizeof(T)
   1.136 +    //
   1.137 +    // from vector<>::max_size. This tries to get out more
   1.138 +    // meaningful info.
   1.139 +    //
   1.140 +    template <typename T>
   1.141 +    typename T::size_type vector_max_size_workaround(const T & v) {
   1.142 +
   1.143 +      typedef typename T::allocator_type allocator_type;
   1.144 +
   1.145 +      const typename allocator_type::size_type alloc_max =
   1.146 +                                                  v.get_allocator().max_size();
   1.147 +      const typename T::size_type container_max = v.max_size();
   1.148 +
   1.149 +      return alloc_max < container_max?
   1.150 +                    alloc_max :
   1.151 +                    container_max;
   1.152 +    }
   1.153 +
   1.154 +    // for static_asserts
   1.155 +    template <typename T>
   1.156 +    struct dynamic_bitset_allowed_block_type {
   1.157 +        enum { value = (T(-1) > 0) }; // ensure T has no sign
   1.158 +    };
   1.159 +
   1.160 +    template <>
   1.161 +    struct dynamic_bitset_allowed_block_type<bool> {
   1.162 +        enum { value = false };
   1.163 +    };
   1.164 +
   1.165 +
   1.166 +  } // namespace detail
   1.167 +
   1.168 +} // namespace boost
   1.169 +
   1.170 +#endif // include guard
   1.171 +