?? xbytebuffer.cpp
字號:
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 + -