16 #include <nn/pia/common/common_Definitions.h>
17 #include <nn/pia/common/common_PtrUtil.h>
18 #include <nn/pia/common/common_ListBase.h>
50 class OffsetList :
public nn::pia::common::ListBase
60 : ListBase(), m_Offset(-1)
72 void InitOffset(int32_t offset)
92 void PushBack(T* pObj)
94 PushBackNode(ObjToListNode(pObj));
103 void PushFront(T* pObj)
105 PushFrontNode(ObjToListNode(pObj));
117 return ListNodeToObjWithNullCheck(PopBackNode());
129 return ListNodeToObjWithNullCheck(PopFrontNode());
140 void InsertBefore(
const T* pBasis, T* pObj)
142 InsertBeforeNode(ObjToListNode(pBasis), ObjToListNode(pObj));
153 void InsertAfter(
const T* pBasis, T* pObj)
155 InsertAfterNode(ObjToListNode(pBasis), ObjToListNode(pObj));
168 EraseNode(ObjToListNode(pObj));
180 return ListNodeToObjWithNullCheck(FrontNode());
192 return ListNodeToObjWithNullCheck(BackNode());
205 T* Prev(
const T* pObj)
const
207 ListNode* pPrev = ObjToListNode(pObj)->Prev();
208 if (pPrev == Terminator())
214 return ListNodeToObj(pPrev);
228 T* Next(
const T* pObj)
const
230 ListNode* pNext = ObjToListNode(pObj)->Next();
231 if (pNext == Terminator())
237 return ListNodeToObj(pNext);
249 bool IsInclude(
const T* pObj)
const
251 return IsIncludeNode(ObjToListNode(pObj));
261 void Rotate(
const T* pObj)
263 RotateNode(ObjToListNode(pObj));
272 friend class OffsetList<T>;
275 Iterator(
const OffsetList<T>* pList, T* pObj)
276 : m_pList(pList), m_pObj(pObj)
281 Iterator& operator++()
283 m_pObj = m_pList->ListNodeToObj(m_pList->ObjToListNode(m_pObj)->Next());
287 bool operator==(
const Iterator& x)
const
289 return m_pObj == x.m_pObj;
291 bool operator!=(
const Iterator& x)
const
293 return m_pObj != x.m_pObj;
305 const OffsetList<T>* GetList()
const
311 const OffsetList<T>* m_pList;
321 friend class OffsetList<T>;
324 ConstIterator(
const OffsetList<T>* pList,
const T* pObj)
325 : m_pList(pList), m_pObj(pObj)
330 ConstIterator& operator++()
332 m_pObj = m_pList->ListNodeToObj(m_pList->ObjToListNode(m_pObj)->Next());
336 bool operator==(
const ConstIterator& x)
const
338 return m_pObj == x.m_pObj;
340 bool operator!=(
const ConstIterator& x)
const
342 return m_pObj != x.m_pObj;
349 const T* operator->()
354 const OffsetList<T>* GetList()
const
360 const OffsetList<T>* m_pList;
373 friend class OffsetList<T>;
376 RobustIterator(
const OffsetList<T>* pList, T* pObj)
377 : m_pList(pList), m_pObj(pObj)
379 m_pNextNode = m_pList->ObjToListNode(pObj)->Next();
383 RobustIterator& operator++()
385 m_pObj = m_pList->ListNodeToObj(m_pNextNode);
386 m_pNextNode = m_pList->ObjToListNode(m_pObj)->Next();
390 bool operator==(
const RobustIterator& x)
const
392 return m_pObj == x.m_pObj;
394 bool operator!=(
const RobustIterator& x)
const
396 return m_pObj != x.m_pObj;
408 const OffsetList<T>* GetList()
const
414 const OffsetList<T>* m_pList;
416 ListNode* m_pNextNode;
425 Iterator Begin()
const
427 return Iterator(
this, ListNodeToObj(Terminator()->Next()));
438 return Iterator(
this, ListNodeToObj(Terminator()));
447 ConstIterator ConstBegin()
const
449 return ConstIterator(
this, ListNodeToObj(Terminator()->Next()));
458 ConstIterator ConstEnd()
const
460 return ConstIterator(
this, ListNodeToObj(Terminator()));
469 RobustIterator RobustBegin()
const
471 return RobustIterator(
this, ListNodeToObj(Terminator()->Next()));
480 RobustIterator RobustEnd()
const
482 return RobustIterator(
this, ListNodeToObj(Terminator()));
489 ListNode* ObjToListNode(
const T* pObj)
const
491 return reinterpret_cast<ListNode*
>(PtrUtil::addOffset(pObj, m_Offset));
494 T* ListNodeToObj(
const ListNode* pNode)
const
496 return reinterpret_cast<T*
>(PtrUtil::addOffset(pNode, -m_Offset));
499 T* ListNodeToObjWithNullCheck(
const ListNode* pNode)
const
502 return reinterpret_cast<T*
>(PtrUtil::addOffset(pNode, -m_Offset));
507 OffsetList(
const OffsetList&);
508 OffsetList& operator=(
const OffsetList&);