diff options
author | Jan Holesovsky <kendy@suse.cz> | 2011-08-15 13:08:50 +0200 |
---|---|---|
committer | Jan Holesovsky <kendy@suse.cz> | 2011-08-15 13:11:54 +0200 |
commit | 433ae0f62df90e6158571c2c3dbed05c14bfa900 (patch) | |
tree | d2cad5c015619c5712548563c2787dcc35871a01 /sfx2 | |
parent | fa77c78adaf0035000a0c107379ccd5abd348c91 (diff) |
Remove WordArr and DECL_2BYTEARRAY, used only once.
Instead that, use std::basic_string.
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/inc/sfx2/minarray.hxx | 65 | ||||
-rw-r--r-- | sfx2/inc/sfx2/msgpool.hxx | 5 | ||||
-rw-r--r-- | sfx2/source/bastyp/minarray.cxx | 233 | ||||
-rw-r--r-- | sfx2/source/control/msgpool.cxx | 26 |
4 files changed, 15 insertions, 314 deletions
diff --git a/sfx2/inc/sfx2/minarray.hxx b/sfx2/inc/sfx2/minarray.hxx index 37c82cfe7c04..d17151dbe273 100644 --- a/sfx2/inc/sfx2/minarray.hxx +++ b/sfx2/inc/sfx2/minarray.hxx @@ -390,71 +390,6 @@ public:\ void Clear() { Remove( 0, Count() ); }\ }; -class WordArr -{ -private: - short* pData; - sal_uInt16 nUsed; - sal_uInt8 nGrow; - sal_uInt8 nUnused; -public: - WordArr( sal_uInt8 nInitSize = 0, sal_uInt8 nGrowSize = 8 ); - WordArr( const WordArr& rOrig ); - ~WordArr(); - WordArr& operator= ( const WordArr& rOrig ); - short GetObject( sal_uInt16 nPos ) const { return operator[](nPos); } - short& GetObject( sal_uInt16 nPos ) { return operator[](nPos); } - void Insert( sal_uInt16 nPos, short rElem ); - void Append( short rElem ); - sal_Bool Remove( short rElem ); - sal_uInt16 Remove( sal_uInt16 nPos, sal_uInt16 nLen ); - sal_uInt16 Count() const { return nUsed; } - short* operator*(); - short operator[]( sal_uInt16 nPos ) const; - short& operator[]( sal_uInt16 nPos ); - sal_Bool Contains( const short rItem ) const; - void Clear() { Remove( 0, Count() ); } -}; - -inline short* WordArr::operator*() -{ - return ( nUsed==0 ? 0 : pData ); -} - -#define DECL_2BYTEARRAY(ARR, T, nI, nG)\ -class ARR: public WordArr\ -{\ -public:\ - ARR( sal_uInt8 nIni=nI, sal_uInt8 nGrowValue=nG ):\ - WordArr(nIni,nGrowValue) \ - {}\ - ARR( const ARR& rOrig ):\ - WordArr(rOrig) \ - {}\ - T GetObject( sal_uInt16 nPos ) const { return operator[](nPos); } \ - T& GetObject( sal_uInt16 nPos ) { return operator[](nPos); } \ - void Insert( sal_uInt16 nPos, T aElement ) {\ - WordArr::Insert(nPos,(short)aElement);\ - }\ - void Append( T aElement ) {\ - WordArr::Append((short)aElement);\ - }\ - void Remove( T aElement ) {\ - WordArr::Remove((short)aElement);\ - }\ - void Remove( sal_uInt16 nPos, sal_uInt16 nLen = 1 ) {\ - WordArr::Remove( nPos, nLen ); \ - }\ - T* operator *() {\ - return (T*) WordArr::operator*();\ - }\ - T operator[]( sal_uInt16 nPos ) const { \ - return (T) WordArr::operator[](nPos); } \ - T& operator[]( sal_uInt16 nPos ) { \ - return (T&) WordArr::operator[](nPos); } \ - void Clear() { Remove( 0, Count() ); }\ -}; - #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/inc/sfx2/msgpool.hxx b/sfx2/inc/sfx2/msgpool.hxx index 05854edbb010..41de48549453 100644 --- a/sfx2/inc/sfx2/msgpool.hxx +++ b/sfx2/inc/sfx2/msgpool.hxx @@ -36,13 +36,16 @@ #include <tools/string.hxx> #include <svl/svarray.hxx> +#include <string> + class SfxInterface; class SfxSlot; class SfxInterfaceArr_Impl; -class SfxSlotGroupArr_Impl; class SfxSlotTypeArr_Impl; class SfxSlotArr_Impl; +typedef std::basic_string< sal_uInt16 > SfxSlotGroupArr_Impl; + //========================================================================= class SFX2_DLLPUBLIC SfxSlotPool diff --git a/sfx2/source/bastyp/minarray.cxx b/sfx2/source/bastyp/minarray.cxx index 2137c625d70f..70e4bfbfc6ca 100644 --- a/sfx2/source/bastyp/minarray.cxx +++ b/sfx2/source/bastyp/minarray.cxx @@ -267,237 +267,4 @@ void SfxPtrArr::Insert( sal_uInt16 nPos, void* rElem ) nUnused -= 1; } -// class WordArr --------------------------------------------------------- - -WordArr::WordArr( sal_uInt8 nInitSize, sal_uInt8 nGrowSize ): - nUsed( 0 ), - nGrow( nGrowSize ? nGrowSize : 1 ), - nUnused( nInitSize ) -{ - DBG_MEMTEST(); - sal_uInt16 nMSCBug = nInitSize; - - if ( nInitSize > 0 ) - pData = new short[nMSCBug]; - else - pData = 0; -} - -// ----------------------------------------------------------------------- - -WordArr::WordArr( const WordArr& rOrig ) -{ - DBG_MEMTEST(); - nUsed = rOrig.nUsed; - nGrow = rOrig.nGrow; - nUnused = rOrig.nUnused; - - if ( rOrig.pData != 0 ) - { - pData = new short[nUsed+nUnused]; - memcpy( pData, rOrig.pData, nUsed*sizeof(short) ); - } - else - pData = 0; -} - -// ----------------------------------------------------------------------- - -WordArr::~WordArr() -{ - DBG_MEMTEST(); - delete [] pData; -} - -// ----------------------------------------------------------------------- - -WordArr& WordArr::operator=( const WordArr& rOrig ) -{ - DBG_MEMTEST(); - - delete [] pData; - - nUsed = rOrig.nUsed; - nGrow = rOrig.nGrow; - nUnused = rOrig.nUnused; - - if ( rOrig.pData != 0 ) - { - pData = new short[nUsed+nUnused]; - memcpy( pData, rOrig.pData, nUsed*sizeof(short) ); - } - else - pData = 0; - return *this; -} - -// ----------------------------------------------------------------------- - -void WordArr::Append( short aElem ) -{ - DBG_MEMTEST(); - // Does the Array need to be copied? - if ( nUnused == 0 ) - { - sal_uInt16 nNewSize = (nUsed == 1) ? (nGrow==1 ? 2 : nGrow) : nUsed+nGrow; - short* pNewData = new short[nNewSize]; - if ( pData ) - { - DBG_ASSERT( nUsed <= nNewSize, " " ); - memmove( pNewData, pData, sizeof(short)*nUsed ); - delete [] pData; - } - nUnused = sal::static_int_cast< sal_uInt8 >(nNewSize-nUsed); - pData = pNewData; - } - - // now write at the back in the open space - pData[nUsed] = aElem; - ++nUsed; - --nUnused; -} - -// ----------------------------------------------------------------------- - -sal_uInt16 WordArr::Remove( sal_uInt16 nPos, sal_uInt16 nLen ) -{ - DBG_MEMTEST(); - // Adjust nLen, thus to avoid deleting beyond the end - nLen = Min( (sal_uInt16)(nUsed-nPos), nLen ); - - // simple problems require simple solutions! - if ( nLen == 0 ) - return 0; - - // Maybe no one will remain - if ( (nUsed-nLen) == 0 ) - { - delete [] pData; - pData = 0; - nUsed = 0; - nUnused = 0; - return nLen; - } - - // Determine whether the array has physically shrunk... - if ( (nUnused+nLen) >= nGrow ) - { - // reduce (rounded up) to the next Grow-border - sal_uInt16 nNewUsed = nUsed-nLen; - sal_uInt16 nNewSize = ((nNewUsed+nGrow-1)/nGrow) * nGrow; - DBG_ASSERT( nNewUsed <= nNewSize && nNewUsed+nGrow > nNewSize, - "shrink size computation failed" ); - short* pNewData = new short[nNewSize]; - if ( nPos > 0 ) - { - DBG_ASSERT( nPos <= nNewSize, "" ); - memmove( pNewData, pData, sizeof(short)*nPos ); - } - if ( nNewUsed != nPos ) - memmove( pNewData+nPos, pData+nPos+nLen, - sizeof(short)*(nNewUsed-nPos) ); - delete [] pData; - pData = pNewData; - nUsed = nNewUsed; - nUnused = sal::static_int_cast< sal_uInt8 >(nNewSize - nNewUsed); - return nLen; - } - - // in all other cases, only push together - if ( nUsed-nPos-nLen > 0 ) - memmove( pData+nPos, pData+nPos+nLen, (nUsed-nPos-nLen)*sizeof(short) ); - nUsed = nUsed - nLen; - nUnused = sal::static_int_cast< sal_uInt8 >(nUnused + nLen); - return nLen; -} - -// ----------------------------------------------------------------------- - -sal_Bool WordArr::Remove( short aElem ) -{ - DBG_MEMTEST(); - // simple tasks ... - if ( nUsed == 0 ) - return sal_False; - - // backwards, since most of the last is first removed - short *pIter = pData + nUsed - 1; - for ( sal_uInt16 n = 0; n < nUsed; ++n, --pIter ) - if ( *pIter == aElem ) - { - Remove(nUsed-n-1, 1); - return sal_True; - } - return sal_False; -} - -// ----------------------------------------------------------------------- - -sal_Bool WordArr::Contains( const short rItem ) const -{ - DBG_MEMTEST(); - if ( !nUsed ) - return sal_False; - - for ( sal_uInt16 n = 0; n < nUsed; ++n ) - { - short p = GetObject(n); - if ( p == rItem ) - return sal_True; - } - - return sal_False; -} - -// ----------------------------------------------------------------------- - -void WordArr::Insert( sal_uInt16 nPos, short rElem ) -{ - DBG_MEMTEST(); - // Does the Array need to be copied? - if ( nUnused == 0 ) - { - // increase (rounded up) to the next Grow-border - sal_uInt16 nNewSize = nUsed+nGrow; - short* pNewData = new short[nNewSize]; - - if ( pData ) - { - DBG_ASSERT( nUsed < nNewSize, "" ); - memmove( pNewData, pData, sizeof(short)*nUsed ); - delete [] pData; - } - nUnused = sal::static_int_cast< sal_uInt8 >(nNewSize-nUsed); - pData = pNewData; - } - - // Now move the rear part - if ( nPos < nUsed ) - memmove( pData+nPos+1, pData+nPos, (nUsed-nPos)*sizeof(short) ); - - // now write at the back in the open space - memmove( pData+nPos, &rElem, sizeof(short) ); - nUsed += 1; - nUnused -= 1; -} - -// ----------------------------------------------------------------------- - -short WordArr::operator[]( sal_uInt16 nPos ) const -{ - DBG_MEMTEST(); - DBG_ASSERT( nPos < nUsed, "" ); - return *(pData+nPos); -} - -// ----------------------------------------------------------------------- - -short& WordArr::operator [] (sal_uInt16 nPos) -{ - DBG_MEMTEST(); - DBG_ASSERT( nPos < nUsed, "" ); - return *(pData+nPos); -} - - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/control/msgpool.cxx b/sfx2/source/control/msgpool.cxx index b2afa3dc1e22..7a4441032662 100644 --- a/sfx2/source/control/msgpool.cxx +++ b/sfx2/source/control/msgpool.cxx @@ -57,11 +57,9 @@ struct SfxSlotType_Impl {} }; -DECL_2BYTEARRAY(SfxSlotGroupArr_Impl, sal_uInt16, 6, 4) DECL_PTRARRAY(SfxInterfaceArr_Impl, SfxInterface*, 6, 3) DECL_PTRARRAY(SfxSlotTypeArr_Impl, SfxSlotType_Impl*, 8, 8) - //==================================================================== SfxSlotPool::SfxSlotPool( SfxSlotPool *pParent, ResMgr* pResManager ) @@ -121,9 +119,7 @@ void SfxSlotPool::RegisterInterface( SfxInterface& rInterface ) if ( _pParentPool ) { // The Groups in parent Slotpool are also known here - SfxSlotGroupArr_Impl& rGroups = *_pParentPool->_pGroups; - for ( sal_uInt16 n=0; n<rGroups.Count(); n++ ) - _pGroups->Append( rGroups[n] ); + _pGroups->append( *_pParentPool->_pGroups ); } } @@ -133,12 +129,12 @@ void SfxSlotPool::RegisterInterface( SfxInterface& rInterface ) { SfxSlot *pDef = rInterface[nFunc]; if ( pDef->GetGroupId() && /* pDef->GetGroupId() != GID_INTERN && */ - !_pGroups->Contains(pDef->GetGroupId()) ) + _pGroups->find(pDef->GetGroupId()) == SfxSlotGroupArr_Impl::npos ) { if (pDef->GetGroupId() == GID_INTERN) - _pGroups->Insert(0, pDef->GetGroupId()); + _pGroups->insert(_pGroups->begin(), pDef->GetGroupId()); else - _pGroups->Append(pDef->GetGroupId()); + _pGroups->push_back(pDef->GetGroupId()); } } } @@ -193,13 +189,13 @@ String SfxSlotPool::SeekGroup( sal_uInt16 nNo ) DBG_ASSERT( _pInterfaces != 0, "no Interfaces registered" ); // if the group exists, use it - if ( _pGroups && nNo < _pGroups->Count() ) + if ( _pGroups && nNo < _pGroups->size() ) { _nCurGroup = nNo; if ( _pParentPool ) { // In most cases, the order of the IDs agree - sal_uInt16 nParentCount = _pParentPool->_pGroups->Count(); + sal_uInt16 nParentCount = _pParentPool->_pGroups->size(); if ( nNo < nParentCount && (*_pGroups)[nNo] == (*_pParentPool->_pGroups)[nNo] ) _pParentPool->_nCurGroup = nNo; else @@ -233,7 +229,7 @@ String SfxSlotPool::SeekGroup( sal_uInt16 nNo ) sal_uInt16 SfxSlotPool::GetGroupCount() { - return _pGroups->Count(); + return _pGroups->size(); } @@ -251,7 +247,7 @@ const SfxSlot* SfxSlotPool::SeekSlot( sal_uInt16 nStartInterface ) // have reached the end of the Parent-Pools? if ( nStartInterface < nFirstInterface && - _pParentPool->_nCurGroup >= _pParentPool->_pGroups->Count() ) + _pParentPool->_nCurGroup >= _pParentPool->_pGroups->size() ) nStartInterface = nFirstInterface; // Is the Interface still in the Parent-Pool? @@ -274,7 +270,7 @@ const SfxSlot* SfxSlotPool::SeekSlot( sal_uInt16 nStartInterface ) ++_nCurMsg ) { const SfxSlot* pMsg = (*pInterface)[_nCurMsg]; - if ( pMsg->GetGroupId() == _pGroups->GetObject(_nCurGroup) ) + if ( pMsg->GetGroupId() == _pGroups->at(_nCurGroup) ) return pMsg; } } @@ -293,7 +289,7 @@ const SfxSlot* SfxSlotPool::NextSlot() // The numbering starts at the interfaces of the parent pool sal_uInt16 nFirstInterface = _pParentPool ? _pParentPool->_pInterfaces->Count() : 0; - if ( _nCurInterface < nFirstInterface && _nCurGroup >= _pParentPool->_pGroups->Count() ) + if ( _nCurInterface < nFirstInterface && _nCurGroup >= _pParentPool->_pGroups->size() ) _nCurInterface = nFirstInterface; if ( _nCurInterface < nFirstInterface ) @@ -318,7 +314,7 @@ const SfxSlot* SfxSlotPool::NextSlot() while ( ++_nCurMsg < pInterface->Count() ) { SfxSlot* pMsg = (*pInterface)[_nCurMsg]; - if ( pMsg->GetGroupId() == _pGroups->GetObject(_nCurGroup) ) + if ( pMsg->GetGroupId() == _pGroups->at(_nCurGroup) ) return pMsg; } |