From 2d162b1c70c1bc16d682b74ee1d0b13a9a80717d Mon Sep 17 00:00:00 2001 From: baltasarq Date: Wed, 24 Feb 2016 14:43:38 +0100 Subject: tdf#84938 Eliminate B_xxx defines in filefmt.hxx for FileOffset scoped enum. Second step: Make SbiOpenRecord() accept a FileOffset as second parameter This is a [partial] patch The objective is to substitute all apparitions of #defined constants for enum class. The victim here is the series of constants B_xxx that were located in filefmt.hxx and were changed for a FileOffset enum class. Obviously some other files where the type is used must be changed too. Change-Id: I7406bdc8e780ee89802ab6823f9c91c4c9b765c0 Reviewed-on: https://gerrit.libreoffice.org/22697 Reviewed-by: Noel Grandin Tested-by: Noel Grandin --- basic/source/classes/image.cxx | 47 +++++++++++++++++++++--------------------- basic/source/inc/filefmt.hxx | 37 ++++++++++++++++++--------------- 2 files changed, 44 insertions(+), 40 deletions(-) (limited to 'basic') diff --git a/basic/source/classes/image.cxx b/basic/source/classes/image.cxx index d79c21c21306..00d5456710df 100644 --- a/basic/source/classes/image.cxx +++ b/basic/source/classes/image.cxx @@ -83,10 +83,11 @@ bool SbiGood( SvStream& r ) } // Open Record -sal_uInt64 SbiOpenRecord( SvStream& r, sal_uInt16 nSignature, sal_uInt16 nElem ) +sal_uInt64 SbiOpenRecord( SvStream& r, FileOffset nSignature, sal_uInt16 nElem ) { sal_uInt64 nPos = r.Tell(); - r.WriteUInt16( nSignature ).WriteInt32( 0 ).WriteUInt16( nElem ); + r.WriteUInt16( static_cast( nSignature ) ) + .WriteInt32( 0 ).WriteUInt16( nElem ); return nPos; } @@ -121,7 +122,7 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion ) sal_uInt32 nReserved2; sal_uInt32 nReserved3; bool bBadVer = false; - if( nSign == B_MODULE ) + if( nSign == static_cast( FileOffset::Module ) ) { sal_uInt16 nTmpFlags; r.ReadUInt32( nVersion ).ReadUInt32( nCharSet ).ReadUInt32( lDimBase ) @@ -143,20 +144,20 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion ) nNext += nLen + 8; if( r.GetError() == SVSTREAM_OK ) { - switch( nSign ) + switch( static_cast( nSign ) ) { - case B_NAME: + case FileOffset::Name: aName = r.ReadUniOrByteString(eCharSet); break; - case B_COMMENT: + case FileOffset::Comment: aComment = r.ReadUniOrByteString(eCharSet ); break; - case B_SOURCE: + case FileOffset::Source: { aOUSource = r.ReadUniOrByteString(eCharSet); break; } - case B_EXTSOURCE: + case FileOffset::ExtSource: { //assuming an empty string with just the lead 32bit/16bit len indicator const size_t nMinStringSize = (eCharSet == RTL_TEXTENCODING_UNICODE) ? 4 : 2; @@ -173,7 +174,7 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion ) } break; } - case B_PCODE: + case FileOffset::PCode: if( bBadVer ) break; pCode = new char[ nLen ]; nCodeSize = nLen; @@ -198,12 +199,12 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion ) // release of the buffer. } break; - case B_PUBLICS: - case B_POOLDIR: - case B_SYMPOOL: - case B_LINERANGES: + case FileOffset::Publics: + case FileOffset::PoolDir: + case FileOffset::SymPool: + case FileOffset::LineRanges: break; - case B_STRINGPOOL: + case FileOffset::StringPool: { if( bBadVer ) break; //assuming an empty string with just the lead 32bit len indicator @@ -240,7 +241,7 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion ) } break; } - case B_USERTYPES: + case FileOffset::UserTypes: { //assuming an empty string with just the lead 32bit/16bit len indicator const size_t nMinStringSize = (eCharSet == RTL_TEXTENCODING_UNICODE) ? 4 : 2; @@ -340,7 +341,7 @@ bool SbiImage::Load( SvStream& r, sal_uInt32& nVersion ) } break; } - case B_MODEND: + case FileOffset::ModEnd: goto done; default: break; @@ -375,7 +376,7 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer ) return true; } // First of all the header - sal_uInt64 nStart = SbiOpenRecord( r, B_MODULE, 1 ); + sal_uInt64 nStart = SbiOpenRecord( r, FileOffset::Module, 1 ); sal_uInt64 nPos; eCharSet = GetSOStoreTextEncoding( eCharSet ); @@ -397,28 +398,28 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer ) // Name? if( !aName.isEmpty() && SbiGood( r ) ) { - nPos = SbiOpenRecord( r, B_NAME, 1 ); + nPos = SbiOpenRecord( r, FileOffset::Name, 1 ); r.WriteUniOrByteString( aName, eCharSet ); SbiCloseRecord( r, nPos ); } // Comment? if( !aComment.isEmpty() && SbiGood( r ) ) { - nPos = SbiOpenRecord( r, B_COMMENT, 1 ); + nPos = SbiOpenRecord( r, FileOffset::Comment, 1 ); r.WriteUniOrByteString( aComment, eCharSet ); SbiCloseRecord( r, nPos ); } // Source? if( !aOUSource.isEmpty() && SbiGood( r ) ) { - nPos = SbiOpenRecord( r, B_SOURCE, 1 ); + nPos = SbiOpenRecord( r, FileOffset::Source, 1 ); r.WriteUniOrByteString( aOUSource, eCharSet ); SbiCloseRecord( r, nPos ); } // Binary data? if( pCode && SbiGood( r ) ) { - nPos = SbiOpenRecord( r, B_PCODE, 1 ); + nPos = SbiOpenRecord( r, FileOffset::PCode, 1 ); if ( bLegacy ) { ReleaseLegacyBuffer(); // release any previously held buffer @@ -437,7 +438,7 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer ) // String-Pool? if( nStrings ) { - nPos = SbiOpenRecord( r, B_STRINGPOOL, nStrings ); + nPos = SbiOpenRecord( r, FileOffset::StringPool, nStrings ); // For every String: // sal_uInt32 Offset of the Strings in the Stringblock short i; @@ -466,7 +467,7 @@ bool SbiImage::Save( SvStream& r, sal_uInt32 nVer ) sal_uInt16 nTypes = rTypes->Count(); if (nTypes > 0 ) { - nPos = SbiOpenRecord( r, B_USERTYPES, nTypes ); + nPos = SbiOpenRecord( r, FileOffset::UserTypes, nTypes ); for (sal_uInt16 i = 0; i < nTypes; i++) { diff --git a/basic/source/inc/filefmt.hxx b/basic/source/inc/filefmt.hxx index c9d6ba7c8f95..d6ef8c8be0f4 100644 --- a/basic/source/inc/filefmt.hxx +++ b/basic/source/inc/filefmt.hxx @@ -57,23 +57,26 @@ class SvStream; // all the file-offsets in records are relative to the module's start! -#define B_LIBRARY 0x4C42 // BL Library Record -#define B_MODULE 0x4D42 // BM Module Record -#define B_NAME 0x4E4D // MN module name -#define B_COMMENT 0x434D // MC comment -#define B_SOURCE 0x4353 // SC source code -#define B_PCODE 0x4350 // PC p-code -#define B_OLDPUBLICS 0x7550 // Pu publics -#define B_PUBLICS 0x5550 // PU publics -#define B_POOLDIR 0x4450 // PD symbol pool directory -#define B_SYMPOOL 0x5953 // SY symbol pool -#define B_STRINGPOOL 0x5453 // ST symbol pool -#define B_LINERANGES 0x524C // LR line ranges for publics -#define B_MODEND 0x454D // ME module end -#define B_SBXOBJECTS 0x5853 // SX SBX objects -#define B_EXTSOURCE 0x5345 // ES extended source - -#define B_USERTYPES 0x4369 // UT user defined types +enum class FileOffset { + Library = 0x4C42, // BL Library Record + Module = 0x4D42, // BM Module Record + Name = 0x4E4D, // MN module name + Comment = 0x434D, // MC comment + Source = 0x4353, // SC source code + PCode = 0x4350, // PC p-code + OldPublics = 0x7550, // Pu publics + Publics = 0x5550, // PU publics + PoolDir = 0x4450, // PD symbol pool directory + SymPool = 0x5953, // SY symbol pool + StringPool = 0x5453, // ST symbol pool + LineRanges = 0x524C, // LR line ranges for publics + ModEnd = 0x454D, // ME module end + SbxObjects = 0x5853, // SX SBX objects + ExtSource = 0x5345, // ES extended source + UserTypes = 0x4369, // UT user defined types + + LastValue = UserTypes +}; // A library record contains only module records -- cgit