added AddStringFiFoWithCompare function

This commit is contained in:
Volker Fischer 2013-02-23 20:13:43 +00:00
parent 7dcd612879
commit 096d3a39d2
2 changed files with 38 additions and 25 deletions

View file

@ -851,30 +851,10 @@ void CLlconClientDlg::ConnectDisconnect ( const bool bDoStart,
if ( !strSelectedAddress.isEmpty() && if ( !strSelectedAddress.isEmpty() &&
!ConnectDlg.GetServerListItemWasChosen() ) !ConnectDlg.GetServerListItemWasChosen() )
{ {
CVector<QString> vstrTempList ( MAX_NUM_SERVER_ADDR_ITEMS, "" ); // store new address at the top of the list, if the list was already
// full, the last element is thrown out
// store the new address in the current server storage list at pClient->vstrIPAddress.AddStringFiFoWithCompare ( strSelectedAddress,
// the top, make sure we do not have more than allowed stored MAX_NUM_SERVER_ADDR_ITEMS );
// 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;
} }
// everything was ok with the connection dialog, set flag // everything was ok with the connection dialog, set flag

View file

@ -92,7 +92,7 @@ template<class TData> class CVector : public std::vector<TData>
{ {
public: public:
CVector() : iVectorSize ( 0 ) { pData = this->begin(); } 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 ); } CVector ( const int iNeSi, const TData tInVa ) { Init ( iNeSi, tInVa ); }
// Copy constructor: The order of the initialization list must not be // Copy constructor: The order of the initialization list must not be
@ -112,6 +112,9 @@ 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,
const int iMaxElements );
inline int Size() const { return iVectorSize; } inline int Size() const { return iVectorSize; }
// This operator allows for a l-value assignment of this object: // 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) * * CFIFO Class (First In, First Out) *