-
-
Notifications
You must be signed in to change notification settings - Fork 3k
/
qgschunklist_p.cpp
129 lines (116 loc) · 2.91 KB
/
qgschunklist_p.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
/***************************************************************************
qgschunklist_p.cpp
--------------------------------------
Date : July 2017
Copyright : (C) 2017 by Martin Dobias
Email : wonder dot sk at gmail dot com
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
#include "qgschunklist_p.h"
#include "qgschunknode_p.h"
///@cond PRIVATE
int QgsChunkList::trueCount() const
{
int len = 0;
QgsChunkListEntry *entry = mHead;
while ( entry )
{
++len;
entry = entry->next;
}
return len;
}
void QgsChunkList::insertEntry( QgsChunkListEntry *entry, QgsChunkListEntry *next )
{
if ( !mHead )
{
Q_ASSERT( next == nullptr );
mTail = mHead = entry;
}
else
{
entry->next = next;
if ( next == nullptr )
{
entry->prev = mTail;
mTail->next = entry;
mTail = entry;
}
else
{
entry->prev = next->prev;
next->prev = entry;
}
if ( next == mHead )
mHead = entry; // update head if "entry" we was head before
}
++mCount;
}
void QgsChunkList::takeEntry( QgsChunkListEntry *entry )
{
Q_ASSERT( entry );
if ( !entry->prev && !entry->next )
{
// last item in the list
Q_ASSERT( mHead == entry && mTail == entry );
mHead = mTail = nullptr;
}
else if ( !entry->prev )
{
// head item
Q_ASSERT( mHead == entry );
entry->next->prev = nullptr;
mHead = entry->next;
entry->next = nullptr;
}
else if ( !entry->next )
{
// tail item
Q_ASSERT( mTail == entry );
entry->prev->next = nullptr;
mTail = entry->prev;
entry->prev = nullptr;
}
else
{
// ordinary item
entry->prev->next = entry->next;
entry->next->prev = entry->prev;
entry->next = nullptr;
entry->prev = nullptr;
}
--mCount;
Q_ASSERT( !entry->prev );
Q_ASSERT( !entry->next );
}
QgsChunkListEntry *QgsChunkList::takeFirst()
{
QgsChunkListEntry *entry = mHead;
takeEntry( entry );
return entry;
}
QgsChunkListEntry *QgsChunkList::takeLast()
{
QgsChunkListEntry *entry = mTail;
takeEntry( entry );
return entry;
}
void QgsChunkList::insertFirst( QgsChunkListEntry *entry )
{
insertEntry( entry, mHead );
}
void QgsChunkList::insertLast( QgsChunkListEntry *entry )
{
insertEntry( entry, nullptr );
}
bool QgsChunkList::isEmpty() const
{
return mHead == nullptr;
}
/// @endcond