Kaydet (Commit) 2207f9c7 authored tarafından Kohei Yoshida's avatar Kohei Yoshida

Refactored SfxItemPool for better encapsulation.

Basically everything except pItemInfos is under pImp.  This will
make it easier for future refactoring in the implementation area.
üst ba75626b
......@@ -87,8 +87,6 @@ public:
virtual void ObjectInDestruction(const SfxItemPool& rSfxItemPool) = 0;
};
typedef ::std::vector< SfxItemPoolUser* > SfxItemPoolUserVector;
class SVL_DLLPUBLIC SfxItemPool
/* [Beschreibung]
......@@ -105,28 +103,14 @@ class SVL_DLLPUBLIC SfxItemPool
*/
{
SVL_DLLPRIVATE void readTheItems(SvStream & rStream, sal_uInt32 nCount, sal_uInt16 nVersion,
SfxPoolItem * pDefItem, SfxPoolItemArray_Impl ** pArr);
friend struct SfxItemPool_Impl;
UniString aName;
sal_uInt16 nStart, nEnd;
sal_uInt16 _nFileFormatVersion;
#ifdef TF_POOLABLE
const SfxItemInfo* pItemInfos;
#else
#error "TF_POOLABLE should always be set."
#endif
SfxItemPool_Impl* pImp;
SfxPoolItem** ppStaticDefaults;
SfxPoolItem** ppPoolDefaults;
SfxItemPool* pSecondary;
SfxItemPool* pMaster;
sal_uInt16* _pPoolRanges;
bool bPersistentRefCounts;
private:
// ObjectUser section
SfxItemPoolUserVector maSfxItemPoolUsers;
public:
void AddSfxItemPoolUser(SfxItemPoolUser& rNewUser);
......@@ -138,8 +122,8 @@ public:
friend class SfxPoolWhichMap;
private:
inline sal_uInt16 GetIndex_Impl(sal_uInt16 nWhich) const;
inline sal_uInt16 GetSize_Impl() const { return nEnd - nStart + 1; }
sal_uInt16 GetIndex_Impl(sal_uInt16 nWhich) const;
sal_uInt16 GetSize_Impl() const;
SVL_DLLPRIVATE SvStream& Load1_Impl( SvStream &rStream );
SVL_DLLPRIVATE bool IsItemFlag_Impl( sal_uInt16 nWhich, sal_uInt16 nFlag ) const;
......@@ -147,15 +131,16 @@ private:
public:
// fuer dflt. SfxItemSet::CTOR, setze dflt. WhichRanges
void FillItemIdRanges_Impl( sal_uInt16*& pWhichRanges ) const;
const sal_uInt16* GetFrozenIdRanges() const
{ return _pPoolRanges; }
const sal_uInt16* GetFrozenIdRanges() const;
#endif
//---------------------------------------------------------------------
protected:
static inline void SetRefCount( SfxPoolItem& rItem, sal_uLong n );
static inline sal_uLong AddRef( const SfxPoolItem& rItem, sal_uLong n = 1 );
static inline sal_uLong ReleaseRef( const SfxPoolItem& rItem, sal_uLong n = 1);
static inline sal_uLong AddRef( const SfxPoolItem& rItem, sal_uLong n = 1 );
static inline sal_uLong ReleaseRef( const SfxPoolItem& rItem, sal_uLong n = 1);
static inline void SetKind( SfxPoolItem& rItem, sal_uInt16 nRef );
public:
SfxItemPool( const SfxItemPool &rPool,
......@@ -196,7 +181,7 @@ public:
const IntlWrapper * pIntlWrapper
= 0 ) const;
virtual SfxItemPool* Clone() const;
UniString const & GetName() const { return aName; }
const UniString& GetName() const;
virtual const SfxPoolItem& Put( const SfxPoolItem&, sal_uInt16 nWhich = 0 );
virtual void Remove( const SfxPoolItem& );
......@@ -220,23 +205,18 @@ public:
virtual SvStream & Load(SvStream &);
virtual SvStream & Store(SvStream &) const;
int HasPersistentRefCounts() const {
return bPersistentRefCounts; }
bool HasPersistentRefCounts() const;
void LoadCompleted();
sal_uInt16 GetFirstWhich() const { return nStart; }
sal_uInt16 GetLastWhich() const { return nEnd; }
bool IsInRange( sal_uInt16 nWhich ) const {
return nWhich >= nStart &&
nWhich <= nEnd; }
sal_uInt16 GetFirstWhich() const;
sal_uInt16 GetLastWhich() const;
bool IsInRange( sal_uInt16 nWhich ) const;
bool IsInVersionsRange( sal_uInt16 nWhich ) const;
bool IsInStoringRange( sal_uInt16 nWhich ) const;
void SetStoringRange( sal_uInt16 nFrom, sal_uInt16 nTo );
void SetSecondaryPool( SfxItemPool *pPool );
SfxItemPool* GetSecondaryPool() const {
return pSecondary; }
SfxItemPool* GetMasterPool() const {
return pMaster; }
SfxItemPool* GetSecondaryPool() const;
SfxItemPool* GetMasterPool() const;
void FreezeIdRanges();
void Delete();
......@@ -250,18 +230,17 @@ public:
#else
#error "TF_POOLABLE should always be set."
#endif
sal_uInt16 GetWhich( sal_uInt16 nSlot, sal_Bool bDeep = sal_True ) const;
sal_uInt16 GetSlotId( sal_uInt16 nWhich, sal_Bool bDeep = sal_True ) const;
sal_uInt16 GetTrueWhich( sal_uInt16 nSlot, sal_Bool bDeep = sal_True ) const;
sal_uInt16 GetTrueSlotId( sal_uInt16 nWhich, sal_Bool bDeep = sal_True ) const;
sal_uInt16 GetWhich( sal_uInt16 nSlot, sal_Bool bDeep = sal_True ) const;
sal_uInt16 GetSlotId( sal_uInt16 nWhich, sal_Bool bDeep = sal_True ) const;
sal_uInt16 GetTrueWhich( sal_uInt16 nSlot, sal_Bool bDeep = sal_True ) const;
sal_uInt16 GetTrueSlotId( sal_uInt16 nWhich, sal_Bool bDeep = sal_True ) const;
void SetVersionMap( sal_uInt16 nVer,
sal_uInt16 nOldStart, sal_uInt16 nOldEnd,
sal_uInt16 *pWhichIdTab );
sal_uInt16 GetNewWhich( sal_uInt16 nOldWhich ) const;
sal_uInt16 GetVersion() const;
sal_uInt16 GetFileFormatVersion() const
{ return _nFileFormatVersion; }
sal_uInt16 GetNewWhich( sal_uInt16 nOldWhich ) const;
sal_uInt16 GetVersion() const;
sal_uInt16 GetFileFormatVersion() const;
void SetFileFormatVersion( sal_uInt16 nFileFormatVersion );
bool IsCurrentVersionLoading() const;
......@@ -296,6 +275,11 @@ inline sal_uLong SfxItemPool::ReleaseRef( const SfxPoolItem& rItem, sal_uLong n
return rItem.ReleaseRef(n);
}
inline void SfxItemPool::SetKind( SfxPoolItem& rItem, sal_uInt16 nRef )
{
rItem.SetKind( nRef );
}
#endif
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
......@@ -28,6 +28,7 @@
#include <svl/brdcst.hxx>
#include <boost/shared_ptr.hpp>
#include <deque>
#include <vector>
#ifndef DELETEZ
#define DELETEZ(pPtr) { delete pPtr; pPtr = 0; }
......@@ -74,8 +75,18 @@ class SfxStyleSheetIterator;
struct SfxItemPool_Impl
{
SfxBroadcaster aBC;
SfxPoolItemArray_Impl** ppPoolItems;
std::vector<SfxPoolItemArray_Impl*> maPoolItems;
std::vector<SfxItemPoolUser*> maSfxItemPoolUsers; /// ObjectUser section
UniString aName;
SfxPoolItem** ppPoolDefaults;
SfxPoolItem** ppStaticDefaults;
SfxItemPool* mpMaster;
SfxItemPool* mpSecondary;
sal_uInt16* mpPoolRanges;
SfxPoolVersionArr_Impl aVersions;
sal_uInt16 mnStart;
sal_uInt16 mnEnd;
sal_uInt16 mnFileFormatVersion;
sal_uInt16 nVersion;
sal_uInt16 nLoadingVersion;
sal_uInt16 nInitRefCount; // 1, beim Laden ggf. 2
......@@ -85,9 +96,19 @@ struct SfxItemPool_Impl
SfxMapUnit eDefMetric;
bool bInSetItem;
bool bStreaming; // in Load() bzw. Store()
SfxItemPool_Impl( sal_uInt16 nStart, sal_uInt16 nEnd )
: ppPoolItems (new SfxPoolItemArray_Impl*[ nEnd - nStart + 1])
bool mbPersistentRefCounts;
SfxItemPool_Impl( SfxItemPool* pMaster, const UniString& rName, sal_uInt16 nStart, sal_uInt16 nEnd )
: maPoolItems(nEnd - nStart + 1, NULL)
, aName(rName)
, ppPoolDefaults(new SfxPoolItem* [nEnd - nStart + 1])
, ppStaticDefaults(0)
, mpMaster(pMaster)
, mpSecondary(NULL)
, mpPoolRanges(NULL)
, mnStart(nStart)
, mnEnd(nEnd)
, mnFileFormatVersion(0)
, nLoadingVersion(0)
, nInitRefCount(0)
, nVerStart(0)
......@@ -99,19 +120,30 @@ struct SfxItemPool_Impl
, bInSetItem(false)
, bStreaming(false)
{
memset( ppPoolItems, 0, sizeof( SfxPoolItemArray_Impl* ) * ( nEnd - nStart + 1) );
DBG_ASSERT(mnStart, "Start-Which-Id must be greater 0" );
memset( ppPoolDefaults, 0, sizeof( SfxPoolItem* ) * (nEnd - nStart + 1));
}
~SfxItemPool_Impl()
{
delete[] ppPoolItems;
DeleteItems();
}
void DeleteItems()
{
delete[] ppPoolItems;
ppPoolItems = 0;
std::vector<SfxPoolItemArray_Impl*>::iterator itr = maPoolItems.begin(), itrEnd = maPoolItems.end();
for (; itr != itrEnd; ++itr)
delete *itr;
maPoolItems.clear();
delete[] mpPoolRanges;
mpPoolRanges = NULL;
delete[] ppPoolDefaults;
ppPoolDefaults = NULL;
}
void readTheItems(SvStream & rStream, sal_uInt32 nCount, sal_uInt16 nVersion,
SfxPoolItem * pDefItem, SfxPoolItemArray_Impl ** pArr);
};
// -----------------------------------------------------------------------
......@@ -204,13 +236,4 @@ struct SfxItemPool_Impl
#define SFX_STYLES_REC_HEADER sal_uInt16(0x0010)
#define SFX_STYLES_REC_STYLES sal_uInt16(0x0020)
//========================================================================
inline sal_uInt16 SfxItemPool::GetIndex_Impl(sal_uInt16 nWhich) const
{
DBG_CHKTHIS(SfxItemPool, 0);
DBG_ASSERT(nWhich >= nStart && nWhich <= nEnd, "Which-Id nicht im Pool-Bereich");
return nWhich - nStart;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment