summaryrefslogtreecommitdiff
path: root/plugins/updater/common.cpp
blob: f7b240bbf687a7f33a209b13a5e16941f7581a9b (plain)
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
#include "common.h"

UpdateList::UpdateList(): count(0), head(0), tail(0) {
}

UpdateList::~UpdateList() {
	clear();
}

UpdateList::UpdateList(UpdateList &source): count(0), head(0), tail(0) {
	for(source.reset(); source.current(); source.next()) 
		push_back(*source.current());
}

void UpdateList::clear() {
	Node *current;
	while(head) {
		current = head;
		head = head->next;
		delete current;
	}

	count = 0;
	head = tail = 0;
	reset();
}

int UpdateList::size() {
	return count;
}

void UpdateList::reset() {
	it_current = head;
}

void UpdateList::erase() {
	if(it_current) {
		if(head == it_current) head = head->next;
		if(tail == it_current) tail = tail->prev;

		if(it_current->next) it_current->next->prev = it_current->prev;
		if(it_current->prev) it_current->prev->next = it_current->next;

		delete it_current;
		count--;
		reset();
	}
}

void UpdateList::next() {
	if(it_current) it_current = (Node *)it_current->next;
}

UpdateInternal *UpdateList::current() {
	return (it_current ? &it_current->ui : 0);
}

void UpdateList::push_back(UpdateInternal &update) {
	if(tail) {
		tail->next = new Node;
		tail->next->prev = tail;
		tail = tail->next;
	} else {
		head = tail = new Node;
	}
	tail->ui = update;
	count++;
}

UpdateInternal &UpdateList::back() {
	return tail->ui;
}