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
This commit is contained in:
committed by
Tor Lillqvist
parent
976deb6b99
commit
7a597eb624
@@ -210,7 +210,7 @@ public:
|
|||||||
sal_Bool IsIncFile(){ return bIncFile; };
|
sal_Bool IsIncFile(){ return bIncFile; };
|
||||||
};
|
};
|
||||||
|
|
||||||
DECLARE_UNIQUEINDEX( RscSubFileTab, RscFile * )
|
typedef UniqueIndex<RscFile> RscSubFileTab;
|
||||||
#define NOFILE_INDEX UNIQUEINDEX_ENTRY_NOTFOUND
|
#define NOFILE_INDEX UNIQUEINDEX_ENTRY_NOTFOUND
|
||||||
|
|
||||||
class RscDefTree {
|
class RscDefTree {
|
||||||
|
@@ -357,20 +357,20 @@ sal_uInt32 RscTypCont :: PutSysName( sal_uInt32 nRscTyp, char * pFileName,
|
|||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
void RscTypCont :: WriteInc( FILE * fOutput, sal_uLong lFileKey )
|
void RscTypCont :: WriteInc( FILE * fOutput, sal_uLong lFileKey )
|
||||||
{
|
{
|
||||||
RscFile * pFName;
|
|
||||||
|
|
||||||
if( NOFILE_INDEX == lFileKey )
|
if( NOFILE_INDEX == lFileKey )
|
||||||
{
|
{
|
||||||
pFName = aFileTab.First();
|
sal_uIntPtr aIndex = aFileTab.FirstIndex();
|
||||||
while( pFName )
|
while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND )
|
||||||
{
|
{
|
||||||
if( pFName && pFName->IsIncFile() )
|
RscFile * pFName = aFileTab.Get( aIndex );
|
||||||
|
if( pFName->IsIncFile() )
|
||||||
{
|
{
|
||||||
fprintf( fOutput, "#include " );
|
fprintf( fOutput, "#include " );
|
||||||
fprintf( fOutput, "\"%s\"\n",
|
fprintf( fOutput, "\"%s\"\n",
|
||||||
pFName->aFileName.getStr() );
|
pFName->aFileName.getStr() );
|
||||||
}
|
}
|
||||||
pFName = aFileTab.Next();
|
aIndex = aFileTab.NextIndex( aIndex );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -378,7 +378,7 @@ void RscTypCont :: WriteInc( FILE * fOutput, sal_uLong lFileKey )
|
|||||||
RscDepend * pDep;
|
RscDepend * pDep;
|
||||||
RscFile * pFile;
|
RscFile * pFile;
|
||||||
|
|
||||||
pFName = aFileTab.Get( lFileKey );
|
RscFile * pFName = aFileTab.Get( lFileKey );
|
||||||
if( pFName )
|
if( pFName )
|
||||||
{
|
{
|
||||||
for ( size_t i = 0, n = pFName->aDepLst.size(); i < n; ++i )
|
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 )
|
if( NOFILE_INDEX == nFileKey )
|
||||||
{
|
{
|
||||||
pFName = aFileTab.First();
|
sal_uIntPtr aIndex = aFileTab.FirstIndex();
|
||||||
while( pFName ){
|
while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ) {
|
||||||
|
pFName = aFileTab.Get( aIndex );
|
||||||
if( !pFName->IsIncFile() )
|
if( !pFName->IsIncFile() )
|
||||||
pFName->aDefLst.WriteAll( fOutput );
|
pFName->aDefLst.WriteAll( fOutput );
|
||||||
aEnumRef.WriteSrc( aFileTab.GetIndex( pFName ) );
|
aEnumRef.WriteSrc( aIndex );
|
||||||
pFName = aFileTab.Next();
|
aIndex = aFileTab.NextIndex( aIndex );
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -745,11 +746,11 @@ void RscTypCont :: WriteSrc( FILE * fOutput, sal_uLong nFileKey,
|
|||||||
RscId::SetNames( sal_False );
|
RscId::SetNames( sal_False );
|
||||||
if( NOFILE_INDEX == nFileKey )
|
if( NOFILE_INDEX == nFileKey )
|
||||||
{
|
{
|
||||||
pFName = aFileTab.First();
|
sal_uIntPtr aIndex = aFileTab.FirstIndex();
|
||||||
while( pFName )
|
while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND )
|
||||||
{
|
{
|
||||||
aEnumRef.WriteSrc( aFileTab.GetIndex( pFName ) );
|
aEnumRef.WriteSrc( aIndex );
|
||||||
pFName = aFileTab.Next();
|
aIndex = aFileTab.NextIndex( aIndex );
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -805,13 +806,11 @@ ERRTYPE RscTypCont :: WriteHxx( FILE * fOutput, sal_uLong nFileKey )
|
|||||||
|
|
||||||
if( NOFILE_INDEX == nFileKey )
|
if( NOFILE_INDEX == nFileKey )
|
||||||
{
|
{
|
||||||
RscFile * pFName;
|
sal_uIntPtr aIndex = aFileTab.FirstIndex();
|
||||||
|
while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND )
|
||||||
pFName = aFileTab.First();
|
|
||||||
while( pFName )
|
|
||||||
{
|
{
|
||||||
aError = aEnumRef.WriteHxx( aFileTab.GetIndex( pFName ) );
|
aError = aEnumRef.WriteHxx( aIndex );
|
||||||
pFName = aFileTab.Next();
|
aIndex = aFileTab.NextIndex( aIndex );
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -838,13 +837,11 @@ ERRTYPE RscTypCont::WriteCxx( FILE * fOutput, sal_uLong nFileKey,
|
|||||||
|
|
||||||
if( NOFILE_INDEX == nFileKey )
|
if( NOFILE_INDEX == nFileKey )
|
||||||
{
|
{
|
||||||
RscFile * pFName;
|
sal_uIntPtr aIndex = aFileTab.FirstIndex();
|
||||||
|
while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND )
|
||||||
pFName = aFileTab.First();
|
|
||||||
while( pFName )
|
|
||||||
{
|
{
|
||||||
aError = aEnumRef.WriteCxx( aFileTab.GetIndex( pFName ) );
|
aError = aEnumRef.WriteCxx( aIndex );
|
||||||
pFName = aFileTab.Next();
|
aIndex = aFileTab.NextIndex( aIndex );
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@@ -453,18 +453,17 @@ ERRTYPE RscCompiler::Start()
|
|||||||
|
|
||||||
pTC->pEH->SetListFile( NULL );
|
pTC->pEH->SetListFile( NULL );
|
||||||
|
|
||||||
pFName = pTC->aFileTab.First();
|
sal_uIntPtr aIndex = pTC->aFileTab.FirstIndex();
|
||||||
while( pFName && aError.IsOk() )
|
while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND && aError.IsOk() )
|
||||||
{
|
{
|
||||||
|
pFName = pTC->aFileTab.Get( aIndex );
|
||||||
if( !pFName->bScanned && !pFName->IsIncFile() )
|
if( !pFName->bScanned && !pFName->IsIncFile() )
|
||||||
{
|
{
|
||||||
aError = IncludeParser(
|
aError = IncludeParser( aIndex );
|
||||||
pTC->aFileTab.GetIndex( pFName )
|
|
||||||
);
|
|
||||||
// Currentzeiger richtig setzen
|
// 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 );
|
pTC->pEH->SetListFile( fListing );
|
||||||
@@ -474,12 +473,13 @@ ERRTYPE RscCompiler::Start()
|
|||||||
if ( pTC->pEH->GetVerbosity() >= RscVerbosityVerbose )
|
if ( pTC->pEH->GetVerbosity() >= RscVerbosityVerbose )
|
||||||
{
|
{
|
||||||
pTC->pEH->StdOut( "Files: " );
|
pTC->pEH->StdOut( "Files: " );
|
||||||
pFName = pTC->aFileTab.First();
|
sal_uIntPtr aIndex = pTC->aFileTab.FirstIndex();
|
||||||
while( pFName )
|
while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND )
|
||||||
{
|
{
|
||||||
|
pFName = pTC->aFileTab.Get( aIndex );
|
||||||
pTC->pEH->StdOut( pFName->aFileName.getStr() );
|
pTC->pEH->StdOut( pFName->aFileName.getStr() );
|
||||||
pTC->pEH->StdOut( " " );
|
pTC->pEH->StdOut( " " );
|
||||||
pFName = pTC->aFileTab.Next();
|
aIndex = pTC->aFileTab.NextIndex( aIndex );
|
||||||
};
|
};
|
||||||
pTC->pEH->StdOut( "\n" );
|
pTC->pEH->StdOut( "\n" );
|
||||||
}
|
}
|
||||||
@@ -522,9 +522,10 @@ void RscCompiler::EndCompile()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Schreibe Datei
|
// Schreibe Datei
|
||||||
pFN = pTC->aFileTab.First();
|
sal_uIntPtr aIndex = pTC->aFileTab.FirstIndex();
|
||||||
while( pFN )
|
while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND )
|
||||||
{
|
{
|
||||||
|
pFN = pTC->aFileTab.Get( aIndex );
|
||||||
if( !pFN->IsIncFile() )
|
if( !pFN->IsIncFile() )
|
||||||
{
|
{
|
||||||
pTC->WriteSrc( foutput, NOFILE_INDEX, sal_False );
|
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 )
|
for( it = pCL->m_aOutputFiles.begin(); it != pCL->m_aOutputFiles.end(); ++it )
|
||||||
{
|
{
|
||||||
// cleanup nodes
|
// 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() )
|
if( !pFName->IsIncFile() )
|
||||||
{
|
{
|
||||||
pTC->Delete( pTC->aFileTab.GetIndex( pFName ) );
|
pTC->Delete( aIndex );
|
||||||
pTC->aFileTab.Seek( pFName );
|
aIndex = pTC->aFileTab.GetIndexOf( pFName );
|
||||||
pFName->bLoaded = sal_False;
|
pFName->bLoaded = sal_False;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -886,12 +890,15 @@ ERRTYPE RscCompiler::Link()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// parse files for specific language
|
// 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() )
|
if( !pFName->IsIncFile() )
|
||||||
{
|
{
|
||||||
aError = ParseOneFile( pTC->aFileTab.GetIndex( pFName ), &*it, &aContext );
|
aError = ParseOneFile( aIndex, &*it, &aContext );
|
||||||
pTC->aFileTab.Seek( pFName );
|
aIndex = pTC->aFileTab.GetIndexOf( pFName );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -935,12 +942,15 @@ ERRTYPE RscCompiler::Link()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
// parse files
|
// 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() )
|
if( !pFName->IsIncFile() )
|
||||||
{
|
{
|
||||||
aError = ParseOneFile( pTC->aFileTab.GetIndex( pFName ), NULL, NULL );
|
aError = ParseOneFile( aIndex, NULL, NULL );
|
||||||
pTC->aFileTab.Seek( pFName );
|
aIndex = pTC->aFileTab.GetIndexOf( pFName );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -653,15 +653,13 @@ RscFileTab::RscFileTab(){
|
|||||||
|*
|
|*
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
RscFileTab :: ~RscFileTab(){
|
RscFileTab :: ~RscFileTab(){
|
||||||
RscFile * pFile;
|
|
||||||
|
|
||||||
aDefTree.Remove();
|
aDefTree.Remove();
|
||||||
|
|
||||||
pFile = Last();
|
sal_uIntPtr aIndex = LastIndex();
|
||||||
while( pFile ){
|
while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ) {
|
||||||
Remove( GetIndex( pFile ) );
|
delete Remove( aIndex );
|
||||||
delete pFile;
|
aIndex = LastIndex();
|
||||||
pFile = Prev();
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -672,16 +670,14 @@ RscFileTab :: ~RscFileTab(){
|
|||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
sal_uLong RscFileTab :: Find( const rtl::OString& rName )
|
sal_uLong RscFileTab :: Find( const rtl::OString& rName )
|
||||||
{
|
{
|
||||||
RscFile * pFName;
|
sal_uIntPtr aIndex = FirstIndex();
|
||||||
|
while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND && (Get(aIndex)->aFileName != rName) )
|
||||||
|
aIndex = NextIndex(aIndex);
|
||||||
|
|
||||||
pFName = First();
|
if( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND )
|
||||||
while( pFName && (pFName->aFileName != rName) )
|
return aIndex;
|
||||||
pFName = Next();
|
|
||||||
|
|
||||||
if( pFName )
|
|
||||||
return( GetIndex( pFName ) );
|
|
||||||
else
|
else
|
||||||
return( NOFILE_INDEX );
|
return NOFILE_INDEX;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
@@ -702,13 +698,14 @@ sal_Bool RscFileTab::Depend( sal_uLong lDepend, sal_uLong lFree ){
|
|||||||
if( lDepend == lFree )
|
if( lDepend == lFree )
|
||||||
return sal_True;
|
return sal_True;
|
||||||
|
|
||||||
RscFile * pFile = First();
|
sal_uIntPtr aIndex = FirstIndex();
|
||||||
while( pFile ){
|
while( aIndex != UNIQUEINDEX_ENTRY_NOTFOUND ){
|
||||||
|
RscFile * pFile = Get(aIndex);
|
||||||
if( !pFile->IsIncFile() ){
|
if( !pFile->IsIncFile() ){
|
||||||
if( !pFile->Depend( lDepend, lFree ) )
|
if( !pFile->Depend( lDepend, lFree ) )
|
||||||
return sal_False;
|
return sal_False;
|
||||||
};
|
};
|
||||||
pFile = Next();
|
aIndex = NextIndex(aIndex);
|
||||||
};
|
};
|
||||||
|
|
||||||
return sal_True;
|
return sal_True;
|
||||||
|
@@ -134,7 +134,7 @@ public:\
|
|||||||
SV_DECL_PERSIST_LIST(ClassName,EntryName)\
|
SV_DECL_PERSIST_LIST(ClassName,EntryName)\
|
||||||
SV_IMPL_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;
|
typedef std::map<SvPersistBase*, sal_uIntPtr> PersistBaseMap;
|
||||||
|
|
||||||
|
@@ -22,6 +22,7 @@
|
|||||||
#include "tools/toolsdllapi.h"
|
#include "tools/toolsdllapi.h"
|
||||||
#include <tools/solar.h>
|
#include <tools/solar.h>
|
||||||
#include <tools/contnr.hxx>
|
#include <tools/contnr.hxx>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
// ---------------
|
// ---------------
|
||||||
// - UniqueIndex -
|
// - UniqueIndex -
|
||||||
@@ -29,109 +30,46 @@
|
|||||||
|
|
||||||
#define UNIQUEINDEX_ENTRY_NOTFOUND CONTAINER_ENTRY_NOTFOUND
|
#define UNIQUEINDEX_ENTRY_NOTFOUND CONTAINER_ENTRY_NOTFOUND
|
||||||
|
|
||||||
class TOOLS_DLLPUBLIC UniqueIndex : private Container
|
class TOOLS_DLLPUBLIC UniqueIndexImpl : public std::map<sal_uInt32, void*>
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
sal_uIntPtr nReSize;
|
|
||||||
sal_uIntPtr nStartIndex;
|
sal_uIntPtr nStartIndex;
|
||||||
sal_uIntPtr nUniqIndex;
|
sal_uIntPtr nUniqIndex;
|
||||||
sal_uIntPtr nCount;
|
sal_uIntPtr nCount;
|
||||||
|
|
||||||
void* Seek( sal_uIntPtr nIndex ); //not implemented
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
using Container::GetCurObject;
|
UniqueIndexImpl( sal_uIntPtr _nStartIndex = 0 )
|
||||||
|
: std::map<sal_uInt32, void*>(),
|
||||||
|
nStartIndex(_nStartIndex), nUniqIndex(_nStartIndex), nCount(0) {}
|
||||||
|
|
||||||
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 );
|
sal_uIntPtr Insert( void* p );
|
||||||
void* Remove( sal_uIntPtr nIndex );
|
// insert value with key, replacing existing entry if necessary
|
||||||
void* Get( sal_uIntPtr nIndex ) const;
|
void Insert( sal_uIntPtr aIndex, void* p );
|
||||||
|
void* Remove( sal_uIntPtr aIndex );
|
||||||
|
void* Get( sal_uIntPtr aIndex ) const;
|
||||||
|
|
||||||
void Clear();
|
sal_uIntPtr GetIndexOf( void* p ) const;
|
||||||
sal_uIntPtr Count() const { return nCount; }
|
sal_uIntPtr FirstIndex() const;
|
||||||
|
sal_uIntPtr LastIndex() const;
|
||||||
sal_uIntPtr GetCurIndex() const;
|
sal_uIntPtr NextIndex( sal_uIntPtr aCurrIndex ) 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 )); }
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline void UniqueIndex::Clear()
|
template<typename T>
|
||||||
|
class UniqueIndex : private UniqueIndexImpl
|
||||||
{
|
{
|
||||||
Container::Clear();
|
public:
|
||||||
nCount = 0;
|
UniqueIndex<T>( sal_uIntPtr _nStartIndex = 0 ) : UniqueIndexImpl(_nStartIndex) {}
|
||||||
nUniqIndex = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// -----------------------
|
sal_uIntPtr Insert(T* p) { return UniqueIndexImpl::Insert(p); }
|
||||||
// - DECLARE_UNIQUEINDEX -
|
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); }
|
||||||
|
|
||||||
#define DECLARE_UNIQUEINDEX( ClassName, Type ) \
|
using UniqueIndexImpl::FirstIndex;
|
||||||
class ClassName : private UniqueIndex \
|
using UniqueIndexImpl::LastIndex;
|
||||||
{ \
|
using UniqueIndexImpl::NextIndex;
|
||||||
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 ); } \
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // _UNQIDX_HXX
|
#endif // _UNQIDX_HXX
|
||||||
|
@@ -20,36 +20,6 @@
|
|||||||
#include <impcont.hxx>
|
#include <impcont.hxx>
|
||||||
#include <tools/unqidx.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
|
// NULL-Pointer ist nicht erlaubt
|
||||||
if ( !p )
|
if ( !p )
|
||||||
return UNIQUEINDEX_ENTRY_NOTFOUND;
|
return UNIQUEINDEX_ENTRY_NOTFOUND;
|
||||||
|
|
||||||
// Ist Array voll, dann expandieren
|
// Ist Array voll, dann expandieren
|
||||||
if ( nCount == Container::GetSize() )
|
sal_uIntPtr nTmp = size();
|
||||||
SetSize( nCount + nReSize );
|
if( nTmp == nCount )
|
||||||
|
nTmp++;
|
||||||
|
|
||||||
// Damit UniqIndex nicht ueberlaeuft, wenn Items geloescht wurden
|
// Damit UniqIndex nicht ueberlaeuft, wenn Items geloescht wurden
|
||||||
nUniqIndex = nUniqIndex % Container::GetSize();
|
nUniqIndex = nUniqIndex % nTmp;
|
||||||
|
|
||||||
// Leeren Eintrag suchen
|
// Leeren Eintrag suchen
|
||||||
while ( Container::ImpGetObject( nUniqIndex ) != NULL )
|
while ( find( nUniqIndex ) != end() )
|
||||||
nUniqIndex = (nUniqIndex+1) % Container::GetSize();
|
nUniqIndex = (nUniqIndex+1) % nTmp;
|
||||||
|
|
||||||
// Object im Array speichern
|
// Object im Array speichern
|
||||||
Container::Replace( p, nUniqIndex );
|
(*this)[ nUniqIndex ] = p;
|
||||||
|
|
||||||
// Anzahl der Eintraege erhoehen und Index zurueckgeben
|
// Anzahl der Eintraege erhoehen und Index zurueckgeben
|
||||||
nCount++;
|
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
|
// NULL-Pointer ist nicht erlaubt
|
||||||
if ( !p )
|
if ( !p )
|
||||||
return UNIQUEINDEX_ENTRY_NOTFOUND;
|
return;
|
||||||
|
|
||||||
sal_uIntPtr nContIndex = nIndex - nStartIndex;
|
sal_uIntPtr nContIndex = nIndex - nStartIndex;
|
||||||
// Ist Array voll, dann expandieren
|
|
||||||
if ( nContIndex >= Container::GetSize() )
|
bool bFound = find( nContIndex ) != end();
|
||||||
SetSize( nContIndex + nReSize );
|
|
||||||
|
|
||||||
// Object im Array speichern
|
// Object im Array speichern
|
||||||
Container::Replace( p, nContIndex );
|
(*this)[ nContIndex ] = p;
|
||||||
|
|
||||||
// Anzahl der Eintraege erhoehen und Index zurueckgeben
|
if( !bFound )
|
||||||
nCount++;
|
nCount++;
|
||||||
return nIndex;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
|*
|
|*
|
||||||
|* UniqueIndex::Remove()
|
|* UniqueIndexImpl::Remove()
|
||||||
|*
|
|*
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
void* UniqueIndex::Remove( sal_uIntPtr nIndex )
|
void* UniqueIndexImpl::Remove( sal_uIntPtr nIndex )
|
||||||
{
|
{
|
||||||
// Ist Index zulaessig
|
// Ist Index zulaessig
|
||||||
if ( (nIndex >= nStartIndex) &&
|
if ( (nIndex >= nStartIndex) &&
|
||||||
(nIndex < (Container::GetSize()+nStartIndex)) )
|
(nIndex < (size() + nStartIndex)) )
|
||||||
{
|
{
|
||||||
// Index-Eintrag als leeren Eintrag setzen und Anzahl der
|
// Index-Eintrag als leeren Eintrag setzen und Anzahl der
|
||||||
// gespeicherten Indexe erniedriegen, wenn Eintrag belegt war
|
// gespeicherten Indexe erniedriegen, wenn Eintrag belegt war
|
||||||
void* p = Container::Replace( NULL, nIndex-nStartIndex );
|
iterator it = find( nIndex - nStartIndex );
|
||||||
if ( p )
|
if( it != end() )
|
||||||
|
{
|
||||||
|
void* p = it->second;
|
||||||
|
erase( it );
|
||||||
nCount--;
|
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
|
// Ist Index zulaessig
|
||||||
if ( (nIndex >= nStartIndex) &&
|
if ( (nIndex >= nStartIndex) &&
|
||||||
(nIndex < (Container::GetSize()+nStartIndex)) )
|
(nIndex < (size() + nStartIndex)) )
|
||||||
return Container::ImpGetObject( nIndex-nStartIndex );
|
{
|
||||||
else
|
const_iterator it = find( nIndex - nStartIndex );
|
||||||
|
if( it != end() )
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
|*
|
|*
|
||||||
|* UniqueIndex::GetCurIndex()
|
|* UniqueIndexImpl::FirstIndex()
|
||||||
|*
|
|*
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
sal_uIntPtr UniqueIndex::GetCurIndex() const
|
sal_uIntPtr UniqueIndexImpl::FirstIndex() const
|
||||||
{
|
{
|
||||||
sal_uIntPtr nPos = Container::GetCurPos();
|
if ( empty() )
|
||||||
|
|
||||||
// Ist der Current-Index nicht belegt, dann gibt es keinen Current-Index
|
|
||||||
if ( !Container::ImpGetObject( nPos ) )
|
|
||||||
return UNIQUEINDEX_ENTRY_NOTFOUND;
|
|
||||||
else
|
|
||||||
return nPos+nStartIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
|*
|
|
||||||
|* UniqueIndex::GetIndex()
|
|
||||||
|*
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
sal_uIntPtr UniqueIndex::GetIndex( const void* p ) const
|
|
||||||
{
|
|
||||||
// Wird ein NULL-Pointer uebergeben, dann wurde Pointer nicht gefunden
|
|
||||||
if ( !p )
|
|
||||||
return UNIQUEINDEX_ENTRY_NOTFOUND;
|
return UNIQUEINDEX_ENTRY_NOTFOUND;
|
||||||
|
|
||||||
sal_uIntPtr nIndex = Container::GetPos( p );
|
return begin()->first;
|
||||||
|
}
|
||||||
|
|
||||||
if ( nIndex != CONTAINER_ENTRY_NOTFOUND )
|
/*************************************************************************
|
||||||
return nIndex+nStartIndex;
|
|*
|
||||||
else
|
|* UniqueIndexImpl::LastIndex()
|
||||||
|
|*
|
||||||
|
*************************************************************************/
|
||||||
|
|
||||||
|
sal_uIntPtr UniqueIndexImpl::LastIndex() const
|
||||||
|
{
|
||||||
|
if ( empty() )
|
||||||
return UNIQUEINDEX_ENTRY_NOTFOUND;
|
return UNIQUEINDEX_ENTRY_NOTFOUND;
|
||||||
|
|
||||||
|
return rbegin()->first;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
|*
|
|*
|
||||||
|* UniqueIndex::Seek()
|
|* UniqueIndexImpl::NextIndex()
|
||||||
|*
|
|*
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
void* UniqueIndex::Seek( void* p )
|
sal_uIntPtr UniqueIndexImpl::NextIndex(sal_uIntPtr aIndex) const
|
||||||
{
|
{
|
||||||
// Wird ein NULL-Pointer uebergeben, dann wurde Pointer nicht gefunden
|
const_iterator it = find( aIndex );
|
||||||
if ( !p )
|
if ( it == end() )
|
||||||
return NULL;
|
return UNIQUEINDEX_ENTRY_NOTFOUND;
|
||||||
|
it++;
|
||||||
sal_uIntPtr nIndex = GetIndex( p );
|
if ( it == end() )
|
||||||
|
return UNIQUEINDEX_ENTRY_NOTFOUND;
|
||||||
// Ist Index vorhanden, dann als aktuellen Eintrag setzen
|
return it->first;
|
||||||
if ( nIndex != UNIQUEINDEX_ENTRY_NOTFOUND )
|
|
||||||
return Container::Seek( nIndex-nStartIndex );
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
|*
|
|*
|
||||||
|* UniqueIndex::First()
|
|* UniqueIndexImpl::GetIndexOf()
|
||||||
|*
|
|*
|
||||||
*************************************************************************/
|
*************************************************************************/
|
||||||
|
|
||||||
void* UniqueIndex::First()
|
sal_uIntPtr UniqueIndexImpl::GetIndexOf(void* p) const
|
||||||
{
|
{
|
||||||
void* p = Container::First();
|
for( const_iterator it = begin(); it != end(); ++it )
|
||||||
|
if( it->second == p )
|
||||||
while ( !p && (Container::GetCurPos() < (Container::GetSize()-1)) )
|
return it->first;
|
||||||
p = Container::Next();
|
return UNIQUEINDEX_ENTRY_NOTFOUND;
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
|*
|
|
||||||
|* UniqueIndex::Prev()
|
|
||||||
|*
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
void* UniqueIndex::Prev()
|
|
||||||
{
|
|
||||||
void* p = NULL;
|
|
||||||
|
|
||||||
while ( !p && Container::GetCurPos() )
|
|
||||||
p = Container::Prev();
|
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
|*
|
|
||||||
|* UniqueIndex::operator =()
|
|
||||||
|*
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
UniqueIndex& UniqueIndex::operator =( const UniqueIndex& rIdx )
|
|
||||||
{
|
|
||||||
// Neue Werte zuweisen
|
|
||||||
Container::operator =( rIdx );
|
|
||||||
nReSize = rIdx.nReSize;
|
|
||||||
nStartIndex = rIdx.nStartIndex;
|
|
||||||
nUniqIndex = rIdx.nUniqIndex;
|
|
||||||
nCount = rIdx.nCount;
|
|
||||||
return *this;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*************************************************************************
|
|
||||||
|*
|
|
||||||
|* UniqueIndex::operator ==()
|
|
||||||
|*
|
|
||||||
*************************************************************************/
|
|
||||||
|
|
||||||
sal_Bool UniqueIndex::operator ==( const UniqueIndex& rIdx ) const
|
|
||||||
{
|
|
||||||
// Neue Werte zuweisen
|
|
||||||
if ( (nStartIndex == rIdx.nStartIndex) &&
|
|
||||||
(nCount == rIdx.nCount) &&
|
|
||||||
(Container::operator ==( rIdx )) )
|
|
||||||
return sal_True;
|
|
||||||
else
|
|
||||||
return sal_False;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|
||||||
|
@@ -792,14 +792,14 @@ SvStream& operator <<
|
|||||||
rThis << bTmp; // Version
|
rThis << bTmp; // Version
|
||||||
sal_uInt32 nCount = (sal_uInt32)rThis.aPUIdx.Count();
|
sal_uInt32 nCount = (sal_uInt32)rThis.aPUIdx.Count();
|
||||||
rThis << nCount;
|
rThis << nCount;
|
||||||
SvPersistBase * pEle = rThis.aPUIdx.First();
|
sal_uIntPtr aIndex = rThis.aPUIdx.FirstIndex();
|
||||||
for( sal_uInt32 i = 0; i < nCount; i++ )
|
for( sal_uInt32 i = 0; i < nCount; i++ )
|
||||||
{
|
{
|
||||||
|
SvPersistBase * pEle = rThis.aPUIdx.Get(aIndex);
|
||||||
sal_uInt8 nP = P_OBJ | P_ID | P_STD;
|
sal_uInt8 nP = P_OBJ | P_ID | P_STD;
|
||||||
WriteId( rThis, nP, rThis.aPUIdx.GetCurIndex(),
|
WriteId( rThis, nP, aIndex, pEle->GetClassId() );
|
||||||
pEle->GetClassId() );
|
|
||||||
rThis.WriteObj( nP, pEle );
|
rThis.WriteObj( nP, pEle );
|
||||||
pEle = rThis.aPUIdx.Next();
|
aIndex = rThis.aPUIdx.NextIndex( aIndex );
|
||||||
}
|
}
|
||||||
rThis.SetStream( pOldStm );
|
rThis.SetStream( pOldStm );
|
||||||
return rStm;
|
return rStm;
|
||||||
|
Reference in New Issue
Block a user