25#include <kiwano/macros.h>
32template <
typename _PtrTy>
36 using value_type =
typename std::pointer_traits<_PtrTy>::pointer;
37 using pointer = value_type*;
38 using reference = value_type&;
83 return first_ ==
nullptr;
91 child->prev_->next_ = child->next_;
93 child->next_->prev_ = child->prev_;
96 child->next_ =
nullptr;
100 last_->next_ = child;
115 child->prev_->next_ = child->next_;
117 child->next_->prev_ = child->prev_;
119 child->prev_ =
nullptr;
120 child->next_ = first_;
124 first_->prev_ = child;
139 child->prev_->next_ = child->next_;
141 child->next_->prev_ = child->prev_;
144 before->prev_->next_ = child;
148 child->prev_ = before->prev_;
149 child->next_ = before;
150 before->prev_ = child;
158 child->prev_->next_ = child->next_;
160 child->next_->prev_ = child->prev_;
163 after->next_->prev_ = child;
167 child->next_ = after->next_;
168 child->prev_ = after;
169 after->next_ = child;
178 child->next_->prev_ = child->prev_;
182 last_ = child->prev_;
187 child->prev_->next_ = child->next_;
191 first_ = child->next_;
194 child->prev_ =
nullptr;
195 child->next_ =
nullptr;
202 value_type p = first_;
209 tmp->next_ =
nullptr;
210 tmp->prev_ =
nullptr;
226 value_type p = first_;
249 template <
typename _IterPtrTy>
252 using iterator_category = std::bidirectional_iterator_tag;
253 using value_type = _IterPtrTy;
254 using pointer = _IterPtrTy*;
255 using reference = _IterPtrTy&;
256 using difference_type = ptrdiff_t;
258 inline Iterator(value_type ptr =
nullptr,
bool is_end =
false)
264 inline reference operator*()
const
266 KGE_ASSERT(base_ && !is_end_);
267 return const_cast<reference
>(base_);
270 inline pointer operator->()
const
272 return std::pointer_traits<pointer>::pointer_to(**
this);
277 KGE_ASSERT(base_ && !is_end_);
278 value_type next = base_->GetNext();
299 base_ = base_->GetPrev();
310 inline bool operator==(
const Iterator& other)
const
312 return base_ == other.base_ && is_end_ == other.is_end_;
315 inline bool operator!=(
const Iterator& other)
const
317 return !(*
this == other);
320 inline operator bool()
const
322 return base_ !=
nullptr && !is_end_;
328 typename std::remove_const<value_type>::type base_;
334 using reverse_iterator = std::reverse_iterator<iterator>;
335 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
339 return iterator(first_, first_ ==
nullptr);
342 inline const_iterator begin()
const
344 return const_iterator(first_, first_ ==
nullptr);
347 inline const_iterator cbegin()
const
352 inline iterator end()
354 return iterator(last_,
true);
357 inline const_iterator end()
const
359 return const_iterator(last_,
true);
362 inline const_iterator cend()
const
367 inline reverse_iterator rbegin()
369 return reverse_iterator(end());
372 inline const_reverse_iterator rbegin()
const
374 return const_reverse_iterator(end());
377 inline const_reverse_iterator crbegin()
const
382 inline reverse_iterator rend()
384 return reverse_iterator(begin());
387 inline const_reverse_iterator rend()
const
389 return const_reverse_iterator(begin());
392 inline const_reverse_iterator crend()
const
397 inline value_type& front()
400 throw std::out_of_range(
"front() called on empty list");
404 inline const value_type& front()
const
407 throw std::out_of_range(
"front() called on empty list");
411 inline value_type& back()
414 throw std::out_of_range(
"back() called on empty list");
418 inline const value_type& back()
const
421 throw std::out_of_range(
"back() called on empty list");
432template <
typename _PtrTy>
436 using value_type =
typename std::pointer_traits<_PtrTy>::pointer;
437 using reference = value_type&;
438 using pointer = value_type*;
侵入式链表元素
Definition: IntrusiveList.h:434
const value_type & GetPrev() const
获取前一元素
Definition: IntrusiveList.h:459
value_type & GetNext()
获取下一元素
Definition: IntrusiveList.h:480
const value_type & GetNext() const
获取下一元素
Definition: IntrusiveList.h:473
value_type & GetPrev()
获取前一元素
Definition: IntrusiveList.h:466
侵入式链表
Definition: IntrusiveList.h:34
value_type & GetFirst()
获取首元素
Definition: IntrusiveList.h:60
void InsertBefore(reference child, reference before)
在链表的对象前插入新对象
Definition: IntrusiveList.h:136
void Clear()
清空所有对象
Definition: IntrusiveList.h:200
const value_type & GetFirst() const
获取首元素
Definition: IntrusiveList.h:53
value_type & GetLast()
获取尾元素
Definition: IntrusiveList.h:74
void PushBack(reference child)
在链表尾部添加对象
Definition: IntrusiveList.h:88
void InsertAfter(reference child, reference after)
在链表的对象后插入新对象
Definition: IntrusiveList.h:155
void Remove(reference child)
移除对象
Definition: IntrusiveList.h:174
bool IsEmpty() const
链表是否为空
Definition: IntrusiveList.h:81
void PushFront(reference child)
在链表头部添加对象
Definition: IntrusiveList.h:112
bool CheckValid()
检查链表是否有效
Definition: IntrusiveList.h:219
const value_type & GetLast() const
获取尾元素
Definition: IntrusiveList.h:67
Definition: IntrusiveList.h:251