Add SvStream::ReadCharAsBool

Change-Id: I9dc0525e04de5ae79205872b779dcd0115a9cc14
This commit is contained in:
Stephan Bergmann
2014-02-20 19:51:04 +01:00
parent 5dcb634dcb
commit 9c9e4b1942
6 changed files with 36 additions and 11 deletions

View File

@@ -308,6 +308,7 @@ public:
SvStream& ReadSChar( signed char& rChar );
SvStream& ReadChar( char& rChar );
SvStream& ReadUChar( unsigned char& rChar );
SvStream& ReadCharAsBool( bool& rBool );
SvStream& ReadFloat( float& rFloat );
SvStream& ReadDouble( double& rDouble );
SvStream& ReadStream( SvStream& rStream );

View File

@@ -169,8 +169,8 @@ TYPEINIT1_AUTOFACTORY(SfxBoolItem, SfxPoolItem);
SfxBoolItem::SfxBoolItem(sal_uInt16 const nWhich, SvStream & rStream)
: SfxPoolItem(nWhich)
{
unsigned char tmp = 0;
rStream.ReadUChar( tmp );
bool tmp = false;
rStream.ReadCharAsBool( tmp );
m_bValue = tmp;
}

View File

@@ -71,8 +71,8 @@ SfxPoolItem* CntContentTypeItem::Create( SvStream& rStream,
rStream.ReadUInt32( nMagic );
if (nMagic == CNTSTRINGITEM_STREAM_MAGIC)
{
unsigned char bEncrypted = sal_False;
rStream.ReadUChar( bEncrypted );
bool bEncrypted = false;
rStream.ReadCharAsBool( bEncrypted );
DBG_ASSERT(!bEncrypted,
"CntContentTypeItem::Create() reads encrypted data");
}

View File

@@ -33,8 +33,8 @@ SfxVisibilityItem::SfxVisibilityItem(sal_uInt16 which, SvStream & rStream):
SfxPoolItem(which)
{
DBG_CTOR(SfxVisibilityItem, 0);
unsigned char bValue = 0;
rStream.ReadUChar( bValue );
bool bValue = false;
rStream.ReadCharAsBool( bValue );
m_nValue.bVisible = bValue;
}

View File

@@ -184,8 +184,8 @@ void ImpSvNumberformatInfo::Load(SvStream& rStream, sal_uInt16 nAnz)
sStrArray[i] = SvNumberformat::LoadString( rStream );
rStream.ReadInt16( nTypeArray[i] );
}
unsigned char bStreamThousand;
rStream.ReadInt16( eScannedType ).ReadUChar( bStreamThousand ).ReadUInt16( nThousand )
bool bStreamThousand;
rStream.ReadInt16( eScannedType ).ReadCharAsBool( bStreamThousand ).ReadUInt16( nThousand )
.ReadUInt16( nCntPre ).ReadUInt16( nCntPost ).ReadUInt16( nCntExp );
bThousand = bStreamThousand;
}
@@ -1702,9 +1702,9 @@ NfHackConversion SvNumberformat::Load( SvStream& rStream,
rHdr.StartEntry();
sal_uInt16 nOp1, nOp2;
sFormatstring = SvNumberformat::LoadString( rStream );
unsigned char bStreamStandard, bStreamUsed;
bool bStreamStandard, bStreamUsed;
rStream.ReadInt16( eType ).ReadDouble( fLimit1 ).ReadDouble( fLimit2 )
.ReadUInt16( nOp1 ).ReadUInt16( nOp2 ).ReadUChar( bStreamStandard ).ReadUChar( bStreamUsed );
.ReadUInt16( nOp1 ).ReadUInt16( nOp2 ).ReadCharAsBool( bStreamStandard ).ReadCharAsBool( bStreamUsed );
bStandard = bStreamStandard;
bIsUsed = bStreamUsed;
NfHackConversion eHackConversion = NF_CONVERT_NONE;
@@ -1795,7 +1795,7 @@ NfHackConversion SvNumberformat::Load( SvStream& rStream,
}
break;
case nNewStandardFlagVersionId :
rStream.ReadUChar( bStreamStandard ); // the real standard flag
rStream.ReadCharAsBool( bStreamStandard ); // the real standard flag
bStandard = bStreamStandard;
break;
default:

View File

@@ -1004,6 +1004,30 @@ SvStream& SvStream::ReadUChar( unsigned char& r )
return *this;
}
SvStream& SvStream::ReadCharAsBool( bool& r )
{
if( (bIoRead || !bIsConsistent) &&
sizeof(char) <= nBufFree )
{
SAL_WARN_IF(
*pBufPos > 1, "tools.stream", unsigned(*pBufPos) << " not 0/1");
r = *pBufPos != 0;
nBufActualPos += sizeof(char);
pBufPos += sizeof(char);
nBufFree -= sizeof(char);
}
else
{
unsigned char c;
if (Read(&c, 1) == 1)
{
SAL_WARN_IF(c > 1, "tools.stream", unsigned(c) << " not 0/1");
r = c != 0;
}
}
return *this;
}
SvStream& SvStream::ReadFloat(float& r)
{
float n = 0;