|
9 | 9 |
|
10 | 10 | #include "bitreader/bitreader-utils.hpp" |
11 | 11 | #include "common/numeric.hpp" |
| 12 | +#include "data_source/byte_source.hpp" |
12 | 13 |
|
13 | 14 | namespace brcpp { |
14 | 15 |
|
15 | 16 |
|
16 | 17 | //-------------------------------------------------------------------------- |
17 | | - template<typename Source> |
| 18 | + template<byte_source Source> |
18 | 19 | class bitreader { |
19 | 20 | public: |
20 | 21 | bitreader(std::shared_ptr<Source> source) |
@@ -101,8 +102,7 @@ namespace brcpp { |
101 | 102 | T read(size_t bits) |
102 | 103 | { |
103 | 104 | using value_type = std::underlying_type_t<T>; |
104 | | - auto val = static_cast<T>(read<value_type>(bits)); |
105 | | - return val; |
| 105 | + return static_cast<T>(read<value_type>(bits)); |
106 | 106 | } |
107 | 107 |
|
108 | 108 | //---------------------------------------------------------------------- |
@@ -146,25 +146,18 @@ namespace brcpp { |
146 | 146 | }; |
147 | 147 |
|
148 | 148 | //---------------------------------------------------------------------- |
149 | | - template<signed_integral T> |
150 | | - T _sign_extend(T raw, size_t bits) |
151 | | - { |
152 | | - const auto m = static_cast<T>(one<T> << (bits - 1)); |
153 | | - return (raw ^ m) - m; |
154 | | - } |
155 | | - |
156 | | - //---------------------------------------------------------------------- |
157 | | - template<unsigned_integral T> |
158 | | - T _sign_extend(T raw, size_t bits) |
159 | | - { |
160 | | - return raw; |
161 | | - } |
162 | | - |
163 | | - //---------------------------------------------------------------------- |
164 | | - template<floating_point T> |
| 149 | + template<bit_readable T> |
165 | 150 | T _sign_extend(T raw, size_t bits) |
166 | 151 | { |
167 | | - return raw; |
| 152 | + if constexpr (signed_integral<T>) |
| 153 | + { |
| 154 | + const auto m = static_cast<T>(one<T> << (bits - 1)); |
| 155 | + return (raw ^ m) - m; |
| 156 | + } |
| 157 | + else |
| 158 | + { |
| 159 | + return raw; |
| 160 | + } |
168 | 161 | } |
169 | 162 |
|
170 | 163 | //---------------------------------------------------------------------- |
|
0 commit comments