-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCell.cpp
More file actions
66 lines (52 loc) · 1.27 KB
/
Cell.cpp
File metadata and controls
66 lines (52 loc) · 1.27 KB
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
#include "Cell.h"
using namespace std;
Cell::Cell(int x, int y) : m_x(x), m_y(y)
{
}
Cell::~Cell()
{
}
void Cell::add_neighb(Cell *n1)
{
for(int i = 0 ; i < m_nb_neighb ; i++)
if(m_neighb[i] == n1)
return;
m_nb_neighb++;
Cell **new_neighb = new Cell*[m_nb_neighb];
for(int i = 0 ; i < m_nb_neighb - 1 ; i++)
new_neighb[i] = m_neighb[i];
new_neighb[m_nb_neighb - 1] = n1;
delete[] m_neighb;
m_neighb = new_neighb;
n1->add_neighb(this);
}
void Cell::add_neighb(Cell *n1, Cell *n2)
{
add_neighb(n1);
add_neighb(n2);
}
void Cell::add_neighb(Cell *n1, Cell *n2, Cell *n3)
{
add_neighb(n1);
add_neighb(n2);
add_neighb(n3);
}
ostream& operator<<(ostream& stream, const Cell& r) {
stream << "("<< r.m_x << ","<<r.m_y<<")"<< r.m_nb_neighb;
for (int i =0; i<r.m_nb_neighb ; i++)
{
stream << "("<< r.m_neighb[i]->m_x << ","<<r.m_neighb[i]->m_y<<")";
}
stream<<endl;
cout << "("<< r.m_x << ","<<r.m_y<<")" << endl;
return stream ;
}
istream& operator<<(istream& stream, Cell& r) {
string ligne;
const char lim=')';
getline(stream,ligne,lim);
Cell* new_r = new Cell(ligne[1],ligne[3]);
cout <<ligne<<endl;
// r = new_r // à faire marcher je veux que l'addresse de r devienne celle de new_r
return stream ;
}