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