1 #include "BitStream.h"
2 
3 using namespace Framework;
4 
TryGetBits_LSBF(uint8 size,uint32 & result)5 bool CBitStream::TryGetBits_LSBF(uint8 size, uint32& result)
6 {
7 	if(!TryPeekBits_LSBF(size, result)) return false;
8 	Advance(size);
9 	return true;
10 }
11 
TryGetBits_MSBF(uint8 size,uint32 & result)12 bool CBitStream::TryGetBits_MSBF(uint8 size, uint32& result)
13 {
14 	if(!TryPeekBits_MSBF(size, result)) return false;
15 	Advance(size);
16 	return true;
17 }
18 
GetBits_LSBF(uint8 size)19 uint32 CBitStream::GetBits_LSBF(uint8 size)
20 {
21 	uint32 result = 0;
22 	if(!TryGetBits_LSBF(size, result))
23 	{
24 		throw CBitStreamException();
25 	}
26 	return result;
27 }
28 
GetBits_MSBF(uint8 size)29 uint32 CBitStream::GetBits_MSBF(uint8 size)
30 {
31 	uint32 result = 0;
32 	if(!TryGetBits_MSBF(size, result))
33 	{
34 		throw CBitStreamException();
35 	}
36 	return result;
37 }
38 
PeekBits_LSBF(uint8 size)39 uint32 CBitStream::PeekBits_LSBF(uint8 size)
40 {
41 	uint32 result = 0;
42 	if(!TryPeekBits_LSBF(size, result))
43 	{
44 		throw CBitStreamException();
45 	}
46 	return result;
47 }
48 
PeekBits_MSBF(uint8 size)49 uint32 CBitStream::PeekBits_MSBF(uint8 size)
50 {
51 	uint32 result = 0;
52 	if(!TryPeekBits_MSBF(size, result))
53 	{
54 		throw CBitStreamException();
55 	}
56 	return result;
57 }
58 
SeekToByteAlign()59 void CBitStream::SeekToByteAlign()
60 {
61 	unsigned int remainder = GetBitIndex() & 0x07;
62 	if(remainder == 0) return;
63 	Advance(8 - remainder);
64 }
65 
IsOnByteBoundary() const66 bool CBitStream::IsOnByteBoundary() const
67 {
68 	return (GetBitIndex() == 0);
69 }