/////////////////////////////////////////////////////////// // Softwarebauelemente II, Aufgabe O2.1 // // author: Stephan Brumme // last changes: February 26, 2001 #include "Room.h" #include CRoom::CRoom(int nNumberOfRoom, int nArea) { m_nArea = nArea; m_nNumberOfRoom = nNumberOfRoom; } // attention ! this method is NOT part of CRoom ostream& operator<<(ostream &mystream, const CRoom& room) { return room.OutStream(mystream); } // used to perform proper display in derived classes ostream& CRoom::OutStream(ostream& mystream, bool bDebug) const { if (!bDebug) { mystream << "Room no. " << m_nNumberOfRoom << " covers an area of " << m_nArea << " square feet."; } else { mystream << "DEBUG info for '" << ClassnameOf() << "'" << endl << " m_nArea=" << m_nArea << " m_nNumberOfRoom=" << m_nNumberOfRoom << endl; } return mystream; } // compare the room with another one bool CRoom::operator==(const CRoom &room) const { return ((room.m_nArea == m_nArea) && (room.m_nNumberOfRoom == m_nNumberOfRoom)); } // compare the room with another one // routes call down to "==" operator bool CRoom::EqualValue(const CRoom* room) const { // disallow NULL pointer if (room == NULL) return false; return (operator==(*room)); } // copy one room to another one // prevents user from copying an object to itself CRoom& CRoom::operator=(const CRoom &room) { // copy all variables m_nArea = room.m_nArea; m_nNumberOfRoom = room.m_nNumberOfRoom; return *this; } // copy one room to another one // prevents user from copying an object to itself // calls "=" operator internally bool CRoom::Copy(const CRoom* room) { // disallow NULL pointer if (room == NULL) return false; // cannot copy an object to itself if (this == room) return false; // use "=" operator operator=(*room); return true; } // retrieve the private value of m_nNumberOfRoom int CRoom::GetNumberOfRoom() const { return m_nNumberOfRoom; } // change private m_nNumberOfRoom void CRoom::SetNumberOfRoom(const int nNumberOfRoom) { m_nNumberOfRoom = nNumberOfRoom; } // retrieve the private value of m_nArea int CRoom::GetArea() const { return m_nArea; }