rsc/inc/rscdef.hxx | 2 rsc/source/parser/rscdb.cxx | 49 +++---- rsc/source/rsc/rsc.cxx | 52 ++++---- rsc/source/tools/rscdef.cxx | 31 ++-- tools/inc/tools/pstm.hxx | 2 tools/inc/tools/unqidx.hxx | 124 ++++--------------- tools/source/memtools/unqidx.cxx | 244 +++++++++------------------------------ tools/source/ref/pstm.cxx | 8 - 8 files changed, 166 insertions(+), 346 deletions(-)
New commits: commit 7a597eb6248ef48ebeb23daa40d2c75e5a24d9ee Author: Noel Grandin <n...@peralex.com> Date: Tue Aug 7 14:36:26 2012 +0200 STL'ify UniqueIndex Convert the UniqueIndex code from a macro to a C++ template. Also use std::map as the underlying container instead of tools/contnr.hxx. Change-Id: I0b7b37dd7160ae019aaecdacd1e973ac6d8498e2 diff --git a/rsc/inc/rscdef.hxx b/rsc/inc/rscdef.hxx index 3eeb8ec..be54ad7 100644 --- a/rsc/inc/rscdef.hxx +++ b/rsc/inc/rscdef.hxx @@ -210,7 +210,7 @@ public: sal_Bool IsIncFile(){ return bIncFile; }; }; -DECLARE_UNIQUEINDEX( RscSubFileTab, RscFile * ) +typedef UniqueIndex<RscFile> RscSubFileTab; #define NOFILE_INDEX UNIQUEINDEX_ENTRY_NOTFOUND class RscDefTree { diff --git a/rsc/source/parser/rscdb.cxx b/rsc/source/parser/rscdb.cxx index 42fd1bd..93a3281 100644 --- a/rsc/source/parser/rscdb.cxx +++ b/rsc/source/parser/rscdb.cxx @@ -357,20 +357,20 @@ sal_uInt32 RscTypCont :: PutSysName( sal_uInt32 nRscTyp, char * pFileName, *************************************************************************/ void RscTypCont :: WriteInc( FILE * fOutput, sal_uLong lFileKey ) { - RscFile * pFName; if( NOFILE_INDEX == lFileKey ) { - pFName = aFileTab.First(); - while( pFName ) + sal_uIntPtr aIndex = aFileTab.FirstIndex(); + while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ) { - if( pFName && pFName->IsIncFile() ) + RscFile * pFName = aFileTab.Get( aIndex ); + if( pFName->IsIncFile() ) { fprintf( fOutput, "#include " ); fprintf( fOutput, "\"%s\"\n", pFName->aFileName.getStr() ); } - pFName = aFileTab.Next(); + aIndex = aFileTab.NextIndex( aIndex ); } } else @@ -378,7 +378,7 @@ void RscTypCont :: WriteInc( FILE * fOutput, sal_uLong lFileKey ) RscDepend * pDep; RscFile * pFile; - pFName = aFileTab.Get( lFileKey ); + RscFile * pFName = aFileTab.Get( lFileKey ); if( pFName ) { for ( size_t i = 0, n = pFName->aDepLst.size(); i < n; ++i ) @@ -723,12 +723,13 @@ void RscTypCont :: WriteSrc( FILE * fOutput, sal_uLong nFileKey, if( NOFILE_INDEX == nFileKey ) { - pFName = aFileTab.First(); - while( pFName ){ + sal_uIntPtr aIndex = aFileTab.FirstIndex(); + while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ) { + pFName = aFileTab.Get( aIndex ); if( !pFName->IsIncFile() ) pFName->aDefLst.WriteAll( fOutput ); - aEnumRef.WriteSrc( aFileTab.GetIndex( pFName ) ); - pFName = aFileTab.Next(); + aEnumRef.WriteSrc( aIndex ); + aIndex = aFileTab.NextIndex( aIndex ); }; } else @@ -745,11 +746,11 @@ void RscTypCont :: WriteSrc( FILE * fOutput, sal_uLong nFileKey, RscId::SetNames( sal_False ); if( NOFILE_INDEX == nFileKey ) { - pFName = aFileTab.First(); - while( pFName ) + sal_uIntPtr aIndex = aFileTab.FirstIndex(); + while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ) { - aEnumRef.WriteSrc( aFileTab.GetIndex( pFName ) ); - pFName = aFileTab.Next(); + aEnumRef.WriteSrc( aIndex ); + aIndex = aFileTab.NextIndex( aIndex ); }; } else @@ -805,13 +806,11 @@ ERRTYPE RscTypCont :: WriteHxx( FILE * fOutput, sal_uLong nFileKey ) if( NOFILE_INDEX == nFileKey ) { - RscFile * pFName; - - pFName = aFileTab.First(); - while( pFName ) + sal_uIntPtr aIndex = aFileTab.FirstIndex(); + while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ) { - aError = aEnumRef.WriteHxx( aFileTab.GetIndex( pFName ) ); - pFName = aFileTab.Next(); + aError = aEnumRef.WriteHxx( aIndex ); + aIndex = aFileTab.NextIndex( aIndex ); }; } else @@ -838,13 +837,11 @@ ERRTYPE RscTypCont::WriteCxx( FILE * fOutput, sal_uLong nFileKey, if( NOFILE_INDEX == nFileKey ) { - RscFile * pFName; - - pFName = aFileTab.First(); - while( pFName ) + sal_uIntPtr aIndex = aFileTab.FirstIndex(); + while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ) { - aError = aEnumRef.WriteCxx( aFileTab.GetIndex( pFName ) ); - pFName = aFileTab.Next(); + aError = aEnumRef.WriteCxx( aIndex ); + aIndex = aFileTab.NextIndex( aIndex ); }; } else diff --git a/rsc/source/rsc/rsc.cxx b/rsc/source/rsc/rsc.cxx index d422de9..9199659 100644 --- a/rsc/source/rsc/rsc.cxx +++ b/rsc/source/rsc/rsc.cxx @@ -453,18 +453,17 @@ ERRTYPE RscCompiler::Start() pTC->pEH->SetListFile( NULL ); - pFName = pTC->aFileTab.First(); - while( pFName && aError.IsOk() ) + sal_uIntPtr aIndex = pTC->aFileTab.FirstIndex(); + while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND && aError.IsOk() ) { + pFName = pTC->aFileTab.Get( aIndex ); if( !pFName->bScanned && !pFName->IsIncFile() ) { - aError = IncludeParser( - pTC->aFileTab.GetIndex( pFName ) - ); + aError = IncludeParser( aIndex ); // Currentzeiger richtig setzen - pTC->aFileTab.Seek( pFName ); + aIndex = pTC->aFileTab.GetIndexOf( pFName ); }; - pFName = pTC->aFileTab.Next(); + aIndex = pTC->aFileTab.NextIndex( aIndex ); }; pTC->pEH->SetListFile( fListing ); @@ -474,12 +473,13 @@ ERRTYPE RscCompiler::Start() if ( pTC->pEH->GetVerbosity() >= RscVerbosityVerbose ) { pTC->pEH->StdOut( "Files: " ); - pFName = pTC->aFileTab.First(); - while( pFName ) + sal_uIntPtr aIndex = pTC->aFileTab.FirstIndex(); + while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ) { + pFName = pTC->aFileTab.Get( aIndex ); pTC->pEH->StdOut( pFName->aFileName.getStr() ); pTC->pEH->StdOut( " " ); - pFName = pTC->aFileTab.Next(); + aIndex = pTC->aFileTab.NextIndex( aIndex ); }; pTC->pEH->StdOut( "\n" ); } @@ -522,9 +522,10 @@ void RscCompiler::EndCompile() else { // Schreibe Datei - pFN = pTC->aFileTab.First(); - while( pFN ) + sal_uIntPtr aIndex = pTC->aFileTab.FirstIndex(); + while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ) { + pFN = pTC->aFileTab.Get( aIndex ); if( !pFN->IsIncFile() ) { pTC->WriteSrc( foutput, NOFILE_INDEX, sal_False ); @@ -788,12 +789,15 @@ ERRTYPE RscCompiler::Link() for( it = pCL->m_aOutputFiles.begin(); it != pCL->m_aOutputFiles.end(); ++it ) { // cleanup nodes - for( pFName = pTC->aFileTab.First(); pFName && aError.IsOk(); pFName = pTC->aFileTab.Next() ) + for( sal_uIntPtr aIndex = pTC->aFileTab.FirstIndex(); + aIndex != UNIQUEINDEX_ENTRY_NOTFOUND && aError.IsOk(); + aIndex = pTC->aFileTab.NextIndex( aIndex ) ) { + pFName = pTC->aFileTab.Get( aIndex ); if( !pFName->IsIncFile() ) { - pTC->Delete( pTC->aFileTab.GetIndex( pFName ) ); - pTC->aFileTab.Seek( pFName ); + pTC->Delete( aIndex ); + aIndex = pTC->aFileTab.GetIndexOf( pFName ); pFName->bLoaded = sal_False; } } @@ -886,12 +890,15 @@ ERRTYPE RscCompiler::Link() } // parse files for specific language - for( pFName = pTC->aFileTab.First(); pFName && aError.IsOk(); pFName = pTC->aFileTab.Next() ) + for( sal_uIntPtr aIndex = pTC->aFileTab.FirstIndex(); + aIndex != UNIQUEINDEX_ENTRY_NOTFOUND && aError.IsOk(); + aIndex = pTC->aFileTab.NextIndex( aIndex ) ) { + pFName = pTC->aFileTab.Get( aIndex ); if( !pFName->IsIncFile() ) { - aError = ParseOneFile( pTC->aFileTab.GetIndex( pFName ), &*it, &aContext ); - pTC->aFileTab.Seek( pFName ); + aError = ParseOneFile( aIndex, &*it, &aContext ); + aIndex = pTC->aFileTab.GetIndexOf( pFName ); } }; @@ -935,12 +942,15 @@ ERRTYPE RscCompiler::Link() else { // parse files - for( pFName = pTC->aFileTab.First(); pFName && aError.IsOk(); pFName = pTC->aFileTab.Next() ) + for( sal_uIntPtr aIndex = pTC->aFileTab.FirstIndex(); + aIndex != UNIQUEINDEX_ENTRY_NOTFOUND && aError.IsOk(); + aIndex = pTC->aFileTab.NextIndex( aIndex ) ) { + pFName = pTC->aFileTab.Get( aIndex ); if( !pFName->IsIncFile() ) { - aError = ParseOneFile( pTC->aFileTab.GetIndex( pFName ), NULL, NULL ); - pTC->aFileTab.Seek( pFName ); + aError = ParseOneFile( aIndex, NULL, NULL ); + aIndex = pTC->aFileTab.GetIndexOf( pFName ); } }; } diff --git a/rsc/source/tools/rscdef.cxx b/rsc/source/tools/rscdef.cxx index 6c11ec9..6f12022 100644 --- a/rsc/source/tools/rscdef.cxx +++ b/rsc/source/tools/rscdef.cxx @@ -653,15 +653,13 @@ RscFileTab::RscFileTab(){ |* *************************************************************************/ RscFileTab :: ~RscFileTab(){ - RscFile * pFile; aDefTree.Remove(); - pFile = Last(); - while( pFile ){ - Remove( GetIndex( pFile ) ); - delete pFile; - pFile = Prev(); + sal_uIntPtr aIndex = LastIndex(); + while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ) { + delete Remove( aIndex ); + aIndex = LastIndex(); }; } @@ -672,16 +670,14 @@ RscFileTab :: ~RscFileTab(){ *************************************************************************/ sal_uLong RscFileTab :: Find( const rtl::OString& rName ) { - RscFile * pFName; - - pFName = First(); - while( pFName && (pFName->aFileName != rName) ) - pFName = Next(); + sal_uIntPtr aIndex = FirstIndex(); + while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND && (Get(aIndex)->aFileName != rName) ) + aIndex = NextIndex(aIndex); - if( pFName ) - return( GetIndex( pFName ) ); + if( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ) + return aIndex; else - return( NOFILE_INDEX ); + return NOFILE_INDEX; } /************************************************************************* @@ -702,13 +698,14 @@ sal_Bool RscFileTab::Depend( sal_uLong lDepend, sal_uLong lFree ){ if( lDepend == lFree ) return sal_True; - RscFile * pFile = First(); - while( pFile ){ + sal_uIntPtr aIndex = FirstIndex(); + while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ){ + RscFile * pFile = Get(aIndex); if( !pFile->IsIncFile() ){ if( !pFile->Depend( lDepend, lFree ) ) return sal_False; }; - pFile = Next(); + aIndex = NextIndex(aIndex); }; return sal_True; diff --git a/tools/inc/tools/pstm.hxx b/tools/inc/tools/pstm.hxx index c313b6b..64a3b64 100644 --- a/tools/inc/tools/pstm.hxx +++ b/tools/inc/tools/pstm.hxx @@ -134,7 +134,7 @@ public:\ SV_DECL_PERSIST_LIST(ClassName,EntryName)\ SV_IMPL_PERSIST_LIST(ClassName,EntryName) -DECLARE_UNIQUEINDEX( SvPersistUIdx,SvPersistBase *) +typedef UniqueIndex<SvPersistBase> SvPersistUIdx; typedef std::map<SvPersistBase*, sal_uIntPtr> PersistBaseMap; diff --git a/tools/inc/tools/unqidx.hxx b/tools/inc/tools/unqidx.hxx index aeaa7e7..9938961 100644 --- a/tools/inc/tools/unqidx.hxx +++ b/tools/inc/tools/unqidx.hxx @@ -22,6 +22,7 @@ #include "tools/toolsdllapi.h" #include <tools/solar.h> #include <tools/contnr.hxx> +#include <map> // --------------- // - UniqueIndex - @@ -29,109 +30,46 @@ #define UNIQUEINDEX_ENTRY_NOTFOUND CONTAINER_ENTRY_NOTFOUND -class TOOLS_DLLPUBLIC UniqueIndex : private Container +class TOOLS_DLLPUBLIC UniqueIndexImpl : public std::map<sal_uInt32, void*> { private: - sal_uIntPtr nReSize; sal_uIntPtr nStartIndex; sal_uIntPtr nUniqIndex; sal_uIntPtr nCount; - void* Seek( sal_uIntPtr nIndex ); //not implemented - public: - using Container::GetCurObject; - - UniqueIndex( sal_uIntPtr nStartIndex = 0, - sal_uIntPtr nInitSize = 16, - sal_uIntPtr nReSize = 16 ); - UniqueIndex( const UniqueIndex& rIdx ); - - sal_uIntPtr Insert( sal_uIntPtr nIndex, void* p ); - sal_uIntPtr Insert( void* p ); - void* Remove( sal_uIntPtr nIndex ); - void* Get( sal_uIntPtr nIndex ) const; - - void Clear(); - sal_uIntPtr Count() const { return nCount; } - - sal_uIntPtr GetCurIndex() const; - sal_uIntPtr GetIndex( const void* p ) const; - - void* Seek( void* p ); - void* First(); - void* Last(); - void* Next(); - void* Prev(); - - sal_uIntPtr GetStartIndex() const { return nStartIndex; } - sal_uIntPtr GetCurMaxIndex() const - { return (nStartIndex + Container::GetSize()); } - - UniqueIndex& operator =( const UniqueIndex& rIdx ); - - sal_Bool operator ==( const UniqueIndex& rIdx ) const; - sal_Bool operator !=( const UniqueIndex& rIdx ) const - { return !(UniqueIndex::operator==( rIdx )); } + UniqueIndexImpl( sal_uIntPtr _nStartIndex = 0 ) + : std::map<sal_uInt32, void*>(), + nStartIndex(_nStartIndex), nUniqIndex(_nStartIndex), nCount(0) {} + + sal_uIntPtr Insert( void* p ); + // insert value with key, replacing existing entry if necessary + void Insert( sal_uIntPtr aIndex, void* p ); + void* Remove( sal_uIntPtr aIndex ); + void* Get( sal_uIntPtr aIndex ) const; + + sal_uIntPtr GetIndexOf( void* p ) const; + sal_uIntPtr FirstIndex() const; + sal_uIntPtr LastIndex() const; + sal_uIntPtr NextIndex( sal_uIntPtr aCurrIndex ) const; }; -inline void UniqueIndex::Clear() +template<typename T> +class UniqueIndex : private UniqueIndexImpl { - Container::Clear(); - nCount = 0; - nUniqIndex = 0; -} - -// ----------------------- -// - DECLARE_UNIQUEINDEX - -// ----------------------- - -#define DECLARE_UNIQUEINDEX( ClassName, Type ) \ -class ClassName : private UniqueIndex \ -{ \ - Type Seek( sal_uIntPtr nKey ); \ -public: \ - using UniqueIndex::Clear; \ - using UniqueIndex::Count; \ - using UniqueIndex::GetCurIndex; \ - using UniqueIndex::GetStartIndex; \ - using UniqueIndex::GetCurMaxIndex; \ - \ - ClassName( sal_uIntPtr _nStartIndex = 0, \ - sal_uIntPtr _nInitSize = 16, sal_uIntPtr _nReSize = 16 ):\ - UniqueIndex( _nStartIndex, _nInitSize, _nReSize ) {}\ - ClassName( const ClassName& rClassName ) : \ - UniqueIndex( rClassName ) {} \ - \ - sal_uIntPtr Insert( sal_uIntPtr nIndex, Type p ) \ - { return UniqueIndex::Insert( nIndex, (void*)p ); } \ - sal_uIntPtr Insert( Type p ) \ - { return UniqueIndex::Insert( (void*)p ); } \ - Type Remove( sal_uIntPtr nIndex ) \ - { return (Type)UniqueIndex::Remove( nIndex ); } \ - Type Get( sal_uIntPtr nIndex ) const \ - { return (Type)UniqueIndex::Get( nIndex ); } \ - \ - Type GetCurObject() const \ - { return (Type)UniqueIndex::GetCurObject(); } \ - sal_uIntPtr GetIndex( const Type p ) const \ - { return UniqueIndex::GetIndex( (const void*)p ); } \ - \ - Type Seek( Type p ) \ - { return (Type)UniqueIndex::Seek( (void*)p ); } \ - Type First() { return (Type)UniqueIndex::First(); } \ - Type Last() { return (Type)UniqueIndex::Last(); } \ - Type Next() { return (Type)UniqueIndex::Next(); } \ - Type Prev() { return (Type)UniqueIndex::Prev(); } \ - \ - ClassName& operator =( const ClassName& rClassName ) \ - { UniqueIndex::operator =( rClassName ); \ - return *this; } \ - \ - sal_Bool operator ==( const ClassName& rIdx ) const \ - { return UniqueIndex::operator ==( rIdx ); } \ - sal_Bool operator !=( const ClassName& rIdx ) const \ - { return UniqueIndex::operator !=( rIdx ); } \ +public: + UniqueIndex<T>( sal_uIntPtr _nStartIndex = 0 ) : UniqueIndexImpl(_nStartIndex) {} + + sal_uIntPtr Insert(T* p) { return UniqueIndexImpl::Insert(p); } + void Insert(sal_uIntPtr aIdx, T* p) { return UniqueIndexImpl::Insert(aIdx, p); } + T* Get(sal_uIntPtr idx) const { return static_cast<T*>( UniqueIndexImpl::Get(idx) ); } + T* Remove(sal_uIntPtr idx) { return static_cast<T*>( UniqueIndexImpl::Remove(idx) ); } + sal_uIntPtr Count() const { return UniqueIndexImpl::size(); } + sal_uIntPtr GetIndexOf(T* p) const { return UniqueIndexImpl::GetIndexOf(p); } + + using UniqueIndexImpl::FirstIndex; + using UniqueIndexImpl::LastIndex; + using UniqueIndexImpl::NextIndex; }; #endif // _UNQIDX_HXX diff --git a/tools/source/memtools/unqidx.cxx b/tools/source/memtools/unqidx.cxx index a66a481..63539d0 100644 --- a/tools/source/memtools/unqidx.cxx +++ b/tools/source/memtools/unqidx.cxx @@ -20,36 +20,6 @@ #include <impcont.hxx> #include <tools/unqidx.hxx> -/************************************************************************* -|* -|* UniqueIndex::UniqueIndex() -|* -*************************************************************************/ - -UniqueIndex::UniqueIndex( sal_uIntPtr _nStartIndex, - sal_uIntPtr _nInitSize, sal_uIntPtr _nReSize ) : - Container( _nInitSize ) -{ - nReSize = _nReSize; - nStartIndex = _nStartIndex; - nUniqIndex = 0; - nCount = 0; -} - -/************************************************************************* -|* -|* UniqueIndex::UniqueIndex() -|* -*************************************************************************/ - -UniqueIndex::UniqueIndex( const UniqueIndex& rIdx ) : - Container( rIdx ) -{ - nReSize = rIdx.nReSize; - nStartIndex = rIdx.nStartIndex; - nUniqIndex = rIdx.nUniqIndex; - nCount = rIdx.nCount; -} /************************************************************************* |* @@ -57,25 +27,26 @@ UniqueIndex::UniqueIndex( const UniqueIndex& rIdx ) : |* *************************************************************************/ -sal_uIntPtr UniqueIndex::Insert( void* p ) +sal_uIntPtr UniqueIndexImpl::Insert( void* p ) { // NULL-Pointer ist nicht erlaubt if ( !p ) return UNIQUEINDEX_ENTRY_NOTFOUND; - // Ist Array voll, dann expandieren - if ( nCount == Container::GetSize() ) - SetSize( nCount + nReSize ); + // Ist Array voll, dann expandieren + sal_uIntPtr nTmp = size(); + if( nTmp == nCount ) + nTmp++; // Damit UniqIndex nicht ueberlaeuft, wenn Items geloescht wurden - nUniqIndex = nUniqIndex % Container::GetSize(); + nUniqIndex = nUniqIndex % nTmp; // Leeren Eintrag suchen - while ( Container::ImpGetObject( nUniqIndex ) != NULL ) - nUniqIndex = (nUniqIndex+1) % Container::GetSize(); + while ( find( nUniqIndex ) != end() ) + nUniqIndex = (nUniqIndex+1) % nTmp; // Object im Array speichern - Container::Replace( p, nUniqIndex ); + (*this)[ nUniqIndex ] = p; // Anzahl der Eintraege erhoehen und Index zurueckgeben nCount++; @@ -85,222 +56,129 @@ sal_uIntPtr UniqueIndex::Insert( void* p ) /************************************************************************* |* -|* UniqueIndex::Insert() +|* UniqueIndexImpl::Insert() |* *************************************************************************/ -sal_uIntPtr UniqueIndex::Insert( sal_uIntPtr nIndex, void* p ) +void UniqueIndexImpl::Insert( sal_uIntPtr nIndex, void* p ) { // NULL-Pointer ist nicht erlaubt if ( !p ) - return UNIQUEINDEX_ENTRY_NOTFOUND; + return; sal_uIntPtr nContIndex = nIndex - nStartIndex; - // Ist Array voll, dann expandieren - if ( nContIndex >= Container::GetSize() ) - SetSize( nContIndex + nReSize ); + + bool bFound = find( nContIndex ) != end(); // Object im Array speichern - Container::Replace( p, nContIndex ); + (*this)[ nContIndex ] = p; - // Anzahl der Eintraege erhoehen und Index zurueckgeben - nCount++; - return nIndex; + if( !bFound ) + nCount++; } /************************************************************************* |* -|* UniqueIndex::Remove() +|* UniqueIndexImpl::Remove() |* *************************************************************************/ -void* UniqueIndex::Remove( sal_uIntPtr nIndex ) +void* UniqueIndexImpl::Remove( sal_uIntPtr nIndex ) { // Ist Index zulaessig if ( (nIndex >= nStartIndex) && - (nIndex < (Container::GetSize()+nStartIndex)) ) + (nIndex < (size() + nStartIndex)) ) { // Index-Eintrag als leeren Eintrag setzen und Anzahl der // gespeicherten Indexe erniedriegen, wenn Eintrag belegt war - void* p = Container::Replace( NULL, nIndex-nStartIndex ); - if ( p ) + iterator it = find( nIndex - nStartIndex ); + if( it != end() ) + { + void* p = it->second; + erase( it ); nCount--; - return p; + return p; + } } - else - return NULL; + return NULL; } /************************************************************************* |* -|* UniqueIndex::Get() +|* UniqueIndexImpl::Get() |* *************************************************************************/ -void* UniqueIndex::Get( sal_uIntPtr nIndex ) const +void* UniqueIndexImpl::Get( sal_uIntPtr nIndex ) const { // Ist Index zulaessig if ( (nIndex >= nStartIndex) && - (nIndex < (Container::GetSize()+nStartIndex)) ) - return Container::ImpGetObject( nIndex-nStartIndex ); - else - return NULL; -} - -/************************************************************************* -|* -|* UniqueIndex::GetCurIndex() -|* -*************************************************************************/ - -sal_uIntPtr UniqueIndex::GetCurIndex() const -{ - sal_uIntPtr nPos = Container::GetCurPos(); - - // Ist der Current-Index nicht belegt, dann gibt es keinen Current-Index - if ( !Container::ImpGetObject( nPos ) ) - return UNIQUEINDEX_ENTRY_NOTFOUND; - else - return nPos+nStartIndex; + (nIndex < (size() + nStartIndex)) ) + { + const_iterator it = find( nIndex - nStartIndex ); + if( it != end() ) + return it->second; + } + return NULL; } /************************************************************************* |* -|* UniqueIndex::GetIndex() +|* UniqueIndexImpl::FirstIndex() |* *************************************************************************/ -sal_uIntPtr UniqueIndex::GetIndex( const void* p ) const +sal_uIntPtr UniqueIndexImpl::FirstIndex() const { - // Wird ein NULL-Pointer uebergeben, dann wurde Pointer nicht gefunden - if ( !p ) - return UNIQUEINDEX_ENTRY_NOTFOUND; - - sal_uIntPtr nIndex = Container::GetPos( p ); - - if ( nIndex != CONTAINER_ENTRY_NOTFOUND ) - return nIndex+nStartIndex; - else + if ( empty() ) return UNIQUEINDEX_ENTRY_NOTFOUND; -} - -/************************************************************************* -|* -|* UniqueIndex::Seek() -|* -*************************************************************************/ - -void* UniqueIndex::Seek( void* p ) -{ - // Wird ein NULL-Pointer uebergeben, dann wurde Pointer nicht gefunden - if ( !p ) - return NULL; - - sal_uIntPtr nIndex = GetIndex( p ); - - // Ist Index vorhanden, dann als aktuellen Eintrag setzen - if ( nIndex != UNIQUEINDEX_ENTRY_NOTFOUND ) - return Container::Seek( nIndex-nStartIndex ); - else - return NULL; -} - -/************************************************************************* -|* -|* UniqueIndex::First() -|* -*************************************************************************/ - -void* UniqueIndex::First() -{ - void* p = Container::First(); - - while ( !p && (Container::GetCurPos() < (Container::GetSize()-1)) ) - p = Container::Next(); - - return p; -} - -/************************************************************************* -|* -|* UniqueIndex::Last() -|* -*************************************************************************/ - -void* UniqueIndex::Last() -{ - void* p = Container::Last(); - - while ( !p && Container::GetCurPos() ) - p = Container::Prev(); - - return p; -} - -/************************************************************************* -|* -|* UniqueIndex::Next() -|* -*************************************************************************/ - -void* UniqueIndex::Next() -{ - void* p = NULL; - while ( !p && (Container::GetCurPos() < (Container::GetSize()-1)) ) - p = Container::Next(); - - return p; + return begin()->first; } /************************************************************************* |* -|* UniqueIndex::Prev() +|* UniqueIndexImpl::LastIndex() |* *************************************************************************/ -void* UniqueIndex::Prev() +sal_uIntPtr UniqueIndexImpl::LastIndex() const { - void* p = NULL; - - while ( !p && Container::GetCurPos() ) - p = Container::Prev(); + if ( empty() ) + return UNIQUEINDEX_ENTRY_NOTFOUND; - return p; + return rbegin()->first; } /************************************************************************* |* -|* UniqueIndex::operator =() +|* UniqueIndexImpl::NextIndex() |* *************************************************************************/ -UniqueIndex& UniqueIndex::operator =( const UniqueIndex& rIdx ) +sal_uIntPtr UniqueIndexImpl::NextIndex(sal_uIntPtr aIndex) const { - // Neue Werte zuweisen - Container::operator =( rIdx ); - nReSize = rIdx.nReSize; - nStartIndex = rIdx.nStartIndex; - nUniqIndex = rIdx.nUniqIndex; - nCount = rIdx.nCount; - return *this; + const_iterator it = find( aIndex ); + if ( it == end() ) + return UNIQUEINDEX_ENTRY_NOTFOUND; + it++; + if ( it == end() ) + return UNIQUEINDEX_ENTRY_NOTFOUND; + return it->first; } /************************************************************************* |* -|* UniqueIndex::operator ==() +|* UniqueIndexImpl::GetIndexOf() |* *************************************************************************/ -sal_Bool UniqueIndex::operator ==( const UniqueIndex& rIdx ) const +sal_uIntPtr UniqueIndexImpl::GetIndexOf(void* p) const { - // Neue Werte zuweisen - if ( (nStartIndex == rIdx.nStartIndex) && - (nCount == rIdx.nCount) && - (Container::operator ==( rIdx )) ) - return sal_True; - else - return sal_False; + for( const_iterator it = begin(); it != end(); ++it ) + if( it->second == p ) + return it->first; + return UNIQUEINDEX_ENTRY_NOTFOUND; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/ref/pstm.cxx b/tools/source/ref/pstm.cxx index 442d266..064a09b 100644 --- a/tools/source/ref/pstm.cxx +++ b/tools/source/ref/pstm.cxx @@ -792,14 +792,14 @@ SvStream& operator << rThis << bTmp; // Version sal_uInt32 nCount = (sal_uInt32)rThis.aPUIdx.Count(); rThis << nCount; - SvPersistBase * pEle = rThis.aPUIdx.First(); + sal_uIntPtr aIndex = rThis.aPUIdx.FirstIndex(); for( sal_uInt32 i = 0; i < nCount; i++ ) { + SvPersistBase * pEle = rThis.aPUIdx.Get(aIndex); sal_uInt8 nP = P_OBJ | P_ID | P_STD; - WriteId( rThis, nP, rThis.aPUIdx.GetCurIndex(), - pEle->GetClassId() ); + WriteId( rThis, nP, aIndex, pEle->GetClassId() ); rThis.WriteObj( nP, pEle ); - pEle = rThis.aPUIdx.Next(); + aIndex = rThis.aPUIdx.NextIndex( aIndex ); } rThis.SetStream( pOldStm ); return rStm; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits