/////////////////////////////////////////////////////////// // Softwarebauelemente II, Aufgabe C1.1 // // author: Stephan Brumme // last changes: July 3, 2001 #include "Exception.h" CException::CException() { m_strError.empty(); m_pSource = NULL; } CException::CException(const CException& exception) { operator=(exception); } // constructs a new exception CException::CException(const string strError, const CBasicClass* pSource) { m_strError = strError; m_pSource = pSource; } // show attributes string CException::Show() const { // check invariance if (!ClassInvariant()) return ""; ostringstream strOutput; strOutput << "Exception " << m_strError << " thrown." << endl << m_pSource->Show(); return strOutput.str(); } // shows all internal attributes string CException::ShowDebug() const { ostringstream strOutput; // print any information about this class strOutput << "DEBUG info for 'CException'" << endl << " m_strError=" << m_strError << endl << " m_pSource=" << m_pSource << endl; return strOutput.str(); } // validate an exception bool CException::ClassInvariant() const { return (m_pSource != NULL); } // copy constructor CException& CException::operator =(const CException &exception) { m_strError = exception.m_strError; m_pSource = exception.m_pSource; return *this; } // virtual, see operator= bool CException::Copy(const CBasicClass* pClass) { // cast to CException const CException *exception = dynamic_cast(pClass); // invalid class (is NULL when pClass is not a CException) if (exception == NULL || exception == this) return false; // use non virtual reference based copy // return value isn't needed operator=(*exception); // we're done return true; } // compare two exceptions bool CException::operator ==(const CException &exception) const { // all rooms were found return (m_strError == exception.m_strError && m_pSource == exception.m_pSource); } // virtual, see operator== bool CException::EqualValue(const CBasicClass* pClass) const { // cast to CException const CException *exception = dynamic_cast(pClass); // invalid class (is NULL when pClass is not a CException) if (exception == NULL || exception == this) return false; // use non virtual reference based copy return operator==(*exception); }