return the old value (removed entry) of the list
This commit is contained in:
parent
f79d8e410c
commit
9a9ca7c1c4
1 changed files with 18 additions and 8 deletions
18
src/util.h
18
src/util.h
|
@ -112,7 +112,7 @@ public:
|
||||||
void Enlarge ( const int iAddedSize );
|
void Enlarge ( const int iAddedSize );
|
||||||
void Add ( const TData& tI ) { Enlarge ( 1 ); pData[iVectorSize - 1] = tI; }
|
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; }
|
inline int Size() const { return iVectorSize; }
|
||||||
|
|
||||||
|
@ -206,8 +206,9 @@ template<class TData> void CVector<TData>::Reset ( const TData tResetVal )
|
||||||
}
|
}
|
||||||
|
|
||||||
// note: this is only supported for string vectors
|
// note: this is only supported for string vectors
|
||||||
template<class TData> void CVector<TData>::AddStringFiFoWithCompare ( const QString strNewValue )
|
template<class TData> int CVector<TData>::AddStringFiFoWithCompare ( const QString strNewValue )
|
||||||
{
|
{
|
||||||
|
int iOldIndex = -1; // init with illegal index per definition
|
||||||
CVector<QString> vstrTempList ( iVectorSize, "" );
|
CVector<QString> vstrTempList ( iVectorSize, "" );
|
||||||
|
|
||||||
// store the new element in the current storage list at
|
// store the new element in the current storage list at
|
||||||
|
@ -217,20 +218,29 @@ template<class TData> void CVector<TData>::AddStringFiFoWithCompare ( const QStr
|
||||||
int iTempListCnt = 1;
|
int iTempListCnt = 1;
|
||||||
|
|
||||||
for ( int iIdx = 0; iIdx < iVectorSize; iIdx++ )
|
for ( int iIdx = 0; iIdx < iVectorSize; iIdx++ )
|
||||||
|
{
|
||||||
|
// first check if we still have space in our data storage
|
||||||
|
if ( iTempListCnt < iVectorSize )
|
||||||
{
|
{
|
||||||
// only add old element if it is not the same as the
|
// only add old element if it is not the same as the
|
||||||
// selected one
|
// selected one
|
||||||
if ( ( pData[iIdx].compare ( strNewValue ) ) &&
|
if ( pData[iIdx].compare ( strNewValue ) )
|
||||||
( iTempListCnt < iVectorSize ) )
|
|
||||||
{
|
{
|
||||||
vstrTempList[iTempListCnt] = pData[iIdx];
|
vstrTempList[iTempListCnt] = pData[iIdx];
|
||||||
|
|
||||||
iTempListCnt++;
|
iTempListCnt++;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
iOldIndex = iIdx;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy new generated list to data base
|
// copy new generated list to data base
|
||||||
*this = vstrTempList;
|
*this = vstrTempList;
|
||||||
|
|
||||||
|
return iOldIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue