Introduction
This article presents the code of Simon Hughes' SmartList with some new functions that I have added. This code is (as it was) completely free and can be used however you want, but please leave our (Simon's and mine) e-mail addresses in the code to receive possible bug-reports.
This article presents a number of list classes that encapsulate the MFC list classes with some new features. This code (with the new functions) is in some of my projects and has been fully tested. But, if anyone out there finds out any bugs or improvements please send them to me, I will correct them as soon as possible.
The New Functions
BOOL FindAndRemoveElement (const ARG_TYPE searchValue);
BOOL FindAndReplaceElement (const ARG_TYPE searchValue, const ARG_TYPE
newValue);
BOOL operator== (const CMyList &temp)
template <class TYPE, class ARG_TYPE>
BOOL CMyList<TYPE, ARG_TYPE>::FindAndRemoveElement(const ARG_TYPE
searchValue)
{
ASSERT_VALID (this);
POSITION pos = Find (searchValue);
if (pos != NULL) {
RemoveAt(pos);
return TRUE;
}
else
return FALSE;
}
template <class TYPE, class ARG_TYPE>
BOOL CMyList<TYPE, ARG_TYPE>::FindAndReplaceElement(const ARG_TYPE
searchValue, const ARG_TYPE newValue)
{
ASSERT_VALID (this);
POSITION pos = Find (searchValue);
if (pos != NULL) {
SetAt (pos, newValue);
return TRUE;
}
else
return FALSE;
}
template <class TYPE, class ARG_TYPE>
BOOL CMyList<TYPE, ARG_TYPE>::operator== (const CMyList &temp)
{
ASSERT_VALID (this);
ASSERT_VALID (&temp);
int nMatches = 0;
if(this == &temp) return TRUE;
if (GetCount () != temp.GetCount ())
return FALSE;
POSITION posThis = GetHeadPosition ();
POSITION posOther = temp.GetHeadPosition ();
while ((posThis)&&(posOther))
{ TYPE thisTYPE = (TYPE)GetNext(posThis);
TYPE otherTYPE = (TYPE)temp.GetNext(posOther);
if (thisTYPE == otherTYPE)
nMatches++;
else
break;
}
if (nMatches == GetCount ())
return TRUE;
return
FALSE;
}
I come from Spain. After making a lot of silly things during the studies, I wanted to correct me and to make something positive with my life, so I asked for (and got) an “Erasmus” scholarship to go to Germany. After obtaining a placement to make my Thesis in a Firm of Automation and Software development, I reached the double Degree in Electronics’ Engineering and Informatic. I worked a time with VC++ 6, many years with industry PLC and robot programming, done backbone IT for something related to car electronics and production, back to my roots in C++ and PLC Programming again and currently working as system architect for my division.
I contrinue trying to learn more C# in my spare time (which is even less than before, God bless my kids)