-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpan.cpp
More file actions
50 lines (50 loc) · 1.21 KB
/
Copy pathSpan.cpp
File metadata and controls
50 lines (50 loc) · 1.21 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
#include"Span.h"
SpanList::SpanList()
{
//static ObjectPool<Span> head_spanPool;
//m_head = new Span;
m_head = m_head_spanPool.New();
m_head->m_next = m_head;
m_head->m_prev = m_head;
}
void SpanList::Insert(Span* pos, Span* newSpan)
{
if (pos == nullptr) throw(SpanListException("Function Insert: Insert pos is nullptr\n"));
if (newSpan == nullptr) throw(SpanListException("Function Insert: Insert obj is nullptr\n"));
Span* prev = pos->m_prev;
prev->m_next = newSpan;
newSpan->m_prev = prev;
newSpan->m_next = pos;
pos->m_prev = newSpan;
}
void SpanList::Erase(Span* pos)
{
if (pos == nullptr) throw(SpanListException("Function Erase: Erase pos is nullptr\n"));
if (pos == m_head) throw(SpanListException("Function Erase: Erase pos is m_head\n"));
Span* prev = pos->m_prev;
Span* next = pos->m_next;
prev->m_next = next;
next->m_prev = prev;
}
Span* SpanList::Begin()
{
return m_head->m_next;
}
Span* SpanList::End()
{
return m_head;
}
bool SpanList::Empty()
{
return m_head->m_next == m_head;
}
void SpanList::PushFront(Span* newSpan)
{
Insert(m_head->m_next, newSpan);
}
Span* SpanList::PopFront()
{
Span* front = m_head->m_next;
Erase(front);
return front;
}