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