/////////////////////////////////////////////////////////// // Softwarebauelemente II, Aufgabe O3.2 // // author: Stephan Brumme // last changes: May 29, 2001 #include "CashOffice.h" // default constructor CCashOffice::CCashOffice() : CRoom() { m_nNumberOfCounter = 0; } // copy constructor CCashOffice::CCashOffice(const CCashOffice& cashOffice) { operator=(cashOffice); } CCashOffice::CCashOffice(int nNumberOfRoom, int nArea, int nNumberOfCounter) : CRoom(nNumberOfRoom, nArea) { m_nNumberOfCounter = nNumberOfCounter; } // display the attributes string CCashOffice::Show() const { // check invariance if (!ClassInvariant()) return ""; ostringstream strOutput; strOutput << CRoom::Show() << " Counter no. " << m_nNumberOfCounter << "." << endl; return strOutput.str(); } // display the attributes // only for internal purposes ! string CCashOffice::ShowDebug() const { ostringstream strOutput; strOutput << CRoom::ShowDebug() << "DEBUG info for 'CCashOffice'" << endl << " m_nNumberOfCounter = " << m_nNumberOfCounter << endl; return strOutput.str(); } // verify invariance bool CCashOffice::ClassInvariant() const { // only positive numbers allowed return (CRoom::ClassInvariant() && m_nNumberOfCounter > 0 && m_nNumberOfCounter <= MAXCOUNTER); } // copy one CashOffice to another one CCashOffice& CCashOffice::operator=(const CCashOffice& cashOffice) { // copy all variables // first copy the attributes of CRoom CRoom::operator=(cashOffice); // and now our new ones of CCashOffice m_nNumberOfCounter = cashOffice.m_nNumberOfCounter; return *this; } // virtual, see operator= bool CCashOffice::Copy(const CBasicClass* pClass) { // cast to CCashOffice const CCashOffice *cashOffice = dynamic_cast(pClass); // invalid class (is NULL when pClass is not a CCashOffice) if (cashOffice == NULL || cashOffice == this) return false; // use non virtual reference based copy // return value isn't needed operator=(*cashOffice); // we're done return true; } // compare the CashOffice with another one bool CCashOffice::operator==(const CCashOffice& cashOffice) const { // use the CRoom compare function return (CRoom::operator==(cashOffice) && m_nNumberOfCounter == cashOffice.m_nNumberOfCounter); } // compare the CashOffice with another one // routes call down to "==" operator bool CCashOffice::EqualValue(const CBasicClass* pClass) const { // cast to CCashOffice const CCashOffice *cashOffice = dynamic_cast(pClass); // invalid class (is NULL when pClass is not a CCashOffice) if (cashOffice == NULL || cashOffice == this) return false; // use non virtual reference based copy return operator==(*cashOffice); } // retrieve the private value of m_nNumberOfCounter int CCashOffice::GetNumberOfCounter() const { return m_nNumberOfCounter; } // change private m_nNumberOfCounter void CCashOffice::SetNumberOfCounter(const int nNumberOfCounter) { m_nNumberOfCounter = nNumberOfCounter; } // retrieve the private value of CRoom::m_nNumberOfCashOffice int CCashOffice::GetNumberOfCashOffice() const { return CRoom::GetNumberOfRoom(); } // change private CRoom::m_nNumberOfCashOffice void CCashOffice::SetNumberOfCashOffice(const int nNumberOfCashOffice) { CRoom::SetNumberOfRoom(nNumberOfCashOffice); } // deliver CRoom::m_nArea int CCashOffice::GetAreaOfCashOffice() const { return CRoom::GetArea(); }