NW4F Sys
Loading...
Searching...
No Matches
ut_LinkList.h
Go to the documentation of this file.
1#ifndef NW_UT_LINKLIST_H_
2#define NW_UT_LINKLIST_H_
3
4#include <nw/types.h>
5#include <nw/ut/ut_Inlines.h>
6#include <nw/ut/ut_Iterator.h>
7
8namespace nw { namespace ut {
9
10class LinkListNode;
11
12namespace internal {
13
14class LinkListImpl;
15
16} // namespace internal
17
19{
20private:
22
23public:
25
26 explicit LinkListNode()
27 : m_pNext(NULL)
28 , m_pPrev(NULL)
29 {
30 }
31
32 Self* GetNext() const
33 {
34 return m_pNext;
35 }
36
37 Self* GetPrev() const
38 {
39 return m_pPrev;
40 }
41
42 friend bool operator==(const Self& r1, const Self& r2)
43 {
44 return &r1 == &r2;
45 }
46
47 friend bool operator!=(const Self& r1, const Self& r2)
48 {
49 return !(r1 == r2);
50 }
51
52private:
55
56 friend class internal::LinkListImpl;
57};
58static_assert(sizeof(LinkListNode) == 8);
59
60namespace internal {
61
63{
64private:
66
67public:
69 typedef u32 size_type;
71
75 typedef const value_type* const_pointer;
78 typedef std::bidirectional_iterator_tag iterator_category;
79
80 explicit LinkListImpl()
81 {
83 }
84
86 {
87 }
88
89 size_type size() const { return m_Size; }
90 bool empty() const { return m_Size == 0; }
91
92protected:
93 Node* GetBaseNode() { return &m_BaseNode; }
94 const Node* GetBaseNode() const { return &m_BaseNode; }
95
96private:
103
106};
107static_assert(sizeof(LinkListImpl) == 0xC);
108
109} // namespace internal
110
111template <typename T, PtrDiff TNOffset>
113{
114private:
116
117public:
118 typedef LinkList Self;
119 using Base::Node;
120
121 using Base::size_type;
122 using Base::difference_type;
123
124 typedef T value_type;
126 typedef const value_type* const_pointer;
129 typedef std::bidirectional_iterator_tag iterator_category;
130
132 {
133 }
134
135 using Base::size;
136 using Base::empty;
137
139 {
140 Node* baseNode = GetBaseNode();
141 Node* node = p == NULL ? baseNode : GetNodeFromPointer(p);
142 node = node->GetPrev();
143 return node == baseNode ? NULL : GetPointerFromNode(node);
144 }
145
147 {
148 const Node* baseNode = GetBaseNode();
149 const Node* node = p == NULL ? baseNode : GetNodeFromPointer(p);
150 node = node->GetPrev();
151 return node == baseNode ? NULL : GetPointerFromNode(node);
152 }
153
155 {
156 Node* baseNode = GetBaseNode();
157 Node* node = p == NULL ? baseNode : GetNodeFromPointer(p);
158 node = node->GetNext();
159 return node == baseNode ? NULL : GetPointerFromNode(node);
160 }
161
163 {
164 const Node* baseNode = GetBaseNode();
165 const Node* node = p == NULL ? baseNode : GetNodeFromPointer(p);
166 node = node->GetNext();
167 return node == baseNode ? NULL : GetPointerFromNode(node);
168 }
169
171 {
172 //NW_ASSERT_NOT_NULL(p);
173 return reinterpret_cast<Node*>(reinterpret_cast<IntPtr>(p) + TNOffset);
174 }
176 {
177 //NW_ASSERT_NOT_NULL(p);
178 return reinterpret_cast<const Node*>(reinterpret_cast<IntPtr>(p) + TNOffset);
179 }
180
182 {
183 //NW_ASSERT_NOT_NULL(p);
184 return reinterpret_cast<pointer>(reinterpret_cast<IntPtr>(p) - TNOffset);
185 }
187 {
188 //NW_ASSERT_NOT_NULL(p);
189 return reinterpret_cast<const_pointer>( reinterpret_cast<IntPtr>(p) - TNOffset);
190 }
191
192 size_type GetSize() const { return this->size(); }
193 bool IsEmpty() const { return this->empty(); }
194};
195
196} } // namespace nw::ut
197
198#endif // NW_UT_LINKLIST_H_
Definition ut_LinkList.h:19
Self * GetPrev() const
Definition ut_LinkList.h:37
friend bool operator==(const Self &r1, const Self &r2)
Definition ut_LinkList.h:42
LinkListNode Self
Definition ut_LinkList.h:24
Self * GetNext() const
Definition ut_LinkList.h:32
friend bool operator!=(const Self &r1, const Self &r2)
Definition ut_LinkList.h:47
LinkListNode()
Definition ut_LinkList.h:26
Self * m_pPrev
Definition ut_LinkList.h:54
Self * m_pNext
Definition ut_LinkList.h:53
Definition ut_LinkList.h:63
bool empty() const
Definition ut_LinkList.h:90
LinkListImpl()
Definition ut_LinkList.h:80
Node m_BaseNode
Definition ut_LinkList.h:105
const Node * GetBaseNode() const
Definition ut_LinkList.h:94
const value_type * const_pointer
Definition ut_LinkList.h:75
Node * GetBaseNode()
Definition ut_LinkList.h:93
std::bidirectional_iterator_tag iterator_category
Definition ut_LinkList.h:78
value_type & reference
Definition ut_LinkList.h:76
value_type * pointer
Definition ut_LinkList.h:74
~LinkListImpl()
Definition ut_LinkList.h:85
size_type m_Size
Definition ut_LinkList.h:104
LinkListImpl Self
Definition ut_LinkList.h:68
u32 size_type
Definition ut_LinkList.h:69
Node value_type
Definition ut_LinkList.h:73
PtrDiff difference_type
Definition ut_LinkList.h:70
LinkListNode Node
Definition ut_LinkList.h:72
const value_type & const_reference
Definition ut_LinkList.h:77
void Initialize_()
Definition ut_LinkList.h:97
size_type size() const
Definition ut_LinkList.h:89
Definition ut_LinkList.h:12
Definition ut_CriticalSection.h:6
Definition math_Constant.cpp:5
signed long PtrDiff
Definition types.h:24
unsigned long IntPtr
Definition types.h:23
#define NW_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition types.h:31