?? xbytebuffer.h
字號:
//---------------------------------------------------------------------------
#ifndef XByteBufferH
#define XByteBufferH
#ifndef XCommonTypeH
#include <XCommonType.h>
#endif
#ifndef XExcepMsgH
#include <XExcepMsg.h>
#endif
#ifndef XArrayH
#include <XArray.h>
#endif
//---------------------------------------------------------------------------
namespace zdhsoft
{
//定義XByteBuffer缺省塊大小
const int XBYTE_BUFFER_MIN_BLOCK = 4096;
/*
///////////////////////////////////////////////////////////////////////////////
[Name]XByteBuffer
[Title]字節緩沖區
///////////////////////////////////////////////////////////////////////////////
[Description]
這個類主要實現數據處理,這個主要是針對DVB中PSI/SI的數據處理進行設計的,以方便數據的操作
緩沖區的大小是XBYTE_BUFFER_MIN_BLOCK的倍數,在這里XBYTE_BUFFER_MIN_BLOCK的值為4k,這樣做則是
為了避免過多的內存碎片和過多的再分配內存
由于這個類主要適用于數字電視系統中,所以對于16位,32位,64位整數存放,與PC系列存放整數的
順序剛好相反:如值0x1234在PC系列中存放為34 12,而XByteBuffer中的存放,則為12 34
為了便于對緩沖區的操作,在這里提供了大量的操作方法
主要有Append...Array追加數組,Append...追加數值,AppendData,AppendString等
重載了許多<<運算符
為了便于設置和取值,還提供了Set...Value和Get...Value系統操作方法
[Version]1.0
[Author]Rex Winter
[Date]2005-6-18
//////////////////////////////////////////////////////////////////////////////
*/
class XByteBuffer
{
public:
//缺省實現的方法
XByteBuffer(int iPrepareLength = XBYTE_BUFFER_MIN_BLOCK);
XByteBuffer(void * aData,int aDataSize,int iPrepareLength = XBYTE_BUFFER_MIN_BLOCK);
XByteBuffer(const XByteBuffer & aBuffer);
~XByteBuffer();
//一些常用方法
const void * Data() const { return (void *)m_Data; }
int GetLength() const { return m_Length; }
XByte & operator[](int Index);
const XByte & operator[] (int Index) const;
XByteBuffer & operator=(const XByteBuffer & aBuffer);
void Clear(bool bFree = false);
void ensureCapacity(int minimumCapacity)
{
if (minimumCapacity > m_DataSize ) {
expandCapacity(minimumCapacity);
}
}
//追加系列方法
XByteBuffer & AppendByteArray(const XArray<XByte> &aByteArray);
XByteBuffer & AppendCharArray(const XArray<XChar> &aCharArray);
XByteBuffer & AppendBoolArray(const XArray<XBoolean> &aBoolArray);
XByteBuffer & AppendShortArray(const XArray<XShort> &aShortArray);
XByteBuffer & AppendWordArray(const XArray<XWord> &aWordArray);
XByteBuffer & AppendIntArray(const XArray<XInt> &aIntArray);
XByteBuffer & AppendDWordArray(const XArray<XDWord> &aDWordArray);
XByteBuffer & AppendLongArray(const XArray<XLong> &aLongArray);
XByteBuffer & AppendDDWordArray(const XArray<XDDWord> &aDDWordArray);
XByteBuffer & AppendFloatArray(const XArray<XFloat> &aFloatArray);
XByteBuffer & AppendDoubleArray(const XArray<XDouble> &aDoubleArray);
XByteBuffer & AppendLongDoubleArray(const XArray<XLongDouble> &aLongDoubleArray);
XByteBuffer & AppendByteArray(const XDynamicArray<XByte> &aByteArray);
XByteBuffer & AppendCharArray(const XDynamicArray<XChar> &aCharArray);
XByteBuffer & AppendBoolArray(const XDynamicArray<XBoolean> &aBoolArray);
XByteBuffer & AppendShortArray(const XDynamicArray<XShort> &aShortArray);
XByteBuffer & AppendWordArray(const XDynamicArray<XWord> &aWordArray);
XByteBuffer & AppendIntArray(const XDynamicArray<XInt> &aIntArray);
XByteBuffer & AppendDWordArray(const XDynamicArray<XDWord> &aDWordArray);
XByteBuffer & AppendLongArray(const XDynamicArray<XLong> &aLongArray);
XByteBuffer & AppendDDWordArray(const XDynamicArray<XDDWord> &aDDWordArray);
XByteBuffer & AppendFloatArray(const XDynamicArray<XFloat> &aFloatArray);
XByteBuffer & AppendDoubleArray(const XDynamicArray<XDouble> &aDoubleArray);
XByteBuffer & AppendLongDoubleArray(const XDynamicArray<XLongDouble> &aLongDoubleArray);
XByteBuffer & operator<<(const XArray<XByte> &aByteArray)
{
return AppendByteArray(aByteArray);
}
XByteBuffer & operator<<(const XArray<XChar> &aCharArray)
{
return AppendCharArray(aCharArray);
}
XByteBuffer & operator<<(const XArray<XBoolean> &aBooleanArray)
{
return AppendBoolArray(aBooleanArray);
}
XByteBuffer & operator<<(const XArray<XShort> &aShortArray)
{
return AppendShortArray( aShortArray );
}
XByteBuffer & operator<<(const XArray<XWord> &aWordArray)
{
return AppendWordArray( aWordArray );
}
XByteBuffer & operator<<(const XArray<XInt> &aIntArray)
{
return AppendIntArray( aIntArray );
}
XByteBuffer & operator<<(const XArray<XDWord> &aDWordArray)
{
return AppendDWordArray( aDWordArray );
}
XByteBuffer & operator<<(const XArray<XLong> &aLongArray)
{
return AppendLongArray( aLongArray );
}
XByteBuffer & operator<<(const XArray<XDDWord> &aDDWordArray)
{
return AppendDDWordArray( aDDWordArray );
}
XByteBuffer & operator<<(const XArray<XFloat> &aFloatArray)
{
return AppendFloatArray( aFloatArray );
}
XByteBuffer & operator<<(const XArray<XDouble> &aDoubleArray)
{
return AppendDoubleArray( aDoubleArray );
}
XByteBuffer & operator<<(const XArray<XLongDouble> &aLongDoubleArray)
{
return AppendLongDoubleArray( aLongDoubleArray );
}
//
XByteBuffer & operator<<(const XDynamicArray<XByte> &aByteArray)
{
return AppendByteArray(aByteArray);
}
XByteBuffer & operator<<(const XDynamicArray<XChar> &aCharArray)
{
return AppendCharArray(aCharArray);
}
XByteBuffer & operator<<(const XDynamicArray<XBoolean> &aBooleanArray)
{
return AppendBoolArray(aBooleanArray);
}
XByteBuffer & operator<<(const XDynamicArray<XShort> &aShortArray)
{
return AppendShortArray( aShortArray );
}
XByteBuffer & operator<<(const XDynamicArray<XWord> &aWordArray)
{
return AppendWordArray( aWordArray );
}
XByteBuffer & operator<<(const XDynamicArray<XInt> &aIntArray)
{
return AppendIntArray( aIntArray );
}
XByteBuffer & operator<<(const XDynamicArray<XDWord> &aDWordArray)
{
return AppendDWordArray( aDWordArray );
}
XByteBuffer & operator<<(const XDynamicArray<XLong> &aLongArray)
{
return AppendLongArray( aLongArray );
}
XByteBuffer & operator<<(const XDynamicArray<XDDWord> &aDDWordArray)
{
return AppendDDWordArray( aDDWordArray );
}
XByteBuffer & operator<<(const XDynamicArray<XFloat> &aFloatArray)
{
return AppendFloatArray( aFloatArray );
}
XByteBuffer & operator<<(const XDynamicArray<XDouble> &aDoubleArray)
{
return AppendDoubleArray( aDoubleArray );
}
XByteBuffer & operator<<(const XDynamicArray<XLongDouble> &aLongDoubleArray)
{
return AppendLongDoubleArray( aLongDoubleArray );
}
//
XByteBuffer & SetByteValue(int iPos,XByte aByte);
XByteBuffer & SetCharValue(int iPos,XChar aChar);
XByteBuffer & SetWordValue(int iPos,XWord aWord);
XByteBuffer & SetShortValue(int iPos,XShort aShort);
XByteBuffer & SetIntValue(int iPos,XInt aInt);
XByteBuffer & SetDWordValue(int iPos,XDWord aDWord);
XByteBuffer & SetLongValue(int iPos,XLong aLong);
XByteBuffer & SetDDWordValue(int iPos,XDDWord aDDWord);
XByteBuffer & SetBoolValue(int iPos,XBoolean aBool);
XByteBuffer & SetFloatValue(int iPos,XFloat aFloat);
XByteBuffer & SetDoubleValue(int iPos,XDouble aDouble);
XByteBuffer & SetLongDoubleValue(int iPos,XLongDouble aLongDouble);
XByteBuffer & SetDataValue(int iPos,const void * aData,int iSize);
XByte GetByteValue(int iPos) const;
XChar GetCharValue(int iPos) const;
XWord GetWordValue(int iPos) const;
XShort GetShortValue(int iPos) const;
XInt GetIntValue(int iPos) const;
XDWord GetDWordValue(int iPos) const;
XLong GetLongValue(int iPos) const;
XDDWord GetDDWordValue(int iPos) const;
XBoolean GetBoolValue(int iPos) const;
XFloat GetFloatValue(int iPos) const;
XDouble GetDoubleValue(int iPos) const;
XLongDouble GetLongDoubleValue(int iPos) const;
XByteBuffer &GetByteValue(int iPos,XByte & v)
{
v = GetByteValue(iPos);
return *this;
}
XByteBuffer &GetCharValue(int iPos,XChar & v)
{
v = GetCharValue(iPos);
return *this;
}
XByteBuffer &GetWordValue(int iPos,XWord & v)
{
v = GetWordValue(iPos);
return *this;
}
XByteBuffer &GetShortValue(int iPos,XShort & v)
{
v = GetShortValue(iPos);
return *this;
}
XByteBuffer &GetIntValue(int iPos,XInt & v)
{
v = GetIntValue(iPos);
return *this;
}
XByteBuffer &GetDWordValue(int iPos,XDWord & v)
{
v = GetDWordValue(iPos);
return *this;
}
XByteBuffer &GetLongValue(int iPos,XLong & v)
{
v = GetLongValue(iPos);
return *this;
}
XByteBuffer &GetDDWordValue(int iPos,XDDWord & v)
{
v = GetDDWordValue(iPos);
return *this;
}
XByteBuffer &GetBoolValue(int iPos,XBoolean & v)
{
v = GetBoolValue(iPos);
return *this;
}
XByteBuffer &GetFloatValue(int iPos,XFloat & v)
{
v = GetFloatValue(iPos);
return *this;
}
XByteBuffer &GetDoubleValue(int iPos,XDouble & v)
{
v = GetDoubleValue(iPos);
return *this;
}
XByteBuffer &GetLongDoubleValue(int iPos,XLongDouble & v)
{
v = GetLongDoubleValue(iPos);
return *this;
}
XByteBuffer &GetDataValue(int iPos,void * aData,int iSize);
void GetDataValue(int iPos,void *aData,int iSize) const;
XByteBuffer & AppendBuffer(const XByteBuffer & aBuffer);
XByteBuffer & AppendString(const AnsiString & aString);
XByteBuffer & AppendData(const void * aData,int aDataSize);
XByteBuffer & AppendString(const char * aString);
XByteBuffer & AppendByte(XByte aByte);
XByteBuffer & AppendChar(XChar aChar);
XByteBuffer & AppendWord(XWord aWord);
XByteBuffer & AppendShort(XShort aShort);
XByteBuffer & AppendInt(XInt aInt);
XByteBuffer & AppendDWord(XDWord aDWord);
XByteBuffer & AppendLong(XLong aLong);
XByteBuffer & AppendDDWord(XDDWord aDDWord);
XByteBuffer & AppendFloat(XFloat aFloat);
XByteBuffer & AppendDouble(XDouble aDouble);
XByteBuffer & AppendLongDouble(XLongDouble aLongDouble);
XByteBuffer & AppendBoolean(XBoolean v);
XByteBuffer & operator<<(XBoolean v)
{
return AppendBoolean(v);
}
XByteBuffer & operator<<(const XByteBuffer & aBuffer)
{
return AppendBuffer(aBuffer);
}
XByteBuffer & operator<<(const AnsiString & aString)
{
return AppendString(aString);
}
XByteBuffer & operator<<(const char * aString)
{
return AppendString(aString);
}
XByteBuffer & operator<<(XByte aByte)
{
return AppendByte(aByte);
}
XByteBuffer & operator<<(XChar aChar)
{
return AppendChar(aChar);
}
XByteBuffer & operator<<(XWord v)
{
return AppendWord(v);
}
XByteBuffer & operator<<(XShort v)
{
return AppendShort(v);
}
XByteBuffer & operator<<(XInt v)
{
return AppendInt(v);
}
XByteBuffer & operator<<(XDWord v)
{
return AppendDWord(v);
}
XByteBuffer & operator<<(XLong v)
{
return AppendLong(v);
}
XByteBuffer & operator<<(XDDWord v)
{
return AppendDDWord(v);
}
XByteBuffer & operator<<(XFloat v)
{
return AppendFloat(v);
}
XByteBuffer & operator<<(XDouble v)
{
return AppendDouble(v);
}
XByteBuffer & operator<<(XLongDouble v)
{
return AppendLongDouble(v);
}
public:
__property int Length = { read = m_Length };
private:
int PrepareLength(iPrepareLength) //計算要準備的字節數
{
if( iPrepareLength < XBYTE_BUFFER_MIN_BLOCK ) iPrepareLength = XBYTE_BUFFER_MIN_BLOCK;
else if( (iPrepareLength % XBYTE_BUFFER_MIN_BLOCK) != 0) iPrepareLength = (iPrepareLength / XBYTE_BUFFER_MIN_BLOCK+1) * XBYTE_BUFFER_MIN_BLOCK;
return iPrepareLength;
}
void expandCapacity(int minimumCapacity,bool bCopyData = true);
private:
XByte * m_Data;
int m_DataSize;
int m_Length;
};
};
#endif
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -