home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cset21v1.zip
/
IBMCPP
/
SAMPLES
/
ICLCC
/
PARCEL.H
< prev
next >
Wrap
C/C++ Source or Header
|
1993-05-07
|
4KB
|
120 lines
/******************************************************************************/
/* */
/* COPYRIGHT: */
/* ---------- */
/* Copyright (C) International Business Machines Corp., 1991,1992. */
/* */
/* DISCLAIMER OF WARRANTIES: */
/* ------------------------- */
/* The following [enclosed] code is sample code created by IBM */
/* Corporation. This sample code is not part of any standard IBM product */
/* and is provided to you solely for the purpose of assisting you in the */
/* development of your applications. The code is provided "AS IS", */
/* without warranty of any kind. IBM shall not be liable for any damages */
/* arising out of your use of the sample code, even if they have been */
/* advised of the possibility of such damages. */
/* */
/******************************************************************************/
/*-------------------------------------------------------------*\
| parcel.h - Class Parcel and its parts for use with the |
| example for Key Sorted Set and Heap. |
\*-------------------------------------------------------------*/
// For definition of Boolean:
#include <iglobals.h>
// Class ToyString:
#include <toystrng.h>
class PlaceTime {
ToyString cty;
int daynum; // Keeping it simple: January 9 is day 9
public:
PlaceTime(ToyString acity, int aday) : cty(acity), daynum(aday) {}
PlaceTime(ToyString acity) : cty(acity) {daynum = 0;}
ToyString const& city() const {
return cty;
}
int const& day() const {
return daynum;
}
void operator=(PlaceTime const& pt) {
cty = pt.cty;
daynum = pt.daynum;
}
Boolean operator==(PlaceTime const& pt) const {
return ( (cty == pt.cty)
&& (daynum == pt.daynum) );
}
};
class Parcel {
PlaceTime org, lstAr;
ToyString dst, id;
public:
Parcel(ToyString orig, ToyString dest, int day, ToyString ident)
: org(orig, day), lstAr(orig, day), dst(dest), id(ident) {}
void arrivedAt(ToyString 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;
}
ToyString const& destination() const {
return dst;
}
PlaceTime const& lastArrival() const {
return lstAr;
}
ToyString 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 << "\n is at " << p.lstAr.city()
<< " since day " << p.lstAr.day() << ".";
}
else {
os << "\n was delivered on day "
<< p.lstAr.day() << ".";
}
return os;
}
};
// Key access:
inline ToyString const& key( Parcel const& p) {
return p.ID();
}
// We need a compare function for the key.
// Let's use the default provided for char*:
inline long compare(ToyString const& TS1, ToyString const& TS2) {
return compare(TS1.text(), TS2.text());
}