⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xbytebuffer.cpp

📁 BCB的学习资料
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    return *this;
}
/*
////////////////////////////////////////////////////////////////////////////////
[Name]AppendLongDouble
[Title]向缓冲区中追加一个80位的长浮点数
////////////////////////////////////////////////////////////////////////////////
[Param]
    <XLongDouble>aLongDouble 被追加浮点数
[Return]
    <XByteBuffer &>当前缓冲区对象的引用
[Exception]
    EOutOfMemory 如果申请缓冲区失败,那么则抛出该异常
[Description]
     向缓冲区中追加一个80位的长浮点数
[Version]1.0
[Author]Rex Winter
[Date]2005-6-21
////////////////////////////////////////////////////////////////////////////////
*/
XByteBuffer & XByteBuffer::AppendLongDouble(XLongDouble aLongDouble)
{
    ensureCapacity( m_Length + sizeof(XLongDouble) );
    *((XLongDouble *)(m_Data + m_Length)) = aLongDouble;
    m_Length += sizeof(XLongDouble);
    return *this;
}

/*
////////////////////////////////////////////////////////////////////////////////
[Name]Set...Value
[Title]一组设置指定缓冲区的位置的值
////////////////////////////////////////////////////////////////////////////////
[Param]
    <int>iPos 被指定的位置
    <...>Value 被设置成的值
[Return]
    <XByteBuffer &>当前缓冲区对象的引用
[Exception]
    XExceptionArrayOutOfRange 如果越界,则抛出该异常
    Exception 如果越下界,则该出该异常
[Description]
     一组设置指定缓冲区的位置的值,包括
     SetByteValue, SetCharValue ,SetWordValue,SetShortValue等
[Version]1.0
[Author]Rex Winter
[Date]2005-6-21
////////////////////////////////////////////////////////////////////////////////
*/

XByteBuffer & XByteBuffer::SetByteValue(int iPos,XByte aByte)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    m_Data[iPos] = aByte;
    return *this;
}
XByteBuffer & XByteBuffer::SetCharValue(int iPos,XChar aChar)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    m_Data[iPos] = aChar;
    return *this;
}
XByteBuffer & XByteBuffer::SetWordValue(int iPos,XWord aWord)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 2) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XByte * src = (XByte *)&aWord;
    XByte * dest = m_Data+iPos+1;
    *dest-- = *src++;
    *dest = *src;
    return *this;
}
XByteBuffer & XByteBuffer::SetShortValue(int iPos,XShort aShort)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos +2) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XByte * src = (XByte *)&aShort;
    XByte * dest = m_Data+iPos+1;
    *dest-- = *src++;
    *dest = *src;
    return *this;
}
XByteBuffer & XByteBuffer::SetIntValue(int iPos,XInt aInt)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 4) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XByte * src = (XByte *)&aInt;
    XByte * dest = m_Data+iPos+3;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest = *src;
    return *this;
}
XByteBuffer & XByteBuffer::SetDWordValue(int iPos,XDWord aDWord)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 4) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XByte * src = (XByte *)&aDWord;
    XByte * dest = m_Data+iPos+3;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest = *src;
    return *this;
}
XByteBuffer & XByteBuffer::SetLongValue(int iPos,XLong aLong)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos +8) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XByte * src = (XByte *)&aLong;
    XByte * dest = m_Data+iPos+7;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest = *src;
    return *this;
}
XByteBuffer & XByteBuffer::SetDDWordValue(int iPos,XDDWord aDDWord)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 8) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XByte * src = (XByte *)&aDDWord;
    XByte * dest = m_Data+iPos+7;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest = *src;
    return *this;
}
XByteBuffer & XByteBuffer::SetBoolValue(int iPos,XBoolean aBool)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( aBool ) m_Data[iPos] = 1;
    else m_Data[iPos] = 0;
    return *this;
}
XByteBuffer & XByteBuffer::SetFloatValue(int iPos,XFloat aFloat)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 4) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    *((XFloat *)(m_Data + iPos)) = aFloat;
    return *this;
}
XByteBuffer & XByteBuffer::SetDoubleValue(int iPos,XDouble aDouble)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 8) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    *((XDouble *)(m_Data + iPos)) = aDouble;
    return *this;
}
XByteBuffer & XByteBuffer::SetLongDoubleValue(int iPos,XLongDouble aLongDouble)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 10) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    *((XLongDouble *)(m_Data + iPos)) = aLongDouble;
    return *this;
}
/*
////////////////////////////////////////////////////////////////////////////////
[Name]Get...Value
[Title]一组取指定缓冲区的位置的值
////////////////////////////////////////////////////////////////////////////////
[Param]
    <int>iPos 被指定的位置
[Return]
    <...>反回所取的值
[Exception]
    XExceptionArrayOutOfRange 如果越界,则抛出该异常
    Exception 如果越下界,则该出该异常
[Description]
     一组取指定缓冲区的位置的值,包括
     GetByteValue, GetCharValue ,GetWordValue,GetShortValue等
[Version]1.0
[Author]Rex Winter
[Date]2005-6-21
////////////////////////////////////////////////////////////////////////////////
*/

XByte XByteBuffer::GetByteValue(int iPos) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    return m_Data[iPos];
}
XChar XByteBuffer::GetCharValue(int iPos) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    return m_Data[iPos];
}
XWord XByteBuffer::GetWordValue(int iPos) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 2) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XWord aRet;
    XByte * dest = ((XByte *)&aRet)+1;
    XByte * src = m_Data + iPos;
    *dest-- = *src++;
    *dest = *src;
    return aRet;
}
XShort XByteBuffer::GetShortValue(int iPos) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 2) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XShort aRet;
    XByte * dest = ((XByte *)&aRet)+1;
    XByte * src = m_Data + iPos;
    *dest-- = *src++;
    *dest = *src;
    return aRet;
}
XInt XByteBuffer::GetIntValue(int iPos) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 4) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XInt aRet;
    XByte * dest = ((XByte *)&aRet)+3;
    XByte * src = m_Data + iPos;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest = *src;
    return aRet;
}
XDWord XByteBuffer::GetDWordValue(int iPos) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 4) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XDWord aRet;
    XByte * dest = ((XByte *)&aRet)+3;
    XByte * src = m_Data + iPos;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest = *src;
    return aRet;
}
XLong XByteBuffer::GetLongValue(int iPos) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 8) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XLong aRet;
    XByte * dest = ((XByte *)&aRet)+7;
    XByte * src = m_Data + iPos;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest = *src;
    return aRet;
}
XDDWord XByteBuffer::GetDDWordValue(int iPos) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 8) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XDDWord aRet;
    XByte * dest = ((XByte *)&aRet)+7;
    XByte * src = m_Data + iPos;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest-- = *src++;
    *dest = *src;
    return aRet;
}
XBoolean XByteBuffer::GetBoolValue(int iPos) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    return m_Data[iPos]==0?false:true;
}
XFloat XByteBuffer::GetFloatValue(int iPos) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 4) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    return *((XFloat *)(m_Data+iPos));

}
XDouble XByteBuffer::GetDoubleValue(int iPos) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 8) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    return *((XDouble *)(m_Data+iPos));
}
XLongDouble XByteBuffer::GetLongDoubleValue(int iPos) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( (iPos + 10) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    return *((XLongDouble *)(m_Data+iPos));
}
/*
////////////////////////////////////////////////////////////////////////////////
[Name]SetDataValue
[Title]设定缓冲区中的数据
////////////////////////////////////////////////////////////////////////////////
[Param]
    <int>iPos 被指定的位置
    <const void *>aData 被Copy的数据
    <int>iSize 被Copy的数据的字节数
[Return]
    <XByteBuffer &>当前缓冲区对象的引用
[Exception]
    XExceptionArrayOutOfRange 如果越界,则抛出该异常
    Exception 如果越下界,则该出该异常
    XExceptionIsLowZero 如果iSize则抛出该异常
[Description]
    设定缓冲区中的数据
[Version]1.0
[Author]Rex Winter
[Date]2005-6-21
////////////////////////////////////////////////////////////////////////////////
*/

XByteBuffer & XByteBuffer::SetDataValue(int iPos,const void * aData,int iSize)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( iSize < 0 ) throw XExceptionIsLowZero("iSize");
    if( (iPos + iSize) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    const XByte * src = (const XByte *)aData;
    XByte * dest = m_Data + iPos;
    for(int i=0;i<iSize;i++)
    {
        *dest++ = *src++;
    }
    return *this;
}
/*
////////////////////////////////////////////////////////////////////////////////
[Name]GetDataValue
[Title]取缓冲区中的数据
////////////////////////////////////////////////////////////////////////////////
[Param]
    <int>iPos 被指定的位置
    <const void *>aData copy的目的指针
    <int>iSize 被Copy的数据的字节数
[Return]
    <XByteBuffer &>当前缓冲区对象的引用
[Exception]
    XExceptionArrayOutOfRange 如果越界,则抛出该异常
    Exception 如果越下界,则该出该异常
    XExceptionIsLowZero 如果iSize则抛出该异常
[Description]
    取缓冲区中的数据
[Version]1.0
[Author]Rex Winter
[Date]2005-6-21
////////////////////////////////////////////////////////////////////////////////
*/

XByteBuffer &XByteBuffer::GetDataValue(int iPos,void * aData,int iSize)
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( iSize < 0 ) throw XExceptionIsLowZero("iSize");
    if( (iPos + iSize) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XByte * src =  m_Data + iPos;
    XByte * dest = (XByte *)aData;
    for(int i=0;i<iSize;i++)
    {
        *dest++ = *src++;
    }
    return *this;
}

void XByteBuffer::GetDataValue(int iPos,void *aData,int iSize) const
{
    if( iPos < 0 || iPos >= m_Length ) throw XExceptionArrayOutOfRange(iPos,m_Length);
    if( iSize < 0 ) throw XExceptionIsLowZero("iSize");
    if( (iPos + iSize) > m_Length ) throw Exception(EXCEPTION_OUT_OF_SUFFIX_BYTEBUFFER);
    XByte * src =  m_Data + iPos;
    XByte * dest = (XByte *)aData;
    for(int i=0;i<iSize;i++)
    {
        *dest++ = *src++;
    }
}
};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -