home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional Developers Kit 1992 November / Disc01 / Disc01.mdf / cppbeta / bbxxsamk / parcel.h__ / PARCEL.H
Encoding:
C/C++ Source or Header  |  1992-10-26  |  1.2 KB  |  62 lines

  1. /* Copyright (c) IBM Corp. 1992 */
  2. #include <string.h>
  3.  
  4. class PlaceTime {
  5.     char* place;
  6.     float time;
  7. public:
  8.     void setPlaceTime(char* p, float t) {
  9.         place=p;
  10.         time=t;
  11.     }
  12.     void setPlace(char* p) {
  13.         place= p;
  14.     }
  15.     char* const& getPlace() const {
  16.         return place;
  17.     }
  18.     float const& getTime() const {
  19.         return (time);
  20.     }
  21. };
  22.  
  23. class Parcel {
  24.     PlaceTime origin, destination, nowAt;
  25.     char* identification;
  26. public:
  27.     Parcel(char* o, char* d, float t, char* i) {
  28.         origin.setPlaceTime(o, t);
  29.         destination.setPlace(d);
  30.         nowAt.setPlaceTime(o, t);
  31.         identification=i;
  32.     }
  33.     void arrivedAt(char* n, float t) {
  34.         if (nowAt.getPlace()!=destination.getPlace()) {
  35.             nowAt.setPlaceTime(n, t);
  36.         }
  37.     }
  38.     PlaceTime const& orig() const {
  39.         return origin;
  40.     }
  41.     PlaceTime const& dest() const {
  42.         return destination;
  43.     }
  44.     PlaceTime const& now() const {
  45.         return nowAt;
  46.     }
  47.     char* const& getID() const {
  48.         return identification;
  49.     }
  50.     int operator==(Parcel const& p) const {
  51.         return!(strcmp(identification, p.identification));
  52.     }
  53.     int operator<(Parcel const& p) const {
  54.         return(strcmp(identification, p.identification)<0);
  55.     }
  56. };
  57.  
  58. char* const& key( Parcel const& p) {
  59.     return p.getID();
  60. }
  61.  
  62.