home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
IBMCLASS
/
IAEQSEQ.C
< prev
next >
Wrap
Text File
|
1993-09-22
|
3KB
|
72 lines
/*******************************************************************************
* *
* COPYRIGHT: *
* IBM C/C++ Tools Version 2.01 - Collection Class Library *
* Licensed Materials - Property of IBM *
* (C) Copyright IBM Corporation 1992, 1993 *
* All Rights Reserved *
* US Government Users Restricted Rights - Use, duplication, or disclosure *
* restricted by GSA ADP Schedule Contract with IBM Corp. *
* *
*******************************************************************************/
template < class Element >
IBoolean IAEqualitySequence < Element >::
operator == (IAEqualitySequence < Element > const& collection) const
{ if (numberOfElements () != collection.numberOfElements ())
return False;
ICursor *cursor1 = newCursor ();
ICursor *cursor2 = collection.newCursor ();
IBoolean result = True;
cursor1->setToFirst ();
// must be done as follows, since there is no element equality function
// available at this level
if (cursor1->isValid ()) {
result = collection.locateFirst (elementAt (*cursor1), *cursor2);
while (result && cursor1->setToNext ()) {
result = collection.locateNext (elementAt (*cursor1), *cursor2);
}
}
delete cursor2;
delete cursor1;
return result;
}
template < class Element >
IBoolean IAEqualitySequence < Element >::
operator != (IAEqualitySequence < Element > const& collection) const
{ return ! operator == (collection);
}
template < class Element >
long IAEqualitySequence < Element >::
compare (IAEqualitySequence < Element > const& collection,
long (*comparisonFunction) (Element const&, Element const&)) const
{ long result = 0;
ICursor *thisCursor = newCursor ();
ICursor *collectionCursor = collection.newCursor ();
for (thisCursor->setToFirst (), collectionCursor->setToFirst ();
result == 0 && thisCursor->isValid () && collectionCursor->isValid ();
thisCursor->setToNext (), collectionCursor->setToNext ()) {
result = (*comparisonFunction) (this->elementAt (*thisCursor),
collection.elementAt (*collectionCursor));
}
if (result == 0) {
if (thisCursor->isValid () && ! collectionCursor->isValid ())
result = 1;
else if (! thisCursor->isValid () && collectionCursor->isValid ())
result = -1;
else {
}
}
delete thisCursor;
delete collectionCursor;
return result;
}