Rename all member variables to follow the style guidelines (prefixed with the 'm') - class BitStream

This commit is contained in:
bank 2014-05-13 18:25:47 +04:00
parent d6b003e508
commit 3e21f5f677
2 changed files with 81 additions and 81 deletions

View file

@ -78,18 +78,18 @@ ResizeBitStream::ResizeBitStream(U32 minSpace, U32 initialSize) : BitStream(NULL
ResizeBitStream::~ResizeBitStream() ResizeBitStream::~ResizeBitStream()
{ {
dFree(dataPtr); dFree(mDataPtr);
} }
void ResizeBitStream::validate() void ResizeBitStream::validate()
{ {
if(getPosition() + mMinSpace > bufSize) if(getPosition() + mMinSpace > mBufSize)
{ {
bufSize = getPosition() + mMinSpace * 2; mBufSize = getPosition() + mMinSpace * 2;
dataPtr = (U8 *) dRealloc(dataPtr, bufSize); mDataPtr = (U8 *) dRealloc(mDataPtr, mBufSize);
maxReadBitNum = bufSize << 3; mMaxReadBitNum = mBufSize << 3;
maxWriteBitNum = bufSize << 3; mMaxWriteBitNum = mBufSize << 3;
} }
} }
@ -148,53 +148,53 @@ HuffmanProcessor HuffmanProcessor::g_huffProcessor;
void BitStream::setBuffer(void *bufPtr, S32 size, S32 maxSize) void BitStream::setBuffer(void *bufPtr, S32 size, S32 maxSize)
{ {
dataPtr = (U8 *) bufPtr; mDataPtr = (U8 *) bufPtr;
bitNum = 0; mBitNum = 0;
bufSize = size; mBufSize = size;
maxReadBitNum = size << 3; mMaxReadBitNum = size << 3;
if(maxSize < 0) if(maxSize < 0)
maxSize = size; maxSize = size;
maxWriteBitNum = maxSize << 3; mMaxWriteBitNum = maxSize << 3;
error = false; mError = false;
clearCompressionPoint(); clearCompressionPoint();
} }
U32 BitStream::getPosition() const U32 BitStream::getPosition() const
{ {
return (bitNum + 7) >> 3; return (mBitNum + 7) >> 3;
} }
bool BitStream::setPosition(const U32 pos) bool BitStream::setPosition(const U32 pos)
{ {
bitNum = pos << 3; mBitNum = pos << 3;
return (true); return (true);
} }
U32 BitStream::getStreamSize() U32 BitStream::getStreamSize()
{ {
return bufSize; return mBufSize;
} }
U8 *BitStream::getBytePtr() U8 *BitStream::getBytePtr()
{ {
return dataPtr + getPosition(); return mDataPtr + getPosition();
} }
U32 BitStream::getReadByteSize() U32 BitStream::getReadByteSize()
{ {
return (maxReadBitNum >> 3) - getPosition(); return (mMaxReadBitNum >> 3) - getPosition();
} }
U32 BitStream::getWriteByteSize() U32 BitStream::getWriteByteSize()
{ {
return (maxWriteBitNum >> 3) - getPosition(); return (mMaxWriteBitNum >> 3) - getPosition();
} }
void BitStream::clear() void BitStream::clear()
{ {
dMemset(dataPtr, 0, bufSize); dMemset(mDataPtr, 0, mBufSize);
} }
void BitStream::writeClassId(U32 classId, U32 classType, U32 classGroup) void BitStream::writeClassId(U32 classId, U32 classType, U32 classGroup)
@ -228,9 +228,9 @@ void BitStream::writeBits(S32 bitCount, const void *bitPtr)
if(!bitCount) if(!bitCount)
return; return;
if(bitCount + bitNum > maxWriteBitNum) if(bitCount + mBitNum > mMaxWriteBitNum)
{ {
error = true; mError = true;
AssertFatal(false, "Out of range write"); AssertFatal(false, "Out of range write");
return; return;
} }
@ -242,39 +242,39 @@ void BitStream::writeBits(S32 bitCount, const void *bitPtr)
for(S32 srcBitNum = 0;srcBitNum < bitCount;srcBitNum++) for(S32 srcBitNum = 0;srcBitNum < bitCount;srcBitNum++)
{ {
if((*(ptr + (srcBitNum >> 3)) & (1 << (srcBitNum & 0x7))) != 0) if((*(ptr + (srcBitNum >> 3)) & (1 << (srcBitNum & 0x7))) != 0)
*(dataPtr + (bitNum >> 3)) |= (1 << (bitNum & 0x7)); *(mDataPtr + (mBitNum >> 3)) |= (1 << (mBitNum & 0x7));
else else
*(dataPtr + (bitNum >> 3)) &= ~(1 << (bitNum & 0x7)); *(mDataPtr + (mBitNum >> 3)) &= ~(1 << (mBitNum & 0x7));
bitNum++; mBitNum++;
} }
} }
void BitStream::setBit(S32 bitCount, bool set) void BitStream::setBit(S32 bitCount, bool set)
{ {
if(set) if(set)
*(dataPtr + (bitCount >> 3)) |= (1 << (bitCount & 0x7)); *(mDataPtr + (bitCount >> 3)) |= (1 << (bitCount & 0x7));
else else
*(dataPtr + (bitCount >> 3)) &= ~(1 << (bitCount & 0x7)); *(mDataPtr + (bitCount >> 3)) &= ~(1 << (bitCount & 0x7));
} }
bool BitStream::testBit(S32 bitCount) bool BitStream::testBit(S32 bitCount)
{ {
return (*(dataPtr + (bitCount >> 3)) & (1 << (bitCount & 0x7))) != 0; return (*(mDataPtr + (bitCount >> 3)) & (1 << (bitCount & 0x7))) != 0;
} }
bool BitStream::writeFlag(bool val) bool BitStream::writeFlag(bool val)
{ {
if(bitNum + 1 > maxWriteBitNum) if(mBitNum + 1 > mMaxWriteBitNum)
{ {
error = true; mError = true;
AssertFatal(false, "Out of range write"); AssertFatal(false, "Out of range write");
return false; return false;
} }
if(val) if(val)
*(dataPtr + (bitNum >> 3)) |= (1 << (bitNum & 0x7)); *(mDataPtr + (mBitNum >> 3)) |= (1 << (mBitNum & 0x7));
else else
*(dataPtr + (bitNum >> 3)) &= ~(1 << (bitNum & 0x7)); *(mDataPtr + (mBitNum >> 3)) &= ~(1 << (mBitNum & 0x7));
bitNum++; mBitNum++;
return (val); return (val);
} }
@ -282,23 +282,23 @@ void BitStream::readBits(S32 bitCount, void *bitPtr)
{ {
if(!bitCount) if(!bitCount)
return; return;
if(bitCount + bitNum > maxReadBitNum) if(bitCount + mBitNum > mMaxReadBitNum)
{ {
error = true; mError = true;
//AssertFatal(false, "Out of range read"); //AssertFatal(false, "Out of range read");
AssertWarn(false, "Out of range read"); AssertWarn(false, "Out of range read");
return; return;
} }
U8 *stPtr = dataPtr + (bitNum >> 3); U8 *stPtr = mDataPtr + (mBitNum >> 3);
S32 byteCount = (bitCount + 7) >> 3; S32 byteCount = (bitCount + 7) >> 3;
U8 *ptr = (U8 *) bitPtr; U8 *ptr = (U8 *) bitPtr;
S32 downShift = bitNum & 0x7; S32 downShift = mBitNum & 0x7;
S32 upShift = 8 - downShift; S32 upShift = 8 - downShift;
U8 curB = *stPtr; U8 curB = *stPtr;
const U8 *stEnd = dataPtr + bufSize; const U8 *stEnd = mDataPtr + mBufSize;
while(byteCount--) while(byteCount--)
{ {
stPtr++; stPtr++;
@ -307,7 +307,7 @@ void BitStream::readBits(S32 bitCount, void *bitPtr)
curB = nextB; curB = nextB;
} }
bitNum += bitCount; mBitNum += bitCount;
} }
bool BitStream::_read(U32 size, void *dataPtr) bool BitStream::_read(U32 size, void *dataPtr)
@ -625,69 +625,69 @@ void InfiniteBitStream::reset()
void InfiniteBitStream::validate(U32 upcomingBytes) void InfiniteBitStream::validate(U32 upcomingBytes)
{ {
if(getPosition() + upcomingBytes + mMinSpace > bufSize) if(getPosition() + upcomingBytes + mMinSpace > mBufSize)
{ {
bufSize = getPosition() + upcomingBytes + mMinSpace; mBufSize = getPosition() + upcomingBytes + mMinSpace;
dataPtr = (U8 *) dRealloc(dataPtr, bufSize); mDataPtr = (U8 *) dRealloc(mDataPtr, mBufSize);
maxReadBitNum = bufSize << 3; mMaxReadBitNum = mBufSize << 3;
maxWriteBitNum = bufSize << 3; mMaxWriteBitNum = mBufSize << 3;
} }
} }
void InfiniteBitStream::compact() void InfiniteBitStream::compact()
{ {
// Prepare to copy... // Prepare to copy...
U32 oldSize = bufSize; U32 oldSize = mBufSize;
U8 *tmp = (U8*)dMalloc(bufSize); U8 *tmp = (U8*)dMalloc(mBufSize);
// Copy things... // Copy things...
bufSize = getPosition() + mMinSpace * 2; mBufSize = getPosition() + mMinSpace * 2;
dMemcpy(tmp, dataPtr, oldSize); dMemcpy(tmp, mDataPtr, oldSize);
// And clean up. // And clean up.
dFree(dataPtr); dFree(mDataPtr);
dataPtr = tmp; mDataPtr = tmp;
maxReadBitNum = bufSize << 3; mMaxReadBitNum = mBufSize << 3;
maxWriteBitNum = bufSize << 3; mMaxWriteBitNum = mBufSize << 3;
} }
void InfiniteBitStream::writeToStream(Stream &s) void InfiniteBitStream::writeToStream(Stream &s)
{ {
s.write(getPosition(), dataPtr); s.write(getPosition(), mDataPtr);
} }
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void BitStream::readString(char buf[256]) void BitStream::readString(char buf[256])
{ {
if(stringBuffer) if(mStringBuffer)
{ {
if(readFlag()) if(readFlag())
{ {
S32 offset = readInt(8); S32 offset = readInt(8);
HuffmanProcessor::g_huffProcessor.readHuffBuffer(this, stringBuffer + offset); HuffmanProcessor::g_huffProcessor.readHuffBuffer(this, mStringBuffer + offset);
dStrcpy(buf, stringBuffer); dStrcpy(buf, mStringBuffer);
return; return;
} }
} }
HuffmanProcessor::g_huffProcessor.readHuffBuffer(this, buf); HuffmanProcessor::g_huffProcessor.readHuffBuffer(this, buf);
if(stringBuffer) if(mStringBuffer)
dStrcpy(stringBuffer, buf); dStrcpy(mStringBuffer, buf);
} }
void BitStream::writeString(const char *string, S32 maxLen) void BitStream::writeString(const char *string, S32 maxLen)
{ {
if(!string) if(!string)
string = ""; string = "";
if(stringBuffer) if(mStringBuffer)
{ {
S32 j; S32 j;
for(j = 0; j < maxLen && stringBuffer[j] == string[j] && string[j];j++) for(j = 0; j < maxLen && mStringBuffer[j] == string[j] && string[j];j++)
; ;
dStrncpy(stringBuffer, string, maxLen); dStrncpy(mStringBuffer, string, maxLen);
stringBuffer[maxLen] = 0; mStringBuffer[maxLen] = 0;
if(writeFlag(j > 2)) if(writeFlag(j > 2))
{ {
@ -781,7 +781,7 @@ void HuffmanProcessor::generateCodes(BitStream& rBS, S32 index, S32 depth)
// leaf node, copy the code in, and back out... // leaf node, copy the code in, and back out...
HuffLeaf& rLeaf = m_huffLeaves[-(index + 1)]; HuffLeaf& rLeaf = m_huffLeaves[-(index + 1)];
dMemcpy(&rLeaf.code, rBS.dataPtr, sizeof(rLeaf.code)); dMemcpy(&rLeaf.code, rBS.mDataPtr, sizeof(rLeaf.code));
rLeaf.numBits = depth; rLeaf.numBits = depth;
} else { } else {
HuffNode& rNode = m_huffNodes[index]; HuffNode& rNode = m_huffNodes[index];

View file

@ -48,13 +48,13 @@ class QuatF;
class BitStream : public Stream class BitStream : public Stream
{ {
protected: protected:
U8 *dataPtr; U8 *mDataPtr;
S32 bitNum; S32 mBitNum;
S32 bufSize; S32 mBufSize;
bool error; bool mError;
S32 maxReadBitNum; S32 mMaxReadBitNum;
S32 maxWriteBitNum; S32 mMaxWriteBitNum;
char *stringBuffer; char *mStringBuffer;
Point3F mCompressPoint; Point3F mCompressPoint;
friend class HuffmanProcessor; friend class HuffmanProcessor;
@ -63,7 +63,7 @@ public:
static void sendPacketStream(const NetAddress *addr); static void sendPacketStream(const NetAddress *addr);
void setBuffer(void *bufPtr, S32 bufSize, S32 maxSize = 0); void setBuffer(void *bufPtr, S32 bufSize, S32 maxSize = 0);
U8* getBuffer() { return dataPtr; } U8* getBuffer() { return mDataPtr; }
U8* getBytePtr(); U8* getBytePtr();
U32 getReadByteSize(); U32 getReadByteSize();
@ -83,7 +83,7 @@ public:
S32 getBitPosition() const { return getCurPos(); } S32 getBitPosition() const { return getCurPos(); }
void clearStringBuffer(); void clearStringBuffer();
BitStream(void *bufPtr, S32 bufSize, S32 maxWriteSize = -1) { setBuffer(bufPtr, bufSize,maxWriteSize); stringBuffer = NULL; } BitStream(void *bufPtr, S32 bufSize, S32 maxWriteSize = -1) { setBuffer(bufPtr, bufSize,maxWriteSize); mStringBuffer = NULL; }
void clear(); void clear();
void setStringBuffer(char buffer[256]); void setStringBuffer(char buffer[256]);
@ -241,8 +241,8 @@ public:
void setBit(S32 bitCount, bool set); void setBit(S32 bitCount, bool set);
bool testBit(S32 bitCount); bool testBit(S32 bitCount);
bool isFull() { return bitNum > (bufSize << 3); } bool isFull() { return mBitNum > (mBufSize << 3); }
bool isValid() { return !error; } bool isValid() { return !mError; }
bool _read (const U32 size,void* d); bool _read (const U32 size,void* d);
bool _write(const U32 size,const void* d); bool _write(const U32 size,const void* d);
@ -313,26 +313,26 @@ public:
// //
inline S32 BitStream::getCurPos() const inline S32 BitStream::getCurPos() const
{ {
return bitNum; return mBitNum;
} }
inline void BitStream::setCurPos(const U32 in_position) inline void BitStream::setCurPos(const U32 in_position)
{ {
AssertFatal(in_position < (U32)(bufSize << 3), "Out of range bitposition"); AssertFatal(in_position < (U32)(mBufSize << 3), "Out of range bitposition");
bitNum = S32(in_position); mBitNum = S32(in_position);
} }
inline bool BitStream::readFlag() inline bool BitStream::readFlag()
{ {
if(bitNum > maxReadBitNum) if(mBitNum > mMaxReadBitNum)
{ {
error = true; mError = true;
AssertFatal(false, "Out of range read"); AssertFatal(false, "Out of range read");
return false; return false;
} }
S32 mask = 1 << (bitNum & 0x7); S32 mask = 1 << (mBitNum & 0x7);
bool ret = (*(dataPtr + (bitNum >> 3)) & mask) != 0; bool ret = (*(mDataPtr + (mBitNum >> 3)) & mask) != 0;
bitNum++; mBitNum++;
return ret; return ret;
} }