From 096d3a39d2ca676b7734949b7dd75b07b932e323 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Sat, 23 Feb 2013 20:13:43 +0000 Subject: [PATCH] added AddStringFiFoWithCompare function --- src/llconclientdlg.cpp | 28 ++++------------------------ src/util.h | 35 ++++++++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/llconclientdlg.cpp b/src/llconclientdlg.cpp index 105375d2..757d3b7d 100755 --- a/src/llconclientdlg.cpp +++ b/src/llconclientdlg.cpp @@ -851,30 +851,10 @@ void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart, if ( !strSelectedAddress.isEmpty() && !ConnectDlg.GetServerListItemWasChosen() ) { - CVector vstrTempList ( MAX_NUM_SERVER_ADDR_ITEMS, "" ); - - // store the new address in the current server storage list at - // the top, make sure we do not have more than allowed stored - // servers - vstrTempList[0] = strSelectedAddress; - int iTempListCnt = 1; - - for ( int iIdx = 0; iIdx < MAX_NUM_SERVER_ADDR_ITEMS; iIdx++ ) - { - // only add old server address if it is not the same as the - // selected one - if ( ( pClient->vstrIPAddress[iIdx].compare ( strSelectedAddress ) ) && - ( iTempListCnt < MAX_NUM_SERVER_ADDR_ITEMS ) ) - { - vstrTempList[iTempListCnt] = - pClient->vstrIPAddress[iIdx]; - - iTempListCnt++; - } - } - - // copy new generated list to client - pClient->vstrIPAddress = vstrTempList; + // store new address at the top of the list, if the list was already + // full, the last element is thrown out + pClient->vstrIPAddress.AddStringFiFoWithCompare ( strSelectedAddress, + MAX_NUM_SERVER_ADDR_ITEMS ); } // everything was ok with the connection dialog, set flag diff --git a/src/util.h b/src/util.h index b2012dcd..f3d72bdf 100755 --- a/src/util.h +++ b/src/util.h @@ -92,7 +92,7 @@ template class CVector : public std::vector { public: CVector() : iVectorSize ( 0 ) { pData = this->begin(); } - CVector ( const int iNeSi ) { Init(iNeSi); } + CVector ( const int iNeSi ) { Init ( iNeSi ); } CVector ( const int iNeSi, const TData tInVa ) { Init ( iNeSi, tInVa ); } // Copy constructor: The order of the initialization list must not be @@ -112,6 +112,9 @@ public: void Enlarge ( const int iAddedSize ); void Add ( const TData& tI ) { Enlarge ( 1 ); pData[iVectorSize - 1] = tI; } + void AddStringFiFoWithCompare ( const QString strNewValue, + const int iMaxElements ); + inline int Size() const { return iVectorSize; } // This operator allows for a l-value assignment of this object: @@ -203,6 +206,36 @@ template void CVector::Reset ( const TData tResetVal ) } } +// note: this is only supported for string vectors +template void CVector::AddStringFiFoWithCompare ( const QString strNewValue, + const int iMaxElements ) +{ + CVector vstrTempList ( iMaxElements, "" ); + + // store the new element in the current storage list at + // the top, make sure we do not have more than allowed stored + // elements + vstrTempList[0] = strNewValue; + int iTempListCnt = 1; + + for ( int iIdx = 0; iIdx < iMaxElements; iIdx++ ) + { + // only add old element if it is not the same as the + // selected one + if ( ( pData[iIdx].compare ( strNewValue ) ) && + ( iTempListCnt < iMaxElements ) ) + { + vstrTempList[iTempListCnt] = pData[iIdx]; + + iTempListCnt++; + } + } + + // copy new generated list to data base + *this = vstrTempList; +} + + /******************************************************************************\ * CFIFO Class (First In, First Out) *