gtkIOStream
1.7.0
GTK+ << C++ IOStream operators for GTK+. Now with ORBing, numerical computation, audio client and more ...
|
#include <BitStream.H>
Public Member Functions | |
BitStream () | |
Constructor. More... | |
virtual | ~BitStream () |
Destructor. More... | |
std::vector< VTYPE >::size_type | size () const |
float | byteSize () const |
template<typename T > | |
T | reverseBits (T bits) const |
template<typename T > | |
T | reverseBits (T bits, unsigned int N) const |
template<typename T > | |
BitStream & | operator<< (T bits) |
template<typename T > | |
BitStream & | push_back (const T bits, const int N) |
template<typename T > | |
T | pop_back (const unsigned int N) |
template<typename T > | |
T | pop_front (const unsigned int N) |
BitStream & | rotateL (const unsigned int N) |
BitStream & | rotateR (const unsigned int N) |
std::ostream & | hexDump (std::ostream &stream) |
void | clear () |
int | reserve (std::vector< VTYPE >::size_type N) |
std::vector< VTYPE >::size_type | capacity () const |
void | dump (void) |
void | dumpHex (void) |
template<typename T > | |
T | getBits (std::vector< VTYPE >::size_type i, unsigned int N) const |
template<typename T > | |
T | operator[] (std::vector< VTYPE >::size_type i) const |
template<typename T > | |
std::vector< std::vector< VTYPE >::size_type > | find (T toFind, const unsigned int N) const |
std::vector< std::vector< VTYPE >::size_type > | find (BitStream toFind, const unsigned int N) const |
Protected Types | |
typedef unsigned int | VTYPE |
Use this type for the basic stream type. More... | |
Protected Member Functions | |
void | testMask (unsigned int mSize) const |
void | testMask (unsigned int mSize, VTYPE compareAgainst) const |
VTYPE | genMask (int M) const |
Private Member Functions | |
BitStream & | push_backVType (const VTYPE *tempBits, int N, const int sizeOfT) |
unsigned int | VTYPEBits () const |
unsigned int | takenBits () const |
VTYPE | maskBitsToRight (const unsigned int M, const VTYPE &bits) const |
VTYPE | maskOffsetBitsToRight (const unsigned int M, const unsigned int offset, const VTYPE &bits) const |
VTYPE | maskBitsToLeft (const unsigned int M, const VTYPE bits) const |
void | reverseBits (unsigned char *bits, const unsigned int N) const |
VTYPE | shiftLeftSubword (std::vector< VTYPE >::iterator firstWord, std::vector< VTYPE >::iterator lastWord, const unsigned int N) |
VTYPE | shiftRightSubword (std::vector< VTYPE >::iterator firstWord, std::vector< VTYPE >::iterator lastWord, const unsigned int N) |
Private Attributes | |
std::vector< VTYPE > | data |
The array to hold the bitstream. More... | |
int | freeBits |
The number of free bits in the array. More... | |
Static Private Attributes | |
static const unsigned char | revChars [] = {0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255} |
Characters reversed. 8 bit reversals. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &stream, const BitStream &bitStream) |
Create bit streams using this class.
This stream is packed with the oldest entries at the beginning, newest entries added to the end. I.e. push_back. The front is the beginning and the back is the end. The char 0x 80 for example, will be packed as 0b 1000 0000.
In general MSBs are regarded as being on the 'left' and LSBs are regarded as being on the 'right'.
If you push_back in more bits then the data type you provide, leading zeros will be added, for example : If you pack 9 bits from a char, 0x8 again, you get : 0100 0000 0
Here are some examples :
short s=0b1111010100001010; short s2=0b1100110011110000; int i3=0x1f2f3f4f;
bitStream.push_back(s,4); // add specific bits from a variable cout<<bitStream<<endl; cout<<(bitset<4>)s<<'
'<<endl;
bitStream.push_back(s2,16); cout<<bitStream<<endl; cout<<(bitset<4>)s<<(bitset<16>)s2<<'
'<<endl;
bitStream<<i3; // add all bits from a variable cout<<bitStream<<endl; cout<<(bitset<4>)s<<(bitset<16>)s2<<(bitset<32>)i3<<'
'<<endl;
to get leading zeros, increase the number of bits to push_back. For example, for a char c : bitsStream.push_back(c, 10); This will add two leading zeros. <>
Outputs the following;
1010 1010
10101100110011110000 10101100110011110000
1010110011001111000000011111001011110011111101001111 1010110011001111000000011111001011110011111101001111 <>
Definition at line 83 of file BitStream.H.
|
protected |
Use this type for the basic stream type.
Definition at line 85 of file BitStream.H.
BitStream::BitStream | ( | ) |
Constructor.
Definition at line 29 of file BitStream.C.
|
virtual |
float BitStream::byteSize | ( | ) | const |
How many bytes in the stream.
Definition at line 43 of file BitStream.C.
std::vector< BitStream::VTYPE >::size_type BitStream::capacity | ( | ) | const |
Return the capacity (in bits) of the bitstream
Definition at line 199 of file BitStream.C.
void BitStream::clear | ( | ) |
Clear the BitStream to an empty state.
Definition at line 182 of file BitStream.C.
void BitStream::dump | ( | void | ) |
print out with spaces between vector words ... good for debugging.
Definition at line 218 of file BitStream.C.
void BitStream::dumpHex | ( | void | ) |
print out with spaces between vector words ... good for debugging. The last word is printed including the freeBits
Definition at line 232 of file BitStream.C.
|
inline |
Search through the bits of the contained data.
toFind | The bits to find in this BitStream |
N | the number of LSBs to use from the variable toFind. |
Definition at line 435 of file BitStream.H.
std::vector< std::vector< BitStream::VTYPE >::size_type > BitStream::find | ( | BitStream | toFind, |
const unsigned int | N | ||
) | const |
Search through the bits of the contained data.
toFind | The bitStream to find in this BitStream |
N | the number of bits to use from the variable toFind. |
Definition at line 244 of file BitStream.C.
|
inlineprotected |
Generate an M bit mask.
Definition at line 215 of file BitStream.H.
|
inline |
Get bits from the stream. Location starting i, the number of bits is sizeof(T)*CHAR_BIT.
i | The location to retrieve from. |
N | The number of bits to retrieve. |
T | The type to return the bits in. |
Definition at line 402 of file BitStream.H.
std::ostream & BitStream::hexDump | ( | std::ostream & | stream | ) |
Output the bit sequence in hexadecimal format.
stream | The ostream to output to. |
Definition at line 174 of file BitStream.C.
Get the last M bits from a word. Returns these bits left shifted so to the MSB location.
M | The number of bits to get. |
bits | The bits to get the M bits from. |
Definition at line 173 of file BitStream.H.
Get the first M bits from a word. Returns these bits right shifted so to the LSB location.
M | The number of bits to get. |
bits | The bits to get the M bits from. |
Definition at line 150 of file BitStream.H.
|
inlineprivate |
Get M bits from a word, with an offset from the MSB. Returns these bits right shifted so to the LSB location.
M | The number of bits to get. |
offset | The number of bits from the MSB in to get the bits from. |
bits | The bits to get the M bits from. |
Definition at line 162 of file BitStream.H.
|
inline |
Add a simple type to the bit stream.
bits | The data to add to the stream. |
T | The type of the data. |
Definition at line 279 of file BitStream.H.
|
inline |
Get bits from the stream. Location starting i, the number of bits is sizeof(T)*CHAR_BIT.
i | The location to retrieve from. |
T | The type to return the bits in. |
Definition at line 425 of file BitStream.H.
|
inline |
Pop N bits from the end of the stream.
If the requested bit count (N) is larger then the provided return type, then only sizeof(T)*8 bits are poped from the back.
N | The number of bits to pop. |
T | The type of the data to return. |
Definition at line 308 of file BitStream.H.
|
inline |
Pop N bits from the front of the stream.
If the requested bit count (N) is larger then the provided return type, then only sizeof(T)*8 bits are poped from the front.
N | The number of bits to pop. |
T | The type of the data to return. |
Definition at line 340 of file BitStream.H.
|
inline |
Pack some bits at the end of the stream. The input variables N least significant bits are packed into the stream.
bits | the variable to get bits from in order to fill the bit stream |
N | The number of bits >0 to store. |
T | The type of input bit variable |
Definition at line 292 of file BitStream.H.
Pack some bits at the end of the stream. The input variables N least significant bits are packed into the stream.
tempBits | A pointer to the vector of bits to store. |
N | The number of bits to store >0 |
sizeOfT | The size of the type of the original variable from the templated method push_back_back |
Definition at line 47 of file BitStream.C.
int BitStream::reserve | ( | std::vector< VTYPE >::size_type | N | ) |
Resize the underlying data structure to have enough memory to store N bits.
N | The number of bits to store. |
Definition at line 187 of file BitStream.C.
|
inlineprivate |
Reverse the provided bits in the character array.
This bit reverse method uses an 8 bit hash lookup table to reverse the bits in a very fast manner.
bits | the variable to bit reverse. |
N | The number of char to reverse. |
Definition at line 185 of file BitStream.H.
|
inline |
Reverse all of the provided bits.
This bit reverse method uses an 8 bit hash lookup table to reverse the bits in a very fast manner.
bits | the variable to bit reverse. All of the bits are reversed. |
T | The type of input bit variable |
Definition at line 252 of file BitStream.H.
|
inline |
Reverse a subset of the provided bits (possibly all of the bits).
This bit reverse method uses an 8 bit hash lookup table to reverse the bits in a very fast manner.
bits | the variable to bit reverse. Some or all of the bits are reversed, depending on N, the number of bits to reverse requested. |
N | The number of bits >0 to store. |
T | The type of input bit variable |
Definition at line 265 of file BitStream.H.
BitStream & BitStream::rotateL | ( | const unsigned int | N | ) |
Rotate the stream to the left, left most bits are rotated to the right as required.
N | The number of bits to rotate left by. |
Definition at line 97 of file BitStream.C.
BitStream & BitStream::rotateR | ( | const unsigned int | N | ) |
Rotate the stream to the right, right most bits are rotated to the right as required.
N | The number of bits to rotate left by. |
Definition at line 145 of file BitStream.C.
|
private |
Shift left by N sub-word length bits, returning the left most N bits.
firstWord | The first word to be shifted left, its left most bits are returned in the LSB location |
lastWord | The last word to be shifted left, its right most bits are zero upon return. |
Definition at line 80 of file BitStream.C.
|
private |
Shift right by N sub-word length bits, returning the right most (lest significant) N bits shifted to the MSB location.
firstWord | The first word to be shifted right, its left most bits are zeroed on return. |
lastWord | The last word to be shifted left, its right most bits are returned in the MSB location |
Definition at line 126 of file BitStream.C.
std::vector< BitStream::VTYPE >::size_type BitStream::size | ( | ) | const |
How many bits in the stream.
Definition at line 39 of file BitStream.C.
|
inlineprivate |
The number of bits used (taken) in the last word.
Definition at line 141 of file BitStream.H.
|
inlineprotected |
When debugging this method can be executed to test that the mask is being generated correctly.
mSize | The mask size in bits |
Definition at line 90 of file BitStream.H.
|
inlineprotected |
When debugging this method can be executed to test that the mask is being generated correctly.
mSize | The mask size in bits |
compareAgainst | The pre-generated mask to compare against. |
Definition at line 100 of file BitStream.H.
|
inlineprivate |
The number of bits in the base data type.
Definition at line 134 of file BitStream.H.
|
friend |
Overload the ostream operator for printing. This method outputs the string representation of the bit stream.
stream | The ostream to output the bitstream to. |
iob | The iobitstream to output. |
Definition at line 204 of file BitStream.C.
|
private |
The array to hold the bitstream.
Definition at line 116 of file BitStream.H.
|
private |
The number of free bits in the array.
Definition at line 117 of file BitStream.H.
|
staticprivate |
Characters reversed. 8 bit reversals.
Definition at line 120 of file BitStream.H.
GTK+ IOStream
Beta
|