// Programmer: Aaron Shbeeb // File: Pair.h // Created: 10-25-02 // Updated: 08-13-02 #ifndef PAIR_H #define PAIR_H #include #include "../Keywords.h" namespace ShbeebLib { template class Pair_Rep { public: X x; Y y; }; template class Pair { public: //Basic Operations X& x(); //Cheap form of accessor Y& y(); bool operator==(preserves Pair& p); //Constructor/Destructor Pair(); ~Pair(); //Standard Operations void Clear(); void operator &=(alters Pair& p); private: Pair_Rep *rep; protected: void Initialize(); void Finalize(); }; //Basic Operations template X& Pair:: x() { return rep->x; } template Y& Pair:: y() { return rep->y; } template bool Pair:: operator==(preserves Pair& p) { if(rep->x == p.rep->x && rep->y == p.rep->y) return true; return false; } //Constructor/Destructor template Pair:: Pair() { Initialize(); } Pair:: Pair() { Initialize(); rep->x = 0; rep->y = 0; } template Pair:: ~Pair() { Finalize(); } //Standard Operations template void Pair:: Clear() { Finalize(); Initialize(); } template void Pair:: operator &=(alters Pair& p) { Pair_Rep *tmp; tmp = rep; rep = p.rep; p.rep = tmp; } //Protected Operations template void Pair:: Initialize() { rep = new Pair_Rep; assert(rep != 0); } template void Pair:: Finalize() { delete rep; } }//end namespace ShbeebLib #endif