1 ///////////////////////////////////////////////////////////
2 // Softwarebauelemente II, Aufgabe O3.1
3 //
4 // author: Stephan Brumme
5 // last changes: May 15, 2001
6
7 #include "CashOffice.h"
8
9
10 // default constructor
11 CCashOffice::CCashOffice() : CRoom()
12 {
13 m_nNumberOfCounter = 0;
14 }
15
16 // copy constructor
17 CCashOffice::CCashOffice(const CCashOffice& cashOffice)
18 {
19 operator=(cashOffice);
20 }
21
22 CCashOffice::CCashOffice(int nNumberOfRoom, int nArea, int nNumberOfCounter)
23 : CRoom(nNumberOfRoom, nArea)
24 {
25 m_nNumberOfCounter = nNumberOfCounter;
26 }
27
28
29 // display the attributes
30 string CCashOffice::Show() const
{
31 ostringstream strOutput;
32
33 strOutput << CRoom::Show() << " Counter no. "
34 << m_nNumberOfCounter << "." << endl;
35
36 return strOutput.str();
37 }
38
39
40 // display the attributes
41 // only for internal purposes !
42 string CCashOffice::ShowDebug() const
{
43 ostringstream strOutput;
44
45 strOutput << CRoom::ShowDebug()
46 << "DEBUG info for 'CCashOffice'" << endl
47 << " m_nNumberOfCounter = " << m_nNumberOfCounter << endl;
48
49 return strOutput.str();
50 }
51
52
53 // verify invariance
54 bool CCashOffice::ClassInvariant() const
{
55 // only positive numbers allowed
56 return (CRoom::ClassInvariant() &&
57 m_nNumberOfCounter > 0 && m_nNumberOfCounter <= MAXCOUNTER);
58 }
59
60
61 // copy one CashOffice to another one
62 CCashOffice& CCashOffice::operator=(const CCashOffice& cashOffice)
63 {
64 // copy all variables
65 // first copy the attributes of CRoom
66 CRoom::operator=(cashOffice);
67 // and now our new ones of CCashOffice
68 m_nNumberOfCounter = cashOffice.m_nNumberOfCounter;
69
70 return *this;
71 }
72
73
74 // virtual, see operator=
75 bool CCashOffice::Copy(const CBasicClass* pClass)
76 {
77 // cast to CCashOffice
78 CBasicClass *basic;
79 CCashOffice *cashOffice;
80 basic = const_cast<CBasicClass*>(pClass);
81 cashOffice = dynamic_cast<CCashOffice*>(basic);
82
83 // invalid class (is NULL when pClass is not a CCashOffice)
84 if (cashOffice == NULL || cashOffice == this)
85 return false;
86
87 // use non virtual reference based copy
88 // return value isn't needed
89 operator=(*cashOffice);
90
91 // we're done
92 return true;
93 }
94
95
96 // compare the CashOffice with another one
97 bool CCashOffice::operator==(const CCashOffice& cashOffice) const
{
98 // use the CRoom compare function
99 return (CRoom::operator==(cashOffice) &&
100 m_nNumberOfCounter == cashOffice.m_nNumberOfCounter);
101 }
102
103
104 // compare the CashOffice with another one
105 // routes call down to "==" operator
106 bool CCashOffice::EqualValue(const CBasicClass* pClass) const
{
107 // cast to CCashOffice
108 CBasicClass *basic;
109 CCashOffice *cashOffice;
110 basic = const_cast<CBasicClass*>(pClass);
111 cashOffice = dynamic_cast<CCashOffice*>(basic);
112
113 // invalid class (is NULL when pClass is not a CCashOffice)
114 if (cashOffice == NULL || cashOffice == this)
115 return false;
116
117 // use non virtual reference based copy
118 return operator==(*cashOffice);
119 }
120
121
122 // retrieve the private value of m_nNumberOfCounter
123 int CCashOffice::GetNumberOfCounter() const
{
124 return m_nNumberOfCounter;
125 }
126
127
128 // change private m_nNumberOfCounter
129 void CCashOffice::SetNumberOfCounter(const int nNumberOfCounter)
130 {
131 m_nNumberOfCounter = nNumberOfCounter;
132 }
133
134
135 // retrieve the private value of CRoom::m_nNumberOfCashOffice
136 int CCashOffice::GetNumberOfCashOffice() const
{
137 return CRoom::GetNumberOfRoom();
138 }
139
140
141 // change private CRoom::m_nNumberOfCashOffice
142 void CCashOffice::SetNumberOfCashOffice(const int nNumberOfCashOffice)
143 {
144 CRoom::SetNumberOfRoom(nNumberOfCashOffice);
145 }
146
147
148 // deliver CRoom::m_nArea
149 int CCashOffice::GetAreaOfCashOffice() const
{
150 return CRoom::GetArea();
151 }
152
153
154
155