home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
VSCPPv8.zip
/
VACPP
/
IBMCPP
/
samples
/
IOC
/
PARCEL
/
PARCEL.H
< prev
next >
Wrap
Text File
|
1995-03-15
|
3KB
|
116 lines
/*************************************************************************
IBM C/C++ Tools Version 3.00 - Collection Class Library
(C) Copyright IBM Corporation 1992 ,1995, Licensed Program-Property of
IBM. All Rights Reserved. US Government Users Restricted Rights - Use,
duplication or disclosure restricted by GSA ADP Schedule Contract with
IBM Corp.
*************************************************************************/
/*-------------------------------------------------------------*\
| parcel.h - Class Parcel and its parts for use with the |
| example for Key Sorted Set and Heap. |
\*-------------------------------------------------------------*/
#include <iostream.h>
// For definition of Boolean:
#include <iglobals.h>
// Class IString:
#if defined (_SUN)
#include <istring.h>
#else
#include <istring.hpp>
#endif
class PlaceTime {
IString cty;
int daynum; // Keeping it simple: January 9 is day 9
public:
PlaceTime(IString acity, int aday) : cty(acity), daynum(aday) {}
PlaceTime(IString acity) : cty(acity) {daynum = 0;}
IString const& city() const {
return cty;
}
int const& day() const {
return daynum;
}
void operator=(PlaceTime const& pt) {
cty = pt.cty;
daynum = pt.daynum;
}
IBoolean operator==(PlaceTime const& pt) const {
return ( (cty == pt.cty)
&& (daynum == pt.daynum) );
}
};
class Parcel {
PlaceTime org, lstAr;
IString dst, id;
public:
Parcel(IString orig, IString dest, int day, IString ident)
: org(orig, day), lstAr(orig, day), dst(dest), id(ident) {}
void arrivedAt(IString const& acity, int const& day) {
PlaceTime nowAt(acity, day);
// Only if not already there before
if (nowAt.city() != lstAr.city())
lstAr = nowAt;
}
void wasDelivered(int const& day) {arrivedAt(dst, day); }
PlaceTime const& origin() const {
return org;
}
IString const& destination() const {
return dst;
}
PlaceTime const& lastArrival() const {
return lstAr;
}
IString const& ID() const {
return id;
}
friend ostream& operator<<(ostream& os, Parcel const& p) {
os << p.id << ": From " << p.org.city()
<< "(day " << p.org.day() << ") to " << p.dst;
if (p.lstAr.city() != p.dst) {
os << endl << " is at " << p.lstAr.city()
<< " since day " << p.lstAr.day() << ".";
}
else {
os << endl << " was delivered on day "
<< p.lstAr.day() << ".";
}
return os;
}
};
// Key access:
inline IString const& key( Parcel const& p) {
return p.ID();
}
// We need a compare function for the key.
// Let's use the default provided for IString:
inline long compare(Parcel const& p1, Parcel const& p2) {
return compare(p1.ID(), p2.ID());
}