-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPaper.cpp
102 lines (81 loc) · 1.58 KB
/
Paper.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
// Paper.cpp
#include "Paper.h"
Paper::Paper()
{
this->length = 0;
this->current = 0;
}
Paper::Paper(const Paper& source):linkedList(source.linkedList)
{
this->length = source.length;
this->current = 0;
}
Paper::~Paper() {}
Paper& Paper::operator=(const Paper& source)
{
this->linkedList = source.linkedList;
this->length = source.length;
this->current = 0;
return *this;
}
Label& Paper::GetAt(int index)
{
return this->linkedList.GetAt(index);
}
Label* Paper::Attach(Label label)
{
LinkedList<Label>::Node* node = this->linkedList.GetCurrent();
if(node == 0)
{
node = this->linkedList.AppendFromHead(label);
}
else
{
node = this->linkedList.InsertAfter(node, label);
}
this->current = &(node->GetObject());
this->length++;
return this->current;
}
Label Paper::Detach()
{
Label label = *(this->current);
LinkedList<Label>::Node* node = this->linkedList.Delete();
if(node != 0)
{
this->current = &(node->GetObject());
}
else
{
this->current = 0;
}
this->length--;
return label;
}
int CompareLabel(void* one, void* other)
{
int ret = -1;
if(one == other)
{
ret = 0;
}
return ret;
}
Label* Paper::MoveUp()
{
if(this->length > 1)
{
LinkedList<Label>::Node* previous = this->linkedList.Previous();
this->current = &(previous->GetObject());
}
return this->current;
}
Label* Paper::MoveDown()
{
if(this->length > 1)
{
LinkedList<Label>::Node* next = this->linkedList.Next();
this->current = &(next->GetObject());
}
return this->current;
}