1 ///////////////////////////////////////////////////////////
2 // Softwarebauelemente II, Aufgabe O3.2
3 //
4 // author: Stephan Brumme
5 // last changes: May 30, 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 // check invariance
32 if (!ClassInvariant())
33 return "";
34
35 ostringstream strOutput;
36
37 strOutput << "Exception " << m_strError << " thrown." << endl
<< m_pSource->Show();
38
39 return strOutput.str();
40 }
41
42
43 // shows all internal attributes
44 string CException::ShowDebug() const
{
45 ostringstream strOutput;
46
47 // print any information about this class
48 strOutput << "DEBUG info for 'CException'" << endl
49 << " m_strError=" << m_strError << endl
<< " m_pSource=" << m_pSource << endl;
50
51 return strOutput.str();
52 }
53
54
55 // validate an exception
56 bool CException::ClassInvariant() const
{
57 return (m_pSource != NULL);
58 }
59
60
61 // copy constructor
62 CException& CException::operator =(const CException &exception)
63 {
64 m_strError = exception.m_strError;
65 m_pSource = exception.m_pSource;
66 return *this;
67 }
68
69
70 // virtual, see operator=
71 bool CException::Copy(const CBasicClass* pClass)
72 {
73 // cast to CException
74 const CException *exception = dynamic_cast<const CException*>(pClass);
75
76 // invalid class (is NULL when pClass is not a CException)
77 if (exception == NULL || exception == this)
78 return false;
79
80 // use non virtual reference based copy
81 // return value isn't needed
82 operator=(*exception);
83
84 // we're done
85 return true;
86 }
87
88
89 // compare two exceptions
90 bool CException::operator ==(const CException &exception) const
{
91 // all rooms were found
92 return (m_strError == exception.m_strError &&
93 m_pSource == exception.m_pSource);
94 }
95
96
97 // virtual, see operator==
98 bool CException::EqualValue(const CBasicClass* pClass) const
{
99 // cast to CException
100 const CException *exception = dynamic_cast<const CException*>(pClass);
101
102 // invalid class (is NULL when pClass is not a CException)
103 if (exception == NULL || exception == this)
104 return false;
105
106 // use non virtual reference based copy
107 return operator==(*exception);
108 }
109
110