xbytebuffer.cpp
来自「BCB的学习资料」· C++ 代码 · 共 1,560 行 · 第 1/4 页
CPP
1,560 行
XByte * dest = m_Data + m_Length;
const XByte * src = (const XByte *)aWordArray.Data();
for(int i=0; i<ArrayLength; i++)
{
*dest++= *(src+1);
*dest++ = *src++;
src++;
}
m_Length += ArrayLength * 2;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendIntArray(const XArray<XInt> &aIntArray)
{
int ArrayLength = aIntArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * 4 );
XByte * dest = m_Data + m_Length;
const XByte * src = (const XByte *)aIntArray.Data();
for(int i=0; i<ArrayLength; i++)
{
src += 3;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src;
src += 4;
}
m_Length += ArrayLength * 4;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendDWordArray(const XArray<XDWord> &aDWordArray)
{
int ArrayLength = aDWordArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * 4 );
XByte * dest = m_Data + m_Length;
const XByte * src = (const XByte *)aDWordArray.Data();
for(int i=0; i<ArrayLength; i++)
{
src += 3;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src;
src += 4;
}
m_Length += ArrayLength * 4;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendLongArray(const XArray<XLong> &aLongArray)
{
int ArrayLength = aLongArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * 8 );
XByte * dest = m_Data + m_Length;
const XByte * src = (const XByte *)aLongArray.Data();
for(int i=0; i<ArrayLength; i++)
{
src += 7;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src;
src += 8;
}
m_Length += ArrayLength * 8;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendDDWordArray(const XArray<XDDWord> &aDDWordArray)
{
int ArrayLength = aDDWordArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * 8 );
XByte * dest = m_Data + m_Length;
const XByte * src = (const XByte *)aDDWordArray.Data();
for(int i=0; i<ArrayLength; i++)
{
src += 7;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src;
src += 8;
}
m_Length += ArrayLength * 8;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendFloatArray(const XArray<XFloat> &aFloatArray)
{
int ArrayLength = aFloatArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * sizeof(XFloat) );
XFloat * dest = (XFloat *)(m_Data + m_Length);
const XFloat * src = aFloatArray.Data();
for(int i=0; i<ArrayLength; i++)
{
*dest++ = *src++;
}
m_Length += ArrayLength * sizeof(XFloat);
}
return *this;
}
XByteBuffer & XByteBuffer::AppendDoubleArray(const XArray<XDouble> &aDoubleArray)
{
int ArrayLength = aDoubleArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * sizeof(XDouble) );
XDouble * dest = (XDouble *)(m_Data + m_Length);
const XDouble * src = aDoubleArray.Data();
for(int i=0; i<ArrayLength; i++)
{
*dest++ = *src++;
}
m_Length += ArrayLength * sizeof(XDouble);
}
return *this;
}
XByteBuffer & XByteBuffer::AppendLongDoubleArray(const XArray<XLongDouble> &aLongDoubleArray)
{
int ArrayLength = aLongDoubleArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * sizeof(XLongDouble) );
XLongDouble * dest = (XLongDouble *)(m_Data + m_Length);
const XLongDouble * src = aLongDoubleArray.Data();
for(int i=0; i<ArrayLength; i++)
{
*dest++ = *src++;
}
m_Length += ArrayLength * sizeof(XLongDouble);
}
return *this;
}
XByteBuffer & XByteBuffer::AppendByteArray(const XDynamicArray<XByte> &aByteArray)
{
int ArrayLength = aByteArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength );
XByte * dest = m_Data + m_Length;
const XByte * src = aByteArray.Data();
for(int i=0; i<ArrayLength; i++) *dest++ = *src++;
m_Length += ArrayLength;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendCharArray(const XDynamicArray<XChar> &aCharArray)
{
int ArrayLength = aCharArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength );
XByte * dest = m_Data + m_Length;
const XByte * src = (const XByte *)aCharArray.Data();
for(int i=0; i<ArrayLength; i++) *dest++ = *src++;
m_Length += ArrayLength;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendBoolArray(const XDynamicArray<XBoolean> &aBoolArray)
{
int ArrayLength = aBoolArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength );
XByte * dest = m_Data + m_Length;
const XBoolean * src = aBoolArray.Data();
for(int i=0; i<ArrayLength; i++)
{
if( *src ) *dest++ = 1;
else *dest++ = 0;
src++;
}
m_Length += ArrayLength;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendShortArray(const XDynamicArray<XShort> &aShortArray)
{
int ArrayLength = aShortArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * 2 );
XByte * dest = m_Data + m_Length;
const XByte * src = (const XByte *)aShortArray.Data();
for(int i=0; i<ArrayLength; i++)
{
*dest++= *(src+1);
*dest++ = *src++;
src++;
}
m_Length += ArrayLength * 2;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendWordArray(const XDynamicArray<XWord> &aWordArray)
{
int ArrayLength = aWordArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * 2 );
XByte * dest = m_Data + m_Length;
const XByte * src = (const XByte *)aWordArray.Data();
for(int i=0; i<ArrayLength; i++)
{
*dest++= *(src+1);
*dest++ = *src++;
src++;
}
m_Length += ArrayLength * 2;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendIntArray(const XDynamicArray<XInt> &aIntArray)
{
int ArrayLength = aIntArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * 4 );
XByte * dest = m_Data + m_Length;
const XByte * src = (const XByte *)aIntArray.Data();
for(int i=0; i<ArrayLength; i++)
{
src += 3;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src;
src += 4;
}
m_Length += ArrayLength * 4;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendDWordArray(const XDynamicArray<XDWord> &aDWordArray)
{
int ArrayLength = aDWordArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * 4 );
XByte * dest = m_Data + m_Length;
const XByte * src = (const XByte *)aDWordArray.Data();
for(int i=0; i<ArrayLength; i++)
{
src += 3;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src;
src += 4;
}
m_Length += ArrayLength * 4;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendLongArray(const XDynamicArray<XLong> &aLongArray)
{
int ArrayLength = aLongArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * 8 );
XByte * dest = m_Data + m_Length;
const XByte * src = (const XByte *)aLongArray.Data();
for(int i=0; i<ArrayLength; i++)
{
src += 7;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src;
src += 8;
}
m_Length += ArrayLength * 8;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendDDWordArray(const XDynamicArray<XDDWord> &aDDWordArray)
{
int ArrayLength = aDDWordArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * 8 );
XByte * dest = m_Data + m_Length;
const XByte * src = (const XByte *)aDDWordArray.Data();
for(int i=0; i<ArrayLength; i++)
{
src += 7;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src--;
*dest++ = *src;
src += 8;
}
m_Length += ArrayLength * 8;
}
return *this;
}
XByteBuffer & XByteBuffer::AppendFloatArray(const XDynamicArray<XFloat> &aFloatArray)
{
int ArrayLength = aFloatArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * sizeof(XFloat) );
XFloat * dest = (XFloat *)(m_Data + m_Length);
const XFloat * src = aFloatArray.Data();
for(int i=0; i<ArrayLength; i++)
{
*dest++ = *src++;
}
m_Length += ArrayLength * sizeof(XFloat);
}
return *this;
}
XByteBuffer & XByteBuffer::AppendDoubleArray(const XDynamicArray<XDouble> &aDoubleArray)
{
int ArrayLength = aDoubleArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * sizeof(XDouble) );
XDouble * dest = (XDouble *)(m_Data + m_Length);
const XDouble * src = aDoubleArray.Data();
for(int i=0; i<ArrayLength; i++)
{
*dest++ = *src++;
}
m_Length += ArrayLength * sizeof(XDouble);
}
return *this;
}
XByteBuffer & XByteBuffer::AppendLongDoubleArray(const XDynamicArray<XLongDouble> &aLongDoubleArray)
{
int ArrayLength = aLongDoubleArray.GetLength();
if( ArrayLength > 0 )
{
ensureCapacity( m_Length + ArrayLength * sizeof(XLongDouble) );
XLongDouble * dest = (XLongDouble *)(m_Data + m_Length);
const XLongDouble * src = aLongDoubleArray.Data();
for(int i=0; i<ArrayLength; i++)
{
*dest++ = *src++;
}
m_Length += ArrayLength * sizeof(XLongDouble);
}
return *this;
}
/*
////////////////////////////////////////////////////////////////////////////////
[Name]AppendString
[Title]向缓冲区中追加一个字符串的数据
////////////////////////////////////////////////////////////////////////////////
[Param]
<const char *>aString 被追加的字符串
[Return]
<XByteBuffer &>当前缓冲区对象的引用
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?