summaryrefslogtreecommitdiff
path: root/sot/source
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@suse.com>2012-09-19 17:52:31 +0100
committerMichael Meeks <michael.meeks@suse.com>2012-09-19 17:53:49 +0100
commit1da4e8c6bf1f82691514edc5c780907b3009f443 (patch)
tree7bb300b708ba2835bec1499c7e19bcd403a6b406 /sot/source
parent3fa50ac35b6a56ae9628b0310cbf0eb7b4634736 (diff)
sot: stgcache re-factor to use sane lifecycle semantics
Store a dirty page hash to allow us to fix the LRU cache next. Change-Id: I67130af37ac1bc2d0a4abbb11f4d9871bb2bc306
Diffstat (limited to 'sot/source')
-rw-r--r--sot/source/sdstor/stgcache.cxx90
-rw-r--r--sot/source/sdstor/stgcache.hxx85
-rw-r--r--sot/source/sdstor/stgdir.hxx2
-rw-r--r--sot/source/sdstor/stgio.cxx4
-rw-r--r--sot/source/sdstor/stgstrms.cxx132
-rw-r--r--sot/source/sdstor/stgstrms.hxx7
6 files changed, 171 insertions, 149 deletions
diff --git a/sot/source/sdstor/stgcache.cxx b/sot/source/sdstor/stgcache.cxx
index ac628266d720..06a0ee062273 100644
--- a/sot/source/sdstor/stgcache.cxx
+++ b/sot/source/sdstor/stgcache.cxx
@@ -37,10 +37,10 @@
// the correctness of the I/O.
StgPage::StgPage( short nSize, sal_Int32 nPage )
- : mnPage( nPage )
+ : mnRefCount( 0 )
+ , mnPage( nPage )
, mpData( new sal_uInt8[ nSize ] )
, mnSize( nSize )
- , mbDirty( false )
{
OSL_ENSURE( mnSize >= 512, "Unexpected page size is provided!" );
// We will write this data to a permanant file later
@@ -53,15 +53,20 @@ StgPage::~StgPage()
delete [] mpData;
}
-void StgPage::SetPage( short nOff, sal_Int32 nVal )
+rtl::Reference< StgPage > StgPage::Create( short nData, sal_Int32 nPage )
{
- if( ( nOff < (short) ( mnSize / sizeof( sal_Int32 ) ) ) && nOff >= 0 )
+ return rtl::Reference< StgPage >( new StgPage( nData, nPage ) );
+}
+
+void StgCache::SetToPage ( const rtl::Reference< StgPage > xPage, short nOff, sal_Int32 nVal )
+{
+ if( ( nOff < (short) ( xPage->GetSize() / sizeof( sal_Int32 ) ) ) && nOff >= 0 )
{
#ifdef OSL_BIGENDIAN
nVal = OSL_SWAPDWORD(nVal);
#endif
- ((sal_Int32*) mpData )[ nOff ] = nVal;
- mbDirty = true;
+ ((sal_Int32*) xPage->GetData() )[ nOff ] = nVal;
+ SetDirty( xPage );
}
}
@@ -114,61 +119,52 @@ void StgCache::SetPhysPageSize( short n )
// Create a new cache element
-StgPage* StgCache::Create( sal_Int32 nPg )
+rtl::Reference< StgPage > StgCache::Create( sal_Int32 nPg )
{
- StgPage* pElem = new StgPage( nPageSize, nPg );
-
- maLRUCache[pElem->GetPage()] = pElem;
-
- return pElem;
+ rtl::Reference< StgPage > xElem( StgPage::Create( nPageSize, nPg ) );
+ maLRUCache[ xElem->GetPage() ] = xElem;
+ return xElem;
}
// Delete the given element
-void StgCache::Erase( StgPage* pElem )
+void StgCache::Erase( const rtl::Reference< StgPage > &xElem )
{
- OSL_ENSURE( pElem, "The pointer should not be NULL!" );
- if ( pElem )
- {
- maLRUCache.erase( pElem->GetPage() );
- delete pElem;
- }
+ OSL_ENSURE( xElem.is(), "The pointer should not be NULL!" );
+ if ( xElem.is() )
+ maLRUCache.erase( xElem->GetPage() );
}
// remove all cache elements without flushing them
void StgCache::Clear()
{
+ maDirtyPages.clear();
maLRUCache.clear();
}
// Look for a cached page
-StgPage* StgCache::Find( sal_Int32 nPage )
+rtl::Reference< StgPage > StgCache::Find( sal_Int32 nPage )
{
IndexToStgPage::iterator aIt = maLRUCache.find( nPage );
if( aIt != maLRUCache.end() )
- {
- // page found
- StgPage* pFound = (*aIt).second;
- OSL_ENSURE( pFound, "The pointer may not be NULL!" );
- return pFound;
- }
- return NULL;
+ return (*aIt).second;
+ return rtl::Reference< StgPage >();
}
// Load a page into the cache
-StgPage* StgCache::Get( sal_Int32 nPage, sal_Bool bForce )
+rtl::Reference< StgPage > StgCache::Get( sal_Int32 nPage, sal_Bool bForce )
{
- StgPage* p = Find( nPage );
- if( !p )
+ rtl::Reference< StgPage > p = Find( nPage );
+ if( !p.is() )
{
p = Create( nPage );
if( !Read( nPage, p->GetData(), 1 ) && bForce )
{
Erase( p );
- p = NULL;
+ p.clear();
SetError( SVSTREAM_READ_ERROR );
}
}
@@ -179,22 +175,23 @@ StgPage* StgCache::Get( sal_Int32 nPage, sal_Bool bForce )
// to duplicate an existing stream or to create new entries.
// The new page is initially marked dirty. No owner is copied.
-StgPage* StgCache::Copy( sal_Int32 nNew, sal_Int32 nOld )
+rtl::Reference< StgPage > StgCache::Copy( sal_Int32 nNew, sal_Int32 nOld )
{
- StgPage* p = Find( nNew );
- if( !p )
+ rtl::Reference< StgPage > p = Find( nNew );
+ if( !p.is() )
p = Create( nNew );
if( nOld >= 0 )
{
// old page: we must have this data!
- StgPage* q = Get( nOld, sal_True );
- if( q )
+ rtl::Reference< StgPage > q = Get( nOld, sal_True );
+ if( q.is() )
{
OSL_ENSURE( p->GetSize() == q->GetSize(), "Unexpected page size!" );
memcpy( p->GetData(), q->GetData(), p->GetSize() );
}
}
- p->SetDirty( true );
+ SetDirty( p );
+
return p;
}
@@ -203,23 +200,21 @@ StgPage* StgCache::Copy( sal_Int32 nNew, sal_Int32 nOld )
sal_Bool StgCache::Commit()
{
std::vector< StgPage * > aToWrite;
- for ( IndexToStgPage::iterator aIt = maLRUCache.begin();
- aIt != maLRUCache.end(); aIt++ )
- {
- if ( aIt->second->IsDirty() )
- aToWrite.push_back( aIt->second );
- }
+ for ( IndexToStgPage::iterator aIt = maDirtyPages.begin();
+ aIt != maDirtyPages.end(); aIt++ )
+ aToWrite.push_back( aIt->second.get() );
std::sort( aToWrite.begin(), aToWrite.end(), StgPage::IsPageGreater );
for (std::vector< StgPage * >::iterator aWr = aToWrite.begin();
aWr != aToWrite.end(); aWr++)
{
- StgPage *pPage = *aWr;
+ const rtl::Reference< StgPage > &pPage = *aWr;
if ( !Write( pPage->GetPage(), pPage->GetData(), 1 ) )
return sal_False;
- pPage->SetDirty( false );
}
+ maDirtyPages.clear();
+
pStrm->Flush();
SetError( pStrm->GetError() );
@@ -262,6 +257,11 @@ void StgCache::SetStrm( UCBStorageStream* pStgStream )
bMyStream = sal_False;
}
+void StgCache::SetDirty( const rtl::Reference< StgPage > &xPage )
+{
+ maDirtyPages[ xPage->GetPage() ] = xPage;
+}
+
// Open/close the disk file
sal_Bool StgCache::Open( const String& rName, StreamMode nMode )
diff --git a/sot/source/sdstor/stgcache.hxx b/sot/source/sdstor/stgcache.hxx
index d556c5997590..268784683922 100644
--- a/sot/source/sdstor/stgcache.hxx
+++ b/sot/source/sdstor/stgcache.hxx
@@ -21,9 +21,11 @@
#define _STGCACHE_HXX
#include <osl/endian.h>
+#include <rtl/ref.hxx>
#include <tools/solar.h>
#include <tools/stream.hxx>
#include <stgelem.hxx>
+#include <boost/noncopyable.hpp>
#include <boost/unordered_map.hpp>
class UCBStorageStream;
@@ -34,7 +36,7 @@ class StorageBase;
typedef boost::unordered_map
<
sal_Int32,
- StgPage *,
+ rtl::Reference< StgPage >,
boost::hash< sal_Int32 >,
std::equal_to< sal_Int32 >
> IndexToStgPage;
@@ -43,12 +45,13 @@ class StgCache {
sal_uLong nError; // error code
sal_Int32 nPages; // size of data area in pages
sal_uInt16 nRef; // reference count
+ IndexToStgPage maDirtyPages; // hash of all dirty pages
IndexToStgPage maLRUCache; // hash of index to cached pages
short nPageSize; // page size of the file
UCBStorageStream* pStorageStream; // holds reference to UCB storage stream
- void Erase( StgPage* ); // delete a cache element
- StgPage* Create( sal_Int32 ); // create a cached page
+ void Erase( const rtl::Reference< StgPage >& ); // delete a cache element
+ rtl::Reference< StgPage > Create( sal_Int32 ); // create a cached page
protected:
SvStream* pStrm; // physical stream
sal_Bool bMyStream; // sal_True: delete stream in dtor
@@ -57,12 +60,12 @@ protected:
public:
StgCache();
~StgCache();
- void IncRef() { nRef++; }
+ void IncRef() { nRef++; }
sal_uInt16 DecRef() { return --nRef; }
void SetPhysPageSize( short );
sal_Int32 GetPhysPages() { return nPages; }
- short GetPhysPageSize() { return nPageSize; }
- SvStream* GetStrm() { return pStrm; }
+ short GetPhysPageSize() { return nPageSize; }
+ SvStream* GetStrm() { return pStrm; }
void SetStrm( SvStream*, sal_Bool );
void SetStrm( UCBStorageStream* );
sal_Bool IsWritable() { return ( pStrm && pStrm->IsWritable() ); }
@@ -74,47 +77,65 @@ public:
void ResetError();
sal_Bool Open( const String& rName, StreamMode );
void Close();
- sal_Bool Read( sal_Int32 nPage, void* pBuf, sal_Int32 nPages );
- sal_Bool Write( sal_Int32 nPage, void* pBuf, sal_Int32 nPages );
+ sal_Bool Read ( sal_Int32 nPage, void* pBuf, sal_Int32 nPages );
+ sal_Bool Write ( sal_Int32 nPage, void* pBuf, sal_Int32 nPages );
+
+ // two routines for accessing FAT pages
+ // Assume that the data is a FAT page and get/put FAT data.
+ void SetToPage ( const rtl::Reference< StgPage > xPage, short nOff, sal_Int32 nVal );
+ inline sal_Int32 GetFromPage ( const rtl::Reference< StgPage > xPage, short nOff );
+ void SetDirty ( const rtl::Reference< StgPage > &xPage );
sal_Bool SetSize( sal_Int32 nPages );
- StgPage* Find( sal_Int32 ); // find a cached page
- StgPage* Get( sal_Int32, sal_Bool ); // get a cached page
- StgPage* Copy( sal_Int32, sal_Int32=STG_FREE ); // copy a page
+ rtl::Reference< StgPage > Find( sal_Int32 ); // find a cached page
+ rtl::Reference< StgPage > Get( sal_Int32, sal_Bool ); // get a cached page
+ rtl::Reference< StgPage > Copy( sal_Int32, sal_Int32=STG_FREE ); // copy a page
sal_Bool Commit(); // flush all pages
void Clear(); // clear the cache
};
-class StgPage {
+class StgPage : public rtl::IReference, private boost::noncopyable {
+ sal_uInt32 mnRefCount;
const sal_Int32 mnPage; // page index
sal_uInt8* mpData; // nSize bytes
short mnSize; // size of this page
- bool mbDirty; // dirty flag
+ StgPage( short nData, sal_Int32 nPage );
+ virtual ~StgPage();
public:
- StgPage( short nData, sal_Int32 nPage );
- ~StgPage();
+ static rtl::Reference< StgPage > Create( short nData, sal_Int32 nPage );
- sal_Int32 GetPage() { return mnPage; }
- void* GetData() { return mpData; }
- short GetSize() { return mnSize; }
- bool IsDirty() { return mbDirty; }
- void SetDirty( bool bDirty ) { mbDirty = bDirty; }
- // routines for accessing FAT pages
- // Assume that the data is a FAT page and get/put FAT data.
- sal_Int32 GetPage( short nOff )
+ sal_Int32 GetPage() { return mnPage; }
+ void* GetData() { return mpData; }
+ short GetSize() { return mnSize; }
+
+public:
+ virtual oslInterlockedCount SAL_CALL acquire()
{
- if( ( nOff >= (short) ( mnSize / sizeof( sal_Int32 ) ) ) || nOff < 0 )
- return -1;
- sal_Int32 n = ((sal_Int32*) mpData )[ nOff ];
-#ifdef OSL_BIGENDIAN
- return OSL_SWAPDWORD(n);
-#else
- return n;
-#endif
+ return ++mnRefCount;
+ }
+ virtual oslInterlockedCount SAL_CALL release()
+ {
+ if ( --mnRefCount == 0)
+ {
+ delete this;
+ return 0;
+ }
+ return mnRefCount;
}
- void SetPage( short, sal_Int32 ); // put an element
static bool IsPageGreater( const StgPage *pA, const StgPage *pB );
};
+inline sal_Int32 StgCache::GetFromPage ( const rtl::Reference< StgPage > xPage, short nOff )
+{
+ if( ( nOff >= (short) ( xPage->GetSize() / sizeof( sal_Int32 ) ) ) || nOff < 0 )
+ return -1;
+ sal_Int32 n = ((sal_Int32*) xPage->GetData() )[ nOff ];
+#ifdef OSL_BIGENDIAN
+ return OSL_SWAPDWORD(n);
+#else
+ return n;
+#endif
+}
+
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sot/source/sdstor/stgdir.hxx b/sot/source/sdstor/stgdir.hxx
index 88c2cab59abb..c62a035370eb 100644
--- a/sot/source/sdstor/stgdir.hxx
+++ b/sot/source/sdstor/stgdir.hxx
@@ -72,7 +72,7 @@ public:
sal_Bool Store( StgDirStrm& ); // save entry into dir strm
sal_Bool IsContained( StgDirEntry* ); // check if subentry
- void SetDirty() { bDirty = sal_True; }
+ void SetDirty() { bDirty = sal_True; }
sal_Bool IsDirty();
void ClearDirty();
diff --git a/sot/source/sdstor/stgio.cxx b/sot/source/sdstor/stgio.cxx
index 1305f4e5cdc8..acd0a32b0cf1 100644
--- a/sot/source/sdstor/stgio.cxx
+++ b/sot/source/sdstor/stgio.cxx
@@ -171,7 +171,7 @@ EasyFat::EasyFat( StgIo& rIo, StgStrm* pFatStream, sal_Int32 nPSize )
pFat = new sal_Int32[ nPages ];
pFree = new sal_Bool[ nPages ];
- StgPage *pPage = NULL;
+ rtl::Reference< StgPage > pPage;
sal_Int32 nFatPageSize = (1 << rIo.aHdr.GetPageSize()) - 2;
for( sal_Int32 nPage = 0; nPage < nPages; nPage++ )
@@ -183,7 +183,7 @@ EasyFat::EasyFat( StgIo& rIo, StgStrm* pFatStream, sal_Int32 nPSize )
pPage = rIo.Get( nPhysPage, sal_True );
}
- pFat[ nPage ] = pPage->GetPage( short( nPage % nFatPageSize ) );
+ pFat[ nPage ] = rIo.GetFromPage( pPage, short( nPage % nFatPageSize ) );
pFree[ nPage ] = sal_True;
}
}
diff --git a/sot/source/sdstor/stgstrms.cxx b/sot/source/sdstor/stgstrms.cxx
index af9aef1eae5c..b2c94ef3b0e2 100644
--- a/sot/source/sdstor/stgstrms.cxx
+++ b/sot/source/sdstor/stgstrms.cxx
@@ -51,9 +51,9 @@ StgFAT::StgFAT( StgStrm& r, sal_Bool m ) : rStrm( r )
// Retrieve the physical page for a given byte offset.
-StgPage* StgFAT::GetPhysPage( sal_Int32 nByteOff )
+rtl::Reference< StgPage > StgFAT::GetPhysPage( sal_Int32 nByteOff )
{
- StgPage* pPg = NULL;
+ rtl::Reference< StgPage > pPg;
// Position within the underlying stream
// use the Pos2Page() method of the stream
if( rStrm.Pos2Page( nByteOff ) )
@@ -72,8 +72,8 @@ sal_Int32 StgFAT::GetNextPage( sal_Int32 nPg )
{
if( nPg >= 0 )
{
- StgPage* pPg = GetPhysPage( nPg << 2 );
- nPg = pPg ? pPg->GetPage( nOffset >> 2 ) : STG_EOF;
+ rtl::Reference< StgPage > pPg = GetPhysPage( nPg << 2 );
+ nPg = pPg.is() ? rStrm.GetIo().GetFromPage( pPg, nOffset >> 2 ) : STG_EOF;
}
return nPg;
}
@@ -91,7 +91,7 @@ sal_Int32 StgFAT::FindBlock( sal_Int32& nPgs )
sal_Int32 nTmpStart = STG_EOF, nTmpLen = 0;
sal_Int32 nPages = rStrm.GetSize() >> 2;
sal_Bool bFound = sal_False;
- StgPage* pPg = NULL;
+ rtl::Reference< StgPage > pPg;
short nEntry = 0;
for( sal_Int32 i = 0; i < nPages; i++, nEntry++ )
{
@@ -100,10 +100,10 @@ sal_Int32 StgFAT::FindBlock( sal_Int32& nPgs )
// load the next page for that stream
nEntry = 0;
pPg = GetPhysPage( i << 2 );
- if( !pPg )
+ if( !pPg.is() )
return STG_EOF;
}
- sal_Int32 nCur = pPg->GetPage( nEntry );
+ sal_Int32 nCur = rStrm.GetIo().GetFromPage( pPg, nEntry );
if( nCur == STG_FREE )
{
// count the size of this area
@@ -167,28 +167,28 @@ sal_Int32 StgFAT::FindBlock( sal_Int32& nPgs )
sal_Bool StgFAT::MakeChain( sal_Int32 nStart, sal_Int32 nPgs )
{
sal_Int32 nPos = nStart << 2;
- StgPage* pPg = GetPhysPage( nPos );
- if( !pPg || !nPgs )
+ rtl::Reference< StgPage > pPg = GetPhysPage( nPos );
+ if( !pPg.is() || !nPgs )
return sal_False;
while( --nPgs )
{
if( nOffset >= nPageSize )
{
pPg = GetPhysPage( nPos );
- if( !pPg )
+ if( !pPg.is() )
return sal_False;
}
- pPg->SetPage( nOffset >> 2, ++nStart );
+ rStrm.GetIo().SetToPage( pPg, nOffset >> 2, ++nStart );
nOffset += 4;
nPos += 4;
}
if( nOffset >= nPageSize )
{
pPg = GetPhysPage( nPos );
- if( !pPg )
+ if( !pPg.is() )
return sal_False;
}
- pPg->SetPage( nOffset >> 2, STG_EOF );
+ rStrm.GetIo().SetToPage( pPg, nOffset >> 2, STG_EOF );
return sal_True;
}
@@ -223,10 +223,10 @@ sal_Int32 StgFAT::AllocPages( sal_Int32 nBgn, sal_Int32 nPgs )
else
{
// Patch the chain
- StgPage* pPg = GetPhysPage( nLast << 2 );
- if( !pPg )
+ rtl::Reference< StgPage > pPg = GetPhysPage( nLast << 2 );
+ if( !pPg.is() )
return STG_EOF;
- pPg->SetPage( nOffset >> 2, nBegin );
+ rStrm.GetIo().SetToPage( pPg, nOffset >> 2, nBegin );
}
nLast = nBegin + nAlloc - 1;
nPgs -= nAlloc;
@@ -264,16 +264,16 @@ sal_Bool StgFAT::InitNew( sal_Int32 nPage1 )
{
while( n-- )
{
- StgPage* pPg = NULL;
+ rtl::Reference< StgPage > pPg;
// Position within the underlying stream
// use the Pos2Page() method of the stream
rStrm.Pos2Page( nPage1 << 2 );
// Initialize the page
pPg = rStrm.GetIo().Copy( rStrm.GetPage(), STG_FREE );
- if ( !pPg )
+ if ( !pPg.is() )
return sal_False;
for( short i = 0; i < nEntries; i++ )
- pPg->SetPage( i, STG_FREE );
+ rStrm.GetIo().SetToPage( pPg, i, STG_FREE );
nPage1++;
}
}
@@ -286,12 +286,12 @@ sal_Bool StgFAT::FreePages( sal_Int32 nStart, sal_Bool bAll )
{
while( nStart >= 0 )
{
- StgPage* pPg = GetPhysPage( nStart << 2 );
- if( !pPg )
+ rtl::Reference< StgPage > pPg = GetPhysPage( nStart << 2 );
+ if( !pPg.is() )
return sal_False;
- nStart = pPg->GetPage( nOffset >> 2 );
+ nStart = rStrm.GetIo().GetFromPage( pPg, nOffset >> 2 );
// The first released page is either set to EOF or FREE
- pPg->SetPage( nOffset >> 2, bAll ? STG_FREE : STG_EOF );
+ rStrm.GetIo().SetToPage( pPg, nOffset >> 2, bAll ? STG_FREE : STG_EOF );
bAll = sal_True;
}
return sal_True;
@@ -441,7 +441,7 @@ sal_Bool StgStrm::Pos2Page( sal_Int32 nBytePos )
// Retrieve the physical page for a given byte offset.
-StgPage* StgStrm::GetPhysPage( sal_Int32 nBytePos, sal_Bool bForce )
+rtl::Reference< StgPage > StgStrm::GetPhysPage( sal_Int32 nBytePos, sal_Bool bForce )
{
if( !Pos2Page( nBytePos ) )
return NULL;
@@ -558,7 +558,7 @@ sal_Bool StgFATStrm::Pos2Page( sal_Int32 nBytePos )
// Since Pos2Page() already has computed the physical offset,
// use the byte offset directly.
-StgPage* StgFATStrm::GetPhysPage( sal_Int32 nBytePos, sal_Bool bForce )
+rtl::Reference< StgPage > StgFATStrm::GetPhysPage( sal_Int32 nBytePos, sal_Bool bForce )
{
OSL_ENSURE( nBytePos >= 0, "The value may not be negative!" );
return rIo.Get( nBytePos / ( nPageSize >> 2 ), bForce );
@@ -580,8 +580,8 @@ sal_Int32 StgFATStrm::GetPage( short nOff, sal_Bool bMake, sal_uInt16 *pnMasterA
// Offset in letzter Masterpage
nOff = nOff % nMasterCount;
- StgPage* pOldPage = 0;
- StgPage* pMaster = 0;
+ rtl::Reference< StgPage > pOldPage;
+ rtl::Reference< StgPage > pMaster;
sal_Int32 nFAT = rIo.aHdr.GetFATChain();
for( sal_uInt16 nCount = 0; nCount <= nBlocks; nCount++ )
{
@@ -594,15 +594,15 @@ sal_Int32 StgFATStrm::GetPage( short nOff, sal_Bool bMake, sal_uInt16 *pnMasterA
// create a new master page
nFAT = nMaxPage++;
pMaster = rIo.Copy( nFAT, STG_FREE );
- if ( pMaster )
+ if ( pMaster.is() )
{
for( short k = 0; k < ( nPageSize >> 2 ); k++ )
- pMaster->SetPage( k, STG_FREE );
+ rIo.SetToPage( pMaster, k, STG_FREE );
// Verkettung herstellen
- if( !pOldPage )
+ if( !pOldPage.is() )
rIo.aHdr.SetFATChain( nFAT );
else
- pOldPage->SetPage( nMasterCount, nFAT );
+ rIo.SetToPage( pOldPage, nMasterCount, nFAT );
if( nMaxPage >= rIo.GetPhysPages() )
if( !rIo.SetSize( nMaxPage ) )
return STG_EOF;
@@ -612,10 +612,10 @@ sal_Int32 StgFATStrm::GetPage( short nOff, sal_Bool bMake, sal_uInt16 *pnMasterA
{
if( !Pos2Page( nFAT << 2 ) )
return STG_EOF;
- StgPage* pPg = rIo.Get( nPage, sal_True );
- if( !pPg )
+ rtl::Reference< StgPage > pPg = rIo.Get( nPage, sal_True );
+ if( !pPg.is() )
return STG_EOF;
- pPg->SetPage( nOffset >> 2, STG_MASTER );
+ rIo.SetToPage( pPg, nOffset >> 2, STG_MASTER );
}
else
(*pnMasterAlloc)++;
@@ -627,15 +627,15 @@ sal_Int32 StgFATStrm::GetPage( short nOff, sal_Bool bMake, sal_uInt16 *pnMasterA
else
{
pMaster = rIo.Get( nFAT, sal_True );
- if ( pMaster )
+ if ( pMaster.is() )
{
- nFAT = pMaster->GetPage( nMasterCount );
+ nFAT = rIo.GetFromPage( pMaster, nMasterCount );
pOldPage = pMaster;
}
}
}
- if( pMaster )
- return pMaster->GetPage( nOff );
+ if( pMaster.is() )
+ return rIo.GetFromPage( pMaster, nOff );
rIo.SetError( SVSTREAM_GENERALERROR );
return STG_EOF;
}
@@ -660,7 +660,7 @@ sal_Bool StgFATStrm::SetPage( short nOff, sal_Int32 nNewPage )
// Offset in letzter Masterpage
nOff = nOff % nMasterCount;
- StgPage* pMaster = 0;
+ rtl::Reference< StgPage > pMaster;
sal_Int32 nFAT = rIo.aHdr.GetFATChain();
for( sal_uInt16 nCount = 0; nCount <= nBlocks; nCount++ )
{
@@ -670,11 +670,11 @@ sal_Bool StgFATStrm::SetPage( short nOff, sal_Int32 nNewPage )
break;
}
pMaster = rIo.Get( nFAT, sal_True );
- if ( pMaster )
- nFAT = pMaster->GetPage( nMasterCount );
+ if ( pMaster.is() )
+ nFAT = rIo.GetFromPage( pMaster, nMasterCount );
}
- if( pMaster )
- pMaster->SetPage( nOff, nNewPage );
+ if( pMaster.is() )
+ rIo.SetToPage( pMaster, nOff, nNewPage );
else
{
rIo.SetError( SVSTREAM_GENERALERROR );
@@ -686,9 +686,9 @@ sal_Bool StgFATStrm::SetPage( short nOff, sal_Int32 nNewPage )
if( bRes )
{
Pos2Page( nNewPage << 2 );
- StgPage* pPg = rIo.Get( nPage, sal_True );
- if( pPg )
- pPg->SetPage( nOffset >> 2, STG_FAT );
+ rtl::Reference< StgPage > pPg = rIo.Get( nPage, sal_True );
+ if( pPg.is() )
+ rIo.SetToPage( pPg, nOffset >> 2, STG_FAT );
else
bRes = sal_False;
}
@@ -745,11 +745,11 @@ sal_Bool StgFATStrm::SetSize( sal_Int32 nBytes )
return sal_False;
}
// Set up the page with empty entries
- StgPage* pPg = rIo.Copy( nNewPage, STG_FREE );
- if ( !pPg )
+ rtl::Reference< StgPage > pPg = rIo.Copy( nNewPage, STG_FREE );
+ if ( !pPg.is() )
return sal_False;
for( short j = 0; j < ( nPageSize >> 2 ); j++ )
- pPg->SetPage( j, STG_FREE );
+ rIo.SetToPage( pPg, j, STG_FREE );
// store the page number into the master FAT
// Set the size before so the correct FAT can be found
@@ -767,14 +767,14 @@ sal_Bool StgFATStrm::SetSize( sal_Int32 nBytes )
return sal_False;
if( nMax - nCount <= nMasterAlloc )
{
- StgPage* piPg = rIo.Get( nPage, sal_True );
- if( !piPg )
+ rtl::Reference< StgPage > piPg = rIo.Get( nPage, sal_True );
+ if( !piPg.is() )
return sal_False;
- piPg->SetPage( nOffset >> 2, STG_MASTER );
+ rIo.SetToPage( piPg, nOffset >> 2, STG_MASTER );
}
- StgPage* pPage = rIo.Get( nFAT, sal_True );
- if( !pPage ) return sal_False;
- nFAT = pPage->GetPage( (nPageSize >> 2 ) - 1 );
+ rtl::Reference< StgPage > pPage = rIo.Get( nFAT, sal_True );
+ if( !pPage.is() ) return sal_False;
+ nFAT = rIo.GetFromPage( pPage, (nPageSize >> 2 ) - 1 );
}
nOld++;
@@ -865,11 +865,11 @@ void* StgDataStrm::GetPtr( sal_Int32 Pos, sal_Bool bForce, sal_Bool bDirty )
{
if( Pos2Page( Pos ) )
{
- StgPage* pPg = rIo.Get( nPage, bForce );
- if (pPg && nOffset < pPg->GetSize())
+ rtl::Reference< StgPage > pPg = rIo.Get( nPage, bForce );
+ if (pPg.is() && nOffset < pPg->GetSize())
{
if( bDirty )
- pPg->SetDirty( true );
+ rIo.SetDirty( pPg );
return ((sal_uInt8 *)pPg->GetData()) + nOffset;
}
}
@@ -891,7 +891,7 @@ sal_Int32 StgDataStrm::Read( void* pBuf, sal_Int32 n )
while( n )
{
short nBytes = nPageSize - nOffset;
- StgPage* pPg;
+ rtl::Reference< StgPage > pPg;
if( (sal_Int32) nBytes > n )
nBytes = (short) n;
if( nBytes )
@@ -901,7 +901,7 @@ sal_Int32 StgDataStrm::Read( void* pBuf, sal_Int32 n )
if( nBytes == nPageSize )
{
pPg = rIo.Find( nPage );
- if( pPg )
+ if( pPg.is() )
{
// data is present, so use the cached data
memcpy( p, pPg->GetData(), nBytes );
@@ -915,7 +915,7 @@ sal_Int32 StgDataStrm::Read( void* pBuf, sal_Int32 n )
{
// partial block read thru the cache.
pPg = rIo.Get( nPage, sal_False );
- if( !pPg )
+ if( !pPg.is() )
break;
memcpy( p, (sal_uInt8*)pPg->GetData() + nOffset, nBytes );
nRes = nBytes;
@@ -950,7 +950,7 @@ sal_Int32 StgDataStrm::Write( const void* pBuf, sal_Int32 n )
while( n )
{
short nBytes = nPageSize - nOffset;
- StgPage* pPg;
+ rtl::Reference< StgPage > pPg;
if( (sal_Int32) nBytes > n )
nBytes = (short) n;
if( nBytes )
@@ -960,11 +960,11 @@ sal_Int32 StgDataStrm::Write( const void* pBuf, sal_Int32 n )
if( nBytes == nPageSize )
{
pPg = rIo.Find( nPage );
- if( pPg )
+ if( pPg.is() )
{
// data is present, so use the cached data
memcpy( pPg->GetData(), p, nBytes );
- pPg->SetDirty( true );
+ rIo.SetDirty( pPg );
nRes = nBytes;
}
else
@@ -975,10 +975,10 @@ sal_Int32 StgDataStrm::Write( const void* pBuf, sal_Int32 n )
{
// partial block read thru the cache.
pPg = rIo.Get( nPage, sal_False );
- if( !pPg )
+ if( !pPg.is() )
break;
memcpy( (sal_uInt8*)pPg->GetData() + nOffset, p, nBytes );
- pPg->SetDirty( true );
+ rIo.SetDirty( pPg );
nRes = nBytes;
}
nDone += nRes;
diff --git a/sot/source/sdstor/stgstrms.hxx b/sot/source/sdstor/stgstrms.hxx
index b7926f0c73a7..1b9f93d99567 100644
--- a/sot/source/sdstor/stgstrms.hxx
+++ b/sot/source/sdstor/stgstrms.hxx
@@ -21,6 +21,7 @@
#define _STGSTRMS_HXX
#include <tools/stream.hxx>
+#include <rtl/ref.hxx>
#include <vector>
class StgIo;
@@ -41,7 +42,7 @@ class StgFAT
short nOffset; // current offset within page
sal_Int32 nLimit; // search limit recommendation
sal_Bool bPhys; // sal_True: physical FAT
- StgPage* GetPhysPage( sal_Int32 nPage );
+ rtl::Reference< StgPage > GetPhysPage( sal_Int32 nPage );
sal_Bool MakeChain( sal_Int32 nStart, sal_Int32 nPages );
sal_Bool InitNew( sal_Int32 nPage1 );
public:
@@ -88,7 +89,7 @@ public:
virtual sal_Bool Pos2Page( sal_Int32 nBytePos );
virtual sal_Int32 Read( void*, sal_Int32 ) { return 0; }
virtual sal_Int32 Write( const void*, sal_Int32 ) { return 0; }
- virtual StgPage* GetPhysPage( sal_Int32 nBytePos, sal_Bool bForce = sal_False );
+ virtual rtl::Reference< StgPage > GetPhysPage( sal_Int32 nBytePos, sal_Bool bForce = sal_False );
virtual sal_Bool IsSmallStrm() const { return sal_False; }
};
@@ -105,7 +106,7 @@ public:
using StgStrm::GetPage;
sal_Int32 GetPage( short, sal_Bool, sal_uInt16 *pnMasterAlloc = 0);
virtual sal_Bool SetSize( sal_Int32 );
- virtual StgPage* GetPhysPage( sal_Int32 nBytePos, sal_Bool bForce = sal_False );
+ virtual rtl::Reference< StgPage > GetPhysPage( sal_Int32 nBytePos, sal_Bool bForce = sal_False );
};
// The stream has a size increment which normally is 1, but which can be