unrarsrc  6.1.7
About: unrar extracts, views and tests the contents of archives created with the RAR archiver.
  Fossies Dox: unrarsrc-6.1.7.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

getbits.cpp
Go to the documentation of this file.
1#include "rar.hpp"
2
3BitInput::BitInput(bool AllocBuffer)
4{
5 ExternalBuffer=false;
6 if (AllocBuffer)
7 {
8 // getbits32 attempts to read data from InAddr, ... InAddr+3 positions.
9 // So let's allocate 3 additional bytes for situation, when we need to
10 // read only 1 byte from the last position of buffer and avoid a crash
11 // from access to next 3 bytes, which contents we do not need.
12 size_t BufSize=MAX_SIZE+3;
13 InBuf=new byte[BufSize];
14
15 // Ensure that we get predictable results when accessing bytes in area
16 // not filled with read data.
17 memset(InBuf,0,BufSize);
18 }
19 else
20 InBuf=NULL;
21}
22
23
25{
26 if (!ExternalBuffer)
27 delete[] InBuf;
28}
29
30
32{
33 // Function wrapped version of inline addbits to save code size.
34 addbits(Bits);
35}
36
37
39{
40 // Function wrapped version of inline getbits to save code size.
41 return getbits();
42}
43
44
46{
47 if (InBuf!=NULL && !ExternalBuffer)
48 delete[] InBuf;
49 InBuf=Buf;
50 ExternalBuffer=true;
51}
52
BitInput(bool AllocBuffer)
Definition: getbits.cpp:3
bool ExternalBuffer
Definition: getbits.hpp:12
uint fgetbits()
Definition: getbits.cpp:38
uint getbits()
Definition: getbits.hpp:34
@ MAX_SIZE
Definition: getbits.hpp:7
void addbits(uint Bits)
Definition: getbits.hpp:25
~BitInput()
Definition: getbits.cpp:24
void SetExternalBuffer(byte *Buf)
Definition: getbits.cpp:45
void faddbits(uint Bits)
Definition: getbits.cpp:31
byte * InBuf
Definition: getbits.hpp:17
unsigned int uint
Definition: rartypes.hpp:8