-
Notifications
You must be signed in to change notification settings - Fork 0
/
AutoPersonal.cpp
162 lines (145 loc) · 4.02 KB
/
AutoPersonal.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#pragma warning(disable:4996)
#include "AutoPersonal.h"
#include "HierarchyHeaders.h"
#include "DefinedCodes.h"
uint AutoPersonal::autoPersonalCount = 0;
uint AutoPersonal::getAutoPersonalCount(void)
{
return autoPersonalCount;
}
AutoPersonal::AutoPersonal(char *caroserie, uint numarPersoane)
{
setCaroserie(caroserie);
setNumarPersoane(numarPersoane);
("AutoPersonal >>> Constructor protected");
}
AutoPersonal::AutoPersonal(void)
{
++autoPersonalCount;
Logger::client()->write("AutoPersonal >>> Constructor implicit");
}
AutoPersonal::AutoPersonal(char *marca, char *model, uint anFabricatie, float consumMediu, uint pretEUR, char *numar, char *caroserie, uint numarPersoane) : AutoVehicul(marca, model, anFabricatie, consumMediu, pretEUR, numar)
{
++autoPersonalCount;
setCaroserie(caroserie);
setNumarPersoane(numarPersoane);
Logger::client()->write("AutoPersonal >>> Constructor initializare");
}
AutoPersonal::AutoPersonal(const AutoPersonal &o)
{
++autoPersonalCount;
setMarca(o.marca);
setModel(o.model);
setAnFabricatie(o.anFabricatie);
setConsumMediu(o.consumMediu);
setPretEUR(o.pretEUR);
setNumar(o.numar);
setCaroserie(o.caroserie);
setNumarPersoane(o.numarPersoane);
Logger::client()->write("AutoPersonal >>> Constructor copiere");
}
AutoPersonal::~AutoPersonal(void)
{
--autoPersonalCount;
Logger::client()->write("AutoPersonal >>> Destructor");
}
uint AutoPersonal::codObiect(void)
{
return _CodAutoPersonal_;
}
bool AutoPersonal::read(istream &in, bool writeLog)
{
if (writeLog)
Logger::client()->write("AutoPersonal >>> read");
if (Util::isCin(in))
{
AutoVehicul::read(in, false);
setCaroserie(Util::read<char*>(in, "\tCaroserie: "));
setNumarPersoane(Util::read<uint>(in, "\tPersoane: "));
return true;
}
else
{
char *line = Util::read<char*>(in, "");
const uint maxObjectFields = 8;
if (Util::characterCount(line, '\t') != maxObjectFields - 1)
{
Util::warning(line);
return false;
}
int n;
char *copyLine = Util::copyString(line);
char **matrix = new char*[maxObjectFields];
char *token = strtok(line, "\t");
for (n = 0; token != nullptr; ++n)
{
matrix[n] = new char[2 + strlen(token)];
strcpy(matrix[n], token);
token = strtok(NULL, "\t");
}
int code;
float floatValue, uintValue;
setMarca(matrix[0]);
setModel(matrix[1]);
if (Util::successfullyRead(matrix[2], uintValue))
setAnFabricatie(uintValue);
else return false;
if (Util::successfullyRead(matrix[3], floatValue))
setConsumMediu(floatValue);
else return false;
if (Util::successfullyRead(matrix[4], uintValue))
setPretEUR(uintValue);
else return false;
setNumar(matrix[5]);
setCaroserie(matrix[6]);
if (Util::successfullyRead(matrix[7], uintValue))
setNumarPersoane(uintValue);
else return false;
return true;
}
}
void AutoPersonal::write(ostream &out, bool writeClassCode, bool writeNewLine, bool writeLog)
{
if (writeClassCode)
if (!Util::isCout(out))
Util::write(out, "", codObiect(), false);
bool writeNewLineConsideringOut = Util::isCout(out);
AutoVehicul::write(out, false, writeNewLineConsideringOut, false);
Util::write(out, "Caroserie: ", caroserie, writeNewLineConsideringOut);
Util::write(out, "Persoane: ", numarPersoane, writeNewLine);
if(writeLog)
Logger::client()->write("AutoPersonal >>> write");
}
char* AutoPersonal::getCaroserie(void) const
{
return this->caroserie;
}
uint AutoPersonal::getNumarPersoane(void) const
{
return numarPersoane;
}
void AutoPersonal::setCaroserie(char *caroserie)
{
Util::forgetString(this->caroserie);
this->caroserie = Util::copyString(caroserie);
}
void AutoPersonal::setNumarPersoane(uint numarPersoane)
{
this->numarPersoane = numarPersoane;
}
AutoPersonal& AutoPersonal::operator = (const AutoPersonal &o)
{
if (this != &o)
{
setMarca(o.marca);
setModel(o.model);
setAnFabricatie(o.anFabricatie);
setConsumMediu(o.consumMediu);
setPretEUR(o.pretEUR);
setNumar(o.numar);
setCaroserie(o.caroserie);
setNumarPersoane(o.numarPersoane);
}
Logger::client()->write("AutoPersonal >>> operator =");
return *this;
}