added AddStringFiFoWithCompare function
This commit is contained in:
parent
7dcd612879
commit
096d3a39d2
2 changed files with 38 additions and 25 deletions
|
@ -851,30 +851,10 @@ void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart,
|
|||
if ( !strSelectedAddress.isEmpty() &&
|
||||
!ConnectDlg.GetServerListItemWasChosen() )
|
||||
{
|
||||
CVector<QString> 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
|
||||
|
|
35
src/util.h
35
src/util.h
|
@ -92,7 +92,7 @@ template<class TData> class CVector : public std::vector<TData>
|
|||
{
|
||||
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<class TData> void CVector<TData>::Reset ( const TData tResetVal )
|
|||
}
|
||||
}
|
||||
|
||||
// note: this is only supported for string vectors
|
||||
template<class TData> void CVector<TData>::AddStringFiFoWithCompare ( const QString strNewValue,
|
||||
const int iMaxElements )
|
||||
{
|
||||
CVector<QString> 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) *
|
||||
|
|
Loading…
Reference in a new issue