1 ///////////////////////////////////////////////////////////
2 // Softwarebauelemente II, Aufgabe O2.1
3 //
4 // author: Stephan Brumme
5 // last changes: February 26, 2001
6
7 #include "Room.h"
8 #include <iostream>
9
10
11 CRoom::CRoom(int nNumberOfRoom, int nArea)
12 {
13 m_nArea = nArea;
14 m_nNumberOfRoom = nNumberOfRoom;
15 }
16
17
18 // attention ! this method is NOT part of CRoom
19 ostream& operator<<(ostream &mystream, const CRoom& room)
20 {
21 return room.OutStream(mystream);
22 }
23
24
25 // used to perform proper display in derived classes
26 ostream& CRoom::OutStream(ostream& mystream, bool bDebug) const
27 {
28 if (!bDebug)
29 {
30 mystream << "Room no. " << m_nNumberOfRoom
31 << " covers an area of " << m_nArea << " square feet.";
32 }
33 else
34 {
35 mystream << "DEBUG info for '" << ClassnameOf() << "'" << endl
36 << " m_nArea=" << m_nArea
37 << " m_nNumberOfRoom=" << m_nNumberOfRoom << endl;
38 }
39
40 return mystream;
41 }
42
43
44 // compare the room with another one
45 bool CRoom::operator==(const CRoom &room) const
46 {
47 return ((room.m_nArea == m_nArea) &&
48 (room.m_nNumberOfRoom == m_nNumberOfRoom));
49 }
50
51
52 // compare the room with another one
53 // routes call down to "==" operator
54 bool CRoom::EqualValue(const CRoom* room) const
55 {
56 // disallow NULL pointer
57 if (room == NULL)
58 return false;
59
60 return (operator==(*room));
61 }
62
63
64
65 // copy one room to another one
66 // prevents user from copying an object to itself
67 CRoom& CRoom::operator=(const CRoom &room)
68 {
69 // copy all variables
70 m_nArea = room.m_nArea;
71 m_nNumberOfRoom = room.m_nNumberOfRoom;
72
73 return *this;
74 }
75
76
77 // copy one room to another one
78 // prevents user from copying an object to itself
79 // calls "=" operator internally
80 bool CRoom::Copy(const CRoom* room)
81 {
82 // disallow NULL pointer
83 if (room == NULL)
84 return false;
85
86 // cannot copy an object to itself
87 if (this == room)
88 return false;
89
90 // use "=" operator
91 operator=(*room);
92
93 return true;
94 }
95
96
97 // retrieve the private value of m_nNumberOfRoom
98 int CRoom::GetNumberOfRoom() const
99 {
100 return m_nNumberOfRoom;
101 }
102
103
104 // change private m_nNumberOfRoom
105 void CRoom::SetNumberOfRoom(const int nNumberOfRoom)
106 {
107 m_nNumberOfRoom = nNumberOfRoom;
108 }
109
110
111 // retrieve the private value of m_nArea
112 int CRoom::GetArea() const
113 {
114 return m_nArea;
115 }
116