diff options
-rw-r--r-- | rsc/inc/rscdef.hxx | 22 | ||||
-rw-r--r-- | rsc/source/tools/rscdef.cxx | 114 |
2 files changed, 76 insertions, 60 deletions
diff --git a/rsc/inc/rscdef.hxx b/rsc/inc/rscdef.hxx index 993a54e2c4e9..7a8cf52b4017 100644 --- a/rsc/inc/rscdef.hxx +++ b/rsc/inc/rscdef.hxx @@ -30,6 +30,7 @@ #include <tools/unqidx.hxx> #include <rsctree.hxx> +#include <vector> /****************** C L A S S E S ****************************************/ class RscExpression; @@ -152,21 +153,28 @@ public: ByteString GetMacro(); }; -DECLARE_LIST( RscSubDefList, RscDefine * ) +typedef ::std::vector< RscDefine* > RscSubDefList; -class RscDefineList : public RscSubDefList { +class RscDefineList { friend class RscFile; friend class RscFileTab; private: + RscSubDefList maList; // pExpression wird auf jedenfall Eigentum der Liste RscDefine * New( ULONG lFileKey, const ByteString & rDefName, - INT32 lDefId, ULONG lPos ); + INT32 lDefId, size_t lPos ); RscDefine * New( ULONG lFileKey, const ByteString & rDefName, - RscExpression * pExpression, ULONG lPos ); + RscExpression * pExpression, size_t lPos ); BOOL Befor( const RscDefine * pFree, const RscDefine * pDepend ); BOOL Remove( RscDefine * pDef ); - BOOL Remove( ULONG nIndex ); + BOOL Remove( size_t nIndex ); BOOL Remove(); + size_t GetPos( RscDefine* item ) { + for ( size_t i = 0, n = maList.size(); i < n; ++i ) + if ( maList[ i ] == item ) + return i; + return size_t(-1); + } public: void WriteAll( FILE * fOutput ); }; @@ -244,9 +252,9 @@ public: RscDefine * FindDef( ULONG lKey, const ByteString & ); BOOL Depend( ULONG lDepend, ULONG lFree ); - BOOL TestDef( ULONG lFileKey, ULONG lPos, + BOOL TestDef( ULONG lFileKey, size_t lPos, const RscDefine * pDefDec ); - BOOL TestDef( ULONG lFileKey, ULONG lPos, + BOOL TestDef( ULONG lFileKey, size_t lPos, const RscExpression * pExpDec ); RscDefine * NewDef( ULONG lKey, const ByteString & rDefName, diff --git a/rsc/source/tools/rscdef.cxx b/rsc/source/tools/rscdef.cxx index 0b5fe9cc9576..870e5bdd6e65 100644 --- a/rsc/source/tools/rscdef.cxx +++ b/rsc/source/tools/rscdef.cxx @@ -324,25 +324,38 @@ ByteString RscDefine::GetMacro() |* *************************************************************************/ RscDefine * RscDefineList::New( ULONG lFileKey, const ByteString & rDefName, - INT32 lDefId, ULONG lPos ) + INT32 lDefId, size_t lPos ) { RscDefine * pDef; pDef = new RscDefine( lFileKey, rDefName, lDefId ); pDef->IncRef(); - Insert( pDef, lPos ); + if ( lPos < maList.size() ) + { + RscSubDefList::iterator it = maList.begin(); + ::std::advance( it, lPos ); + maList.insert( it, pDef ); + } else { + maList.push_back( pDef ); + } return pDef; } RscDefine * RscDefineList::New( ULONG lFileKey, const ByteString & rDefName, - RscExpression * pExpression, ULONG lPos ) + RscExpression * pExpression, size_t lPos ) { RscDefine * pDef; pDef = new RscDefine( lFileKey, rDefName, pExpression ); pDef->IncRef(); - Insert( pDef, lPos ); - + if ( lPos < maList.size() ) + { + RscSubDefList::iterator it = maList.begin(); + ::std::advance( it, lPos ); + maList.insert( it, pDef ); + } else { + maList.push_back( pDef ); + } return pDef; } @@ -351,36 +364,37 @@ RscDefine * RscDefineList::New( ULONG lFileKey, const ByteString & rDefName, |* RscDefineList::Remove() |* *************************************************************************/ -BOOL RscDefineList::Remove( RscDefine * pDef ){ - pDef = RscSubDefList::Remove( pDef ); - if( pDef ){ - pDef->DefineToNumber(); - pDef->DecRef(); +BOOL RscDefineList::Remove( RscDefine * pDef ) { + for ( RscSubDefList::iterator it = maList.begin(); it < maList.end(); ++it ) { + if ( *it == pDef ) { + (*it)->DefineToNumber(); + (*it)->DecRef(); + maList.erase( it ); + return TRUE; + } } - - return( NULL != pDef ); + return FALSE; } -BOOL RscDefineList::Remove( ULONG lIndex ){ - RscDefine * pDef = RscSubDefList::Remove( lIndex ); - if( pDef ){ - pDef->DefineToNumber(); - pDef->DecRef(); +BOOL RscDefineList::Remove( size_t lIndex ) { + if ( lIndex < maList.size() ) { + RscSubDefList::iterator it = maList.begin(); + ::std::advance( it, lIndex ); + (*it)->DefineToNumber(); + (*it)->DecRef(); + maList.erase( it ); + return TRUE; } - - return( NULL != pDef ); + return FALSE; } -BOOL RscDefineList::Remove(){ - RscDefine * pDef; - - pDef = RscSubDefList::Remove( (ULONG)0 ); +BOOL RscDefineList::Remove() { + if ( maList.empty() ) return FALSE; - if( pDef ){ - pDef->DefineToNumber(); - pDef->DecRef(); - } - return( NULL != pDef ); + maList[ 0 ]->DefineToNumber(); + maList[ 0 ]->DecRef(); + maList.erase( maList.begin() ); + return TRUE; } /************************************************************************* @@ -391,20 +405,18 @@ BOOL RscDefineList::Remove(){ BOOL RscDefineList::Befor( const RscDefine * pFree, const RscDefine * pDepend ) { - RscDefine * pDef; - - pDef = First(); - while( pDef ){ - if( pDef == pFree ){ - pDef = Next(); - while( pDef ){ - if( pDef == pDepend ) + size_t i = 0; + size_t n = maList.size(); + while ( i < n ) { + if ( maList[ i ] == pFree ) { + for ( ++i ; i < n ; ++i ) { + if ( maList[ i ] == pDepend ) { return TRUE; - pDef = Next(); + } } } - pDef = Next(); - }; + ++i; + } return FALSE; } @@ -415,14 +427,12 @@ BOOL RscDefineList::Befor( const RscDefine * pFree, *************************************************************************/ void RscDefineList::WriteAll( FILE * fOutput ) { - RscDefine * pDefEle = First(); - - while( pDefEle ) - { + for ( size_t i = 0, n = maList.size(); i < n; ++i ) { + RscDefine* pDefEle = maList[ i ]; fprintf( fOutput, "#define %s %s\n", pDefEle->GetName().GetBuffer(), - pDefEle->GetMacro().GetBuffer() ); - pDefEle = Next(); + pDefEle->GetMacro().GetBuffer() + ); }; } @@ -606,7 +616,6 @@ RscFile :: ~RscFile(){ //von hinten nach vorne ist besser wegen der Abhaengigkeiten //Objekte zerstoeren sich, wenn Referenzzaehler NULL - aDefLst.Last(); while( aDefLst.Remove() ) ; } @@ -862,10 +871,10 @@ BOOL RscFileTab::Depend( ULONG lDepend, ULONG lFree ){ |* RscFileTab::TestDef() |* *************************************************************************/ -BOOL RscFileTab::TestDef( ULONG lFileKey, ULONG lPos, +BOOL RscFileTab::TestDef( ULONG lFileKey, size_t lPos, const RscDefine * pDefDec ) { - if( lFileKey == pDefDec->GetFileKey() ){ + if( lFileKey == pDefDec->GetFileKey() ) { RscFile * pFile = GetFile( pDefDec->GetFileKey() ); if( pFile && (lPos <= pFile->aDefLst.GetPos( (RscDefine *)pDefDec )) && (lPos != LIST_APPEND) ) @@ -882,7 +891,7 @@ BOOL RscFileTab::TestDef( ULONG lFileKey, ULONG lPos, |* RscFileTab::TestDef() |* *************************************************************************/ -BOOL RscFileTab::TestDef( ULONG lFileKey, ULONG lPos, +BOOL RscFileTab::TestDef( ULONG lFileKey, size_t lPos, const RscExpression * pExpDec ) { if( !pExpDec ) @@ -1081,12 +1090,11 @@ void RscFileTab :: DeleteFileContext( ULONG lFileKey ){ if( pFName ){ RscDefine * pDef; - pDef = pFName->aDefLst.First(); - while( pDef ){ + for ( size_t i = 0, n = pFName->aDefLst.maList.size(); i < n; ++i ) { + pDef = pFName->aDefLst.maList[ i ]; aDefTree.Remove( pDef ); - pDef = pFName->aDefLst.Next(); }; - while( pFName->aDefLst.Remove( (ULONG)0 ) ) ; + while( pFName->aDefLst.Remove() ) ; } } |