-
Notifications
You must be signed in to change notification settings - Fork 0
/
domain.cpp
179 lines (162 loc) · 4.53 KB
/
domain.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include "domain.h"
#include <cstdlib>
#include <vector>
#include <string>
#include "setDebugNew.h"
#define new DEBUG_NEW
Tower::Tower(const std::vector<std::string>& params)
{
location = params[0];
size = params[1];
auraLevel = params[2];
parts = params[3];
vision = params[4];
printable = location + "," + size + "," + auraLevel + "," + parts + "," + vision;//new char[strlen(params[0]) + 2 + strlen(params[1]) + 2 + strlen(params[2]) + 2 + strlen(params[3]) + 2 + strlen(params[4]) + 2];
//printable = auraLevel + ", " + parts + ", " + size + ", " + location + ", " + vision;
}
Tower::Tower(const Tower& tower)
{
auraLevel = tower.auraLevel;
parts = tower.parts;
size = tower.size;
location = tower.location;
vision = tower.vision;
printable = location + "," + size + "," + auraLevel + "," + parts + "," + vision;
//printable = auraLevel + ", " + parts + ", " + size + ", " + location + ", " + vision;
}
Tower& Tower::operator=(const Tower& other)
{
this->auraLevel = other.auraLevel;
this->parts = other.parts;
this->size = other.size;
this->location = other.location;
this->vision = other.vision;
this->printable = other.printable;
// TODO: insert return statement here
return *this;
}
//Tower& Tower::operator=(Tower& tower)
//{
// if (this == &tower)
// return *this;
//
// this->~Tower();
//
// auraLevel = new char[strlen(tower.auraLevel) + 1];
// strcpy(auraLevel, tower.auraLevel);
// parts = new char[strlen(tower.parts) + 1];
// strcpy(parts, tower.parts);
// size = new char[strlen(tower.size) + 1];
// strcpy(size, tower.size);
// location = new char[strlen(tower.location) + 1];
// strcpy(location, tower.location);
// vision = new char[strlen(tower.vision) + 1];
// strcpy(vision, tower.vision);
// printable = new char[strlen(tower.auraLevel) + 2 + strlen(tower.parts) + 2 + strlen(tower.location) + 2 + strlen(tower.size) + 2 + strlen(tower.vision) + 2];
// printable[0] = 0;
//
// strcat(printable, tower.location);
// strcat(printable, ", ");
// strcat(printable, tower.size);
// strcat(printable, ", ");
// strcat(printable, tower.auraLevel);
// strcat(printable, ", ");
// strcat(printable, tower.parts);
// strcat(printable, ", ");
// strcat(printable, tower.vision);
// strcat(printable, "\0");
//
// active = tower.active;
//
// return *this;
//}
//Tower Tower::operator=(Tower tower)
//{
// auraLevel = new char[strlen(tower.auraLevel) + 1];
// strcpy(auraLevel, tower.auraLevel);
// parts = new char[strlen(tower.parts) + 1];
// strcpy(parts, tower.parts);
// size = new char[strlen(tower.size) + 1];
// strcpy(size, tower.size);
// location = new char[strlen(tower.location) + 1];
// strcpy(location, tower.location);
// vision = new char[strlen(tower.vision) + 1];
// strcpy(vision, tower.vision);
// printable = new char[strlen(tower.auraLevel) + 2 + strlen(tower.parts) + 2 + strlen(tower.location) + 2 + strlen(tower.size) + 2 + strlen(tower.vision) + 2];
// printable[0] = 0;
// strcat(printable, tower.location);
// strcat(printable, ", ");
// strcat(printable, tower.size);
// strcat(printable, ", ");
// strcat(printable, tower.auraLevel);
// strcat(printable, ", ");
// strcat(printable, tower.parts);
// strcat(printable, ", ");
// strcat(printable, tower.vision);
// strcat(printable, "\0");
// return *this;
//}
std::string Tower::get_aura_level() const
{
return auraLevel;
}
std::string Tower::get_parts() const
{
return parts;
}
std::string Tower::get_size() const
{
return size;
}
std::string Tower::get_location() const
{
return location;
}
std::string Tower::get_vision() const
{
return vision;
}
std::string Tower::print() const
{
return printable;
}
bool Tower::operator!=(const Tower& other) const
{
return this->location != other.location;
}
bool Tower::operator==(const Tower& other) const
{
return this->location == other.location;
}
Tower::~Tower()
{
}
std::ostream& operator<<(std::ostream& os, const Tower& tower)
{
// TODO: insert return statement here
os << tower.printable;
return os;
}
std::istream& operator>>(std::istream& is, Tower& tower)
{
// TODO: insert return statement here
std::string str;
std::getline(is, str);
/*
std::istringstream iss{ str };
std::string token;
str = "";
while (std::getline(iss, token, ','))
{
str += token;
}
iss.str(str);*/
std::istringstream iss{ str };
std::getline(iss, tower.location, ',');
std::getline(iss, tower.size, ',');
std::getline(iss, tower.auraLevel, ',');
std::getline(iss, tower.parts, ',');
std::getline(iss, tower.vision, ',');
tower.printable = tower.location + "," + tower.size + "," + tower.auraLevel + "," + tower.parts + "," + tower.vision;
return is;
}