Shadowrun: Awakened 29 September 2011 - Build 871
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
cat::BitStream Class Reference

#include <BitStream.hpp>

List of all members.

Public Member Functions

bool aligned ()
 BitStream (u32 bytes=0, void *vbuffer=0)
u8get ()
BitStreamoperator<< (const char *data)
template<class T >
BitStreamoperator<< (T data)
template<u32 N_BITS>
BitStreamoperator<< (const bs_bit::set< N_BITS > &n)
template<>
BitStreamoperator<< (const bs_bit::set< 1 > &n)
template<>
BitStreamoperator<< (const bs_bit::set< 8 > &n)
template<>
BitStreamoperator<< (const bs_bit::set< 16 > &n)
template<>
BitStreamoperator<< (const bs_bit::set< 32 > &n)
BitStreamoperator<< (const bs_byte::set &n)
template<class T >
BitStreamoperator>> (T &data)
template<u32 N_BITS>
BitStreamoperator>> (const bs_bit::get< N_BITS > &n)
template<>
BitStreamoperator>> (const bs_bit::get< 1 > &n)
template<>
BitStreamoperator>> (const bs_bit::get< 8 > &n)
template<>
BitStreamoperator>> (const bs_bit::get< 16 > &n)
template<>
BitStreamoperator>> (const bs_bit::get< 32 > &n)
BitStreamoperator>> (const bs_byte::get &n)
u8peek ()
template<class T >
T read ()
template<>
void read (double &data)
template<class T >
void read (T &data)
template<>
void read (float &data)
u8 read1 ()
u32 readBits (u32 count)
void readBytes (void *data, u32 byte_count)
void shrink ()
void skip (u32 bits)
bool underrun ()
int unread ()
bool valid ()
template<class T >
void write (T data)
template<>
void write (double data)
template<>
void write (s8 data)
template<>
void write (s64 data)
template<>
void write (float data)
template<>
void write (s16 data)
template<>
void write (s32 data)
void write1 (u8 data)
void writeBits (u32 data, int count)
void writeBytes (const void *data, u32 byte_count)
 ~BitStream ()

Public Attributes

u32 read_offset
u32 write_offset

Private Member Functions

void grow (u32 bits)

Private Attributes

u8buffer
u32 buffer_bytes
bool fixed_buffer
bool read_underrun

Detailed Description

Definition at line 81 of file BitStream.hpp.


Constructor & Destructor Documentation

cat::BitStream::BitStream ( u32  bytes = 0,
void *  vbuffer = 0 
)
cat::BitStream::~BitStream ( )

Member Function Documentation

bool cat::BitStream::aligned ( ) [inline]

Definition at line 104 of file BitStream.hpp.

References read_offset.

{ return read_offset % 8 == 0; }
u8* cat::BitStream::get ( ) [inline]

Definition at line 102 of file BitStream.hpp.

References buffer.

{ return buffer; }
void cat::BitStream::grow ( u32  bits) [private]

Referenced by write().

BitStream& cat::BitStream::operator<< ( const char *  data) [inline]

Definition at line 154 of file BitStream.hpp.

References writeBytes().

{ writeBytes(data, (u32)strlen(data)); return *this; }
template<class T >
BitStream& cat::BitStream::operator<< ( T  data) [inline]

Definition at line 156 of file BitStream.hpp.

References write().

{ write(data); return *this; }
template<u32 N_BITS>
BitStream& cat::BitStream::operator<< ( const bs_bit::set< N_BITS > &  n) [inline]

Definition at line 158 of file BitStream.hpp.

References writeBits().

{ writeBits(n.bits, N_BITS); return *this; }
template<>
BitStream& cat::BitStream::operator<< ( const bs_bit::set< 1 > &  n) [inline]

Definition at line 159 of file BitStream.hpp.

References write1().

{ write1((u8)n.bits); return *this; }
template<>
BitStream& cat::BitStream::operator<< ( const bs_bit::set< 8 > &  n) [inline]

Definition at line 160 of file BitStream.hpp.

References write().

{ write((u8)n.bits); return *this; }
template<>
BitStream& cat::BitStream::operator<< ( const bs_bit::set< 16 > &  n) [inline]

Definition at line 161 of file BitStream.hpp.

References write().

{ write((u16)n.bits); return *this; }
template<>
BitStream& cat::BitStream::operator<< ( const bs_bit::set< 32 > &  n) [inline]

Definition at line 162 of file BitStream.hpp.

References write().

{ write((u32)n.bits); return *this; }
BitStream& cat::BitStream::operator<< ( const bs_byte::set n) [inline]

Definition at line 164 of file BitStream.hpp.

References cat::bs_byte::set::bytes, cat::bs_byte::set::ref, and writeBytes().

{ writeBytes(n.ref, n.bytes); return *this; }
template<class T >
BitStream& cat::BitStream::operator>> ( T data) [inline]

Definition at line 199 of file BitStream.hpp.

References read().

{ read(data); return *this; }
template<u32 N_BITS>
BitStream& cat::BitStream::operator>> ( const bs_bit::get< N_BITS > &  n) [inline]

Definition at line 201 of file BitStream.hpp.

References readBits(), and cat::bs_bit::get< N_BITS >::ref.

{ n.ref = readBits(N_BITS); return *this; }
template<>
BitStream& cat::BitStream::operator>> ( const bs_bit::get< 1 > &  n) [inline]

Definition at line 202 of file BitStream.hpp.

References read1(), and cat::bs_bit::get< N_BITS >::ref.

{ n.ref = read1(); return *this; }
template<>
BitStream& cat::BitStream::operator>> ( const bs_bit::get< 8 > &  n) [inline]

Definition at line 203 of file BitStream.hpp.

References cat::bs_bit::get< N_BITS >::ref.

{ n.ref = read<u8>(); return *this; }
BitStream& cat::BitStream::operator>> ( const bs_byte::get n) [inline]

Definition at line 207 of file BitStream.hpp.

References cat::bs_byte::get::bytes, readBytes(), and cat::bs_byte::get::ref.

{ readBytes(n.ref, n.bytes); return *this; }
template<>
BitStream& cat::BitStream::operator>> ( const bs_bit::get< 32 > &  n) [inline]

Definition at line 205 of file BitStream.hpp.

References read(), and cat::bs_bit::get< N_BITS >::ref.

{ read(n.ref); return *this; }
template<>
BitStream& cat::BitStream::operator>> ( const bs_bit::get< 16 > &  n) [inline]

Definition at line 204 of file BitStream.hpp.

References cat::bs_bit::get< N_BITS >::ref.

{ n.ref = read<u16>(); return *this; }
u8* cat::BitStream::peek ( ) [inline]

Definition at line 105 of file BitStream.hpp.

References buffer, and read_offset.

{ return buffer + read_offset / 8; }
template<class T >
T cat::BitStream::read ( ) [inline]

Definition at line 192 of file BitStream.hpp.

References read(), and T.

Referenced by operator>>(), and read().

{ T temp; read(temp); return temp; }
template<class T >
void cat::BitStream::read ( T data) [inline]

Definition at line 170 of file BitStream.hpp.

References buffer, read_offset, read_underrun, T, and write_offset.

    {
        const u32 bits = sizeof(T) * 8;

        if (read_offset + bits > write_offset)
        {
            read_underrun = true;
            return;
        }

        u32 byte_offset = read_offset / 8;
        u32 shift = read_offset % 8;

        if (shift)
            data = (*(T*)(buffer + byte_offset + 1) << (8 - shift)) | (buffer[byte_offset] >> shift);
        else
            data = *(T*)(buffer + byte_offset);

        read_offset += bits;
    }
template<>
void cat::BitStream::read ( float data) [inline]

Definition at line 190 of file BitStream.hpp.

References read().

Referenced by read().

{ read((u32&)data); }
template<>
void cat::BitStream::read ( double &  data) [inline]

Definition at line 191 of file BitStream.hpp.

References write().

{ write(*(u64*)&data); }
u8 cat::BitStream::read1 ( )

Referenced by operator>>().

u32 cat::BitStream::readBits ( u32  count)

Referenced by operator>>().

void cat::BitStream::readBytes ( void *  data,
u32  byte_count 
)

Referenced by operator>>().

void cat::BitStream::shrink ( )
void cat::BitStream::skip ( u32  bits)
bool cat::BitStream::underrun ( )
int cat::BitStream::unread ( ) [inline]

Definition at line 112 of file BitStream.hpp.

References read_offset, and write_offset.

{ return write_offset - read_offset; }
bool cat::BitStream::valid ( ) [inline]

Definition at line 109 of file BitStream.hpp.

References buffer.

{ return buffer != 0; }
template<>
void cat::BitStream::write ( double  data) [inline]

Definition at line 147 of file BitStream.hpp.

References write().

Referenced by write().

{ write(*(u64*)&data); }
template<class T >
void cat::BitStream::write ( T  data) [inline]

Definition at line 124 of file BitStream.hpp.

References buffer, grow(), T, and write_offset.

Referenced by operator<<(), and read().

    {
        grow(sizeof(T) * 8);

        u32 byte_offset = write_offset / 8;
        u32 shift = write_offset % 8;

        if (shift)
        {
            buffer[byte_offset] |= (u8)(data << shift);
            data = data >> (8 - shift);
            ++byte_offset;
        }

        *(T*)(buffer + byte_offset) = data;

        write_offset += sizeof(T) * 8;
    }
template<>
void cat::BitStream::write ( s8  data) [inline]

Definition at line 142 of file BitStream.hpp.

References write().

Referenced by write().

{ write((u8)data); }
template<>
void cat::BitStream::write ( s64  data) [inline]

Definition at line 145 of file BitStream.hpp.

References write().

Referenced by write().

{ write((u64)data); }
template<>
void cat::BitStream::write ( s32  data) [inline]

Definition at line 144 of file BitStream.hpp.

References write().

Referenced by write().

{ write((u32)data); }
template<>
void cat::BitStream::write ( s16  data) [inline]

Definition at line 143 of file BitStream.hpp.

References write().

Referenced by write().

{ write((u16)data); }
template<>
void cat::BitStream::write ( float  data) [inline]

Definition at line 146 of file BitStream.hpp.

References write().

Referenced by write().

{ write(*(u32*)&data); }
void cat::BitStream::write1 ( u8  data)

Referenced by operator<<().

void cat::BitStream::writeBits ( u32  data,
int  count 
)

Referenced by operator<<().

void cat::BitStream::writeBytes ( const void *  data,
u32  byte_count 
)

Referenced by operator<<().


Member Data Documentation

Definition at line 84 of file BitStream.hpp.

Referenced by get(), peek(), read(), valid(), and write().

Definition at line 85 of file BitStream.hpp.

Definition at line 83 of file BitStream.hpp.

Definition at line 92 of file BitStream.hpp.

Referenced by aligned(), peek(), read(), and unread().

Definition at line 86 of file BitStream.hpp.

Referenced by read().

Definition at line 92 of file BitStream.hpp.

Referenced by read(), unread(), and write().


The documentation for this class was generated from the following file:

Copyright © 2007-2010 by The Shadowrun: Awakened Team. This work is licensed under the GNU Lesser General Public License 3.

GNU Lesser General Public License 3 Sourceforge.net