sources:
BasicClass.h (1.4k)
C1_2.cpp (604 bytes)
CashOffice.cpp (3.8k)
CashOffice.h (1.8k)
Date.cpp (6.0k)
Date.h (2.9k)
Exception.cpp (2.5k)
Exception.h (1.4k)
House.cpp (6.8k)
House.h (2.5k)
Room.cpp (3.0k)
Room.h (1.6k)


binaries:
Release/C1_2.exe (140.0k)


website:
more info here
studies/bauelemente/Softwarebauelemente-CodeC1-2/Exception.cpp
download file

  1 ///////////////////////////////////////////////////////////
  2 // Softwarebauelemente II, Aufgabe C1.1
  3 //
  4 // author: Stephan Brumme
  5 // last changes: July 3, 2001
  6
  7 #include "Exception.h"
  8
  9
 10 CException::CException()
 11 {
 12     m_strError.empty();
 13     m_pSource = NULL;
 14 }
 15
 16 CException::CException(const CException& exception)
 17 {
 18     operator=(exception);
 19 }
 20
 21 // constructs a new exception
 22 CException::CException(const string strError, const CBasicClass* pSource)
 23 {
 24     m_strError = strError;
 25     m_pSource  = pSource;
 26 }
 27
 28
 29 // show attributes
 30 string CException::Show() const
 31 {
 32     // check invariance
 33     if (!ClassInvariant())
 34         return "";
 35
 36     ostringstream strOutput;
 37
 38     strOutput << "Exception " << m_strError << " thrown." << endl
 39               << m_pSource->Show();
 40
 41     return strOutput.str();
 42 }
 43
 44
 45 // shows all internal attributes
 46 string CException::ShowDebug() const
 47 {
 48     ostringstream strOutput;
 49
 50     // print any information about this class
 51     strOutput << "DEBUG info for 'CException'"  << endl
 52               << " m_strError=" << m_strError << endl
 53               << " m_pSource=" << m_pSource   << endl;
 54
 55     return strOutput.str();
 56 }
 57
 58
 59 // validate an exception
 60 bool CException::ClassInvariant() const
 61 {
 62     return (m_pSource != NULL);
 63 }
 64
 65
 66 // copy constructor
 67 CException& CException::operator =(const CException &exception)
 68 {
 69     m_strError = exception.m_strError;
 70     m_pSource  = exception.m_pSource;
 71     return *this;
 72 }
 73
 74
 75 // virtual, see operator=
 76 bool CException::Copy(const CBasicClass* pClass)
 77 {
 78     // cast to CException
 79     const CException *exception = dynamic_cast<const CException*>(pClass);
 80
 81     // invalid class (is NULL when pClass is not a CException)
 82     if (exception == NULL || exception == this)
 83         return false;
 84
 85     // use non virtual reference based copy
 86     // return value isn't needed
 87     operator=(*exception);
 88
 89     // we're done
 90     return true;
 91 }
 92
 93
 94 // compare two exceptions
 95 bool CException::operator ==(const CException &exception) const
 96 {
 97     // all rooms were found
 98     return (m_strError == exception.m_strError &&
 99             m_pSource  == exception.m_pSource)
;
100 }
101
102
103 // virtual, see operator==
104 bool CException::EqualValue(const CBasicClass* pClass) const
105 {
106     // cast to CException
107     const CException *exception = dynamic_cast<const CException*>(pClass);
108
109     // invalid class (is NULL when pClass is not a CException)
110     if (exception == NULL || exception == this)
111         return false;
112
113     // use non virtual reference based copy
114     return operator==(*exception);
115 }
116