00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef BOOST_DETAIL_DYNAMIC_BITSET_HPP
00016 #define BOOST_DETAIL_DYNAMIC_BITSET_HPP
00017
00018 #include <cstddef>
00019 #include "sysc/packages/boost/config.hpp"
00020 #include "sysc/packages/boost/detail/workaround.hpp"
00021
00022
00023
00024 namespace boost {
00025
00026 namespace detail {
00027
00028
00029
00030
00031
00032 template <typename T>
00033 inline const unsigned char * object_representation (T* p)
00034 {
00035 return static_cast<const unsigned char *>(static_cast<const void *>(p));
00036 }
00037
00038
00039
00040
00041 namespace dynamic_bitset_count_impl {
00042
00043 typedef unsigned char byte_type;
00044
00045 enum mode { access_by_bytes, access_by_blocks };
00046
00047 template <mode> struct mode_to_type {};
00048
00049
00050
00051
00052 template <bool dummy_name = true>
00053 struct count_table { static const byte_type table[]; };
00054
00055 template <>
00056 struct count_table<false> { };
00057
00058
00059 const unsigned int table_width = 8;
00060 template <bool b>
00061 const byte_type count_table<b>::table[] =
00062 {
00063
00064
00065 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,
00066 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,
00067 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,
00068 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,
00069 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,
00070 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,
00071 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,
00072 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
00073 };
00074
00075
00076
00077
00078
00079 template <typename Iterator>
00080 inline std::size_t do_count(Iterator first, std::size_t length,
00081 int ,
00082 mode_to_type<access_by_bytes>* )
00083 {
00084 std::size_t num = 0;
00085 if (length)
00086 {
00087 const byte_type * p = object_representation(&*first);
00088 length *= sizeof(*first);
00089
00090 do {
00091 num += count_table<>::table[*p];
00092 ++p;
00093 --length;
00094
00095 } while (length);
00096 }
00097
00098 return num;
00099 }
00100
00101
00102
00103
00104 template <typename Iterator, typename ValueType>
00105 inline std::size_t do_count(Iterator first, std::size_t length, ValueType,
00106 mode_to_type<access_by_blocks>*)
00107 {
00108 std::size_t num = 0;
00109 while (length){
00110
00111 ValueType value = *first;
00112 while (value) {
00113 num += count_table<>::table[value & ((1u<<table_width) - 1)];
00114 value >>= table_width;
00115 }
00116
00117 ++first;
00118 --length;
00119 }
00120
00121 return num;
00122 }
00123
00124
00125 }
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137 template <typename T>
00138 typename T::size_type vector_max_size_workaround(const T & v) {
00139
00140 typedef typename T::allocator_type allocator_type;
00141
00142 const typename allocator_type::size_type alloc_max =
00143 v.get_allocator().max_size();
00144 const typename T::size_type container_max = v.max_size();
00145
00146 return alloc_max < container_max?
00147 alloc_max :
00148 container_max;
00149 }
00150
00151
00152 template <typename T>
00153 struct dynamic_bitset_allowed_block_type {
00154 enum { value = T(-1) > 0 };
00155 };
00156
00157 template <>
00158 struct dynamic_bitset_allowed_block_type<bool> {
00159 enum { value = false };
00160 };
00161
00162
00163 }
00164
00165 }
00166
00167 #endif // include guard
00168