// Programmer: Aaron Shbeeb // File: Student.h // Created: 10-20-02 // Updated: 10-25-02 #ifndef STUDENT_H #define STUDENT_H #include #include #include #include "../Keywords.h" #include "../String/String.h" int Compare_cString(preserves String& a, preserves String& b); class Student_Rep { public: String FName,LName,Login,Alias; }; class Student { public: //Basic Operations String& FName(); String& LName(); String& Login(); String& Alias(); bool operator==(preserves Student& s); //Get functions are deep copy void Get_FName(produces String& FN); void Get_LName(produces String& LN); void Get_Login(produces String& Log); void Get_Alias(produces String& Aka); void Get(produces String& FN, produces String& LN, produces String& Log, produces String& Aka); void Swap_FName(alters String& FN); void Swap_LName(alters String& LN); void Swap_Login(alters String& Log); void Swap_Alias(alters String& Aka); void Set(consumes String& FN, consumes String& LN, consumes String& Log, consumes String& Aka); //Constructor/Destructor Student(); ~Student(); //Standard Operations void Clear(); void operator&=(alters Student& s); private: Student_Rep *rep; protected: void Initialize(); void Finalize(); }; //Basic Operations String& Student:: FName() { return rep->FName; } String& Student:: LName() { return rep->LName; } String& Student:: Login() { return rep->Login; } String& Student:: Alias() { return rep->Alias; } bool Student::operator==(preserves Student& s) { if(Compare_cString(s.rep->Login,rep->Login) == 0) return true; return false; } void Student::Get_FName(produces String& FN) { FN = rep->FName; } void Student::Get_LName(produces String& LN) { LN = rep->LName; } void Student::Get_Login(produces String& Log) { Log = rep->Login; } void Student::Get_Alias(produces String& Aka) { Aka = rep->Alias; } void Student::Get(produces String& FN, produces String& LN, produces String& Log, produces String& Aka) { FN &= rep->FName; LN &= rep->LName; Log &= rep->Login; Aka &= rep->Alias; } void Student::Swap_FName(alters String& FN) { FN &= rep->FName; } void Student::Swap_LName(alters String& LN) { LN &= rep->LName; } void Student::Swap_Login(alters String& Log) { Log &= rep->Login; } void Student::Swap_Alias(alters String& Aka) { Aka &= rep->Alias; } void Student::Set(consumes String& FN, consumes String& LN, consumes String& Log, consumes String& Aka) { rep->FName &= FN; rep->LName &= LN; rep->Login &= Log; rep->Alias &= Aka; } //Constructor/Destructor Student::Student() { Initialize(); } Student::~Student() { Finalize(); } //Standard Operations void Student::Clear() { Finalize(); Initialize(); } void Student::operator &=(alters Student& s) { Student_Rep *tmp; tmp = rep; rep = s.rep; s.rep = tmp; } //Protected Operations void Student::Initialize() { rep = new Student_Rep; assert(rep != 0); } void Student::Finalize() { delete rep; } int Compare_cString(preserves String& a, preserves String& b) { int min_len = a.Length(); //assume lhs is smaller int i; if(b.Length() < min_len) //then assumption wrong { min_len = b.Length(); } for(i = 0; i < min_len; i++) { if(a[i] < b[i]) { return -1; //lhs is smaller }else if(a[i] > b[i]) { return 1; //rhs is smaller } } //if we got here, then they're equal up to the minimum length if(a.Length() < b.Length()) { return -1; //lhs is smaller }else if(a.Length() > b.Length()) { return 1; }else{ return 0; //they must be equal } } #endif