BAPS/src/util.cpp

00001 #include "util.h"
00002 
00003 //
00004 // Implements the general purpose functions
00005 //
00006 string tab(int aW)
00007 {
00008         return "";
00009         //return smanip<int>(&setTab, aW);
00010 }
00011 
00012 int Max(int a, int b)
00013 {
00014    if (a > b)
00015       return a;
00016    else
00017       return b;
00018 }
00019 
00020 //
00021 // Implements the class IntPair
00022 //
00023 IntPair::IntPair() : mX(0), mY(0)
00024 {
00025    // empty body
00026 }
00027 
00028 IntPair::IntPair(int a, int b) : mX(a), mY(b)
00029 {
00030    // empty body
00031 }
00032 
00033 IntPair::IntPair(const IntPair& aP) : mX(aP.mX), mY(aP.mY)
00034 {
00035    // empty body
00036 }
00037 
00038 istream& operator>>(istream& aIS, IntPair& aP)
00039 {
00040    aIS >> aP.mX >> aP.mY;
00041    return aIS;
00042 }
00043 
00044 ostream& operator<<(ostream& aOS, const IntPair& aP)
00045 {
00046    aOS << "(" << aP.mX << "," << aP.mY << ")";
00047    return aOS;
00048 }
00049 
00050 int compare(const IntPair& aP1, const IntPair& aP2)
00051 {
00052    if (aP1.mX < aP2.mX) return -1;
00053    if (aP1.mX > aP2.mX) return  1;
00054    if (aP1.mY < aP2.mY) return -1;
00055    if (aP1.mY < aP2.mY) return  1;
00056    return 0;
00057 }
00058 
00059 int   IntPair::First() const { return mX; }
00060 int   IntPair::Start() const { return mX; }
00061 int   IntPair::Second() const { return mY; }
00062 int   IntPair::End() const { return mY; }
00063 
00064 int   IntPair::First(int i)
00065 {
00066    int   temp = mX;
00067    mX = i;
00068    return temp;
00069 }
00070 
00071 int   IntPair::Second(int i)
00072 {
00073    int   temp = mY;
00074    mY = i;
00075    return temp;
00076 }
00077 
00078 int   IntPair::Start(int i) { return First(i); }
00079 int   IntPair::End(int i) { return Second(i); }
00080 
00081 
00082 //
00083 // Implements the Triple structure
00084 //
00085 istream& operator>>(istream& aIS, Triple& aT)
00086 {
00087    aIS >> aT.Time >> aT.ID >> aT.Arrive;
00088    return aIS;
00089 }
00090 
00091 ostream& operator<<(ostream& aOS, const Triple& aT)
00092 {  
00093    aOS << "(" << setw(3) << aT.Time << "," << setw(3) << aT.ID << ")"
00094        << (aT.Arrive ? "Arrival" : "Departure");
00095    return aOS;
00096 }
00097    
00098 int compare(const Triple& aT1, const Triple& aT2)
00099 {
00100    if (aT1.Time > aT2.Time) return 1;
00101    if (aT1.Time < aT2.Time) return -1;
00102    if ((aT1.Arrive) && (!aT2.Arrive)) return 1;    // favour departures
00103    if ((!aT1.Arrive) && (aT2.Arrive)) return -1;   //   to arrivals
00104    if (aT1.ID > aT2.ID) return 1;
00105    if (aT1.ID < aT2.ID) return -1;
00106    
00107    return 0;
00108 }
00109 
00110 int compare(const int& a, const int& b) {
00111         return a - b;
00112 }

Generated on Tue Sep 9 15:40:10 2008 for BAP by  doxygen 1.5.3