From 9a9ca7c1c4e4c40417f67ccf23ea310726e44a94 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Wed, 27 Feb 2013 21:20:14 +0000 Subject: [PATCH] return the old value (removed entry) of the list --- src/util.h | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/src/util.h b/src/util.h index 807894b5..c3db7ea1 100755 --- a/src/util.h +++ b/src/util.h @@ -112,7 +112,7 @@ public: void Enlarge ( const int iAddedSize ); void Add ( const TData& tI ) { Enlarge ( 1 ); pData[iVectorSize - 1] = tI; } - void AddStringFiFoWithCompare ( const QString strNewValue ); + int AddStringFiFoWithCompare ( const QString strNewValue ); inline int Size() const { return iVectorSize; } @@ -206,8 +206,9 @@ template void CVector::Reset ( const TData tResetVal ) } // note: this is only supported for string vectors -template void CVector::AddStringFiFoWithCompare ( const QString strNewValue ) +template int CVector::AddStringFiFoWithCompare ( const QString strNewValue ) { + int iOldIndex = -1; // init with illegal index per definition CVector vstrTempList ( iVectorSize, "" ); // store the new element in the current storage list at @@ -218,19 +219,28 @@ template void CVector::AddStringFiFoWithCompare ( const QStr for ( int iIdx = 0; iIdx < iVectorSize; iIdx++ ) { - // only add old element if it is not the same as the - // selected one - if ( ( pData[iIdx].compare ( strNewValue ) ) && - ( iTempListCnt < iVectorSize ) ) + // first check if we still have space in our data storage + if ( iTempListCnt < iVectorSize ) { - vstrTempList[iTempListCnt] = pData[iIdx]; + // only add old element if it is not the same as the + // selected one + if ( pData[iIdx].compare ( strNewValue ) ) + { + vstrTempList[iTempListCnt] = pData[iIdx]; - iTempListCnt++; + iTempListCnt++; + } + else + { + iOldIndex = iIdx; + } } } // copy new generated list to data base *this = vstrTempList; + + return iOldIndex; }