17 #include <pia/common/common_definitions.h> 18 #include <pia/common/common_OffsetList.h> 38 class ObjList :
public nn::pia::common::ListBase
60 c_LinkOffset = offsetof(Node, m_Link),
61 c_ItemOffset = offsetof(Node, m_Item)
77 c_NodeSize =
sizeof(Node)
85 : ListBase(), m_FreeList(), m_pBuffer(NULL), m_LimitNum(0)
87 m_FreeList.InitOffset(offsetof(Node, m_Link));
96 static u32 GetNeedBufferSize(u32 limitNum)
98 return limitNum * c_NodeSize;
110 void SetBuffer(u32 limitNum,
void* pBuffer)
116 m_pBuffer =
reinterpret_cast<Node*
>(pBuffer);
117 m_LimitNum = limitNum;
118 for (u32 i = 0; i < limitNum; ++i)
120 new (&m_pBuffer[i].m_Link) ListNode();
121 m_FreeList.PushBack(&m_pBuffer[i]);
126 PIA_ASSERTMSG(
false,
"pBuf is null");
131 PIA_ASSERTMSG(
false,
"limitNum[%d] must be larger than zero", limitNum);
141 bool IsBufferReady()
const 143 return m_pBuffer != NULL;
165 return m_FreeList.IsEmpty();
176 ListNode* pNode = Terminator()->Next();
177 while (pNode != Terminator())
179 ListNode* pN = pNode;
180 pNode = pNode->Next();
182 m_FreeList.PushFront(ListNodeToNode(pN));
199 PIA_ASSERTMSG(
false,
"buffer full");
202 Node* pNode = m_FreeList.PopBack();
203 new (&pNode->m_Item) T();
204 PushBackNode(&(pNode->m_Link));
205 return &(pNode->m_Item);
222 Node* pNode = m_FreeList.PopBack();
223 new (&pNode->m_Item) T();
224 PushBackNode(&(pNode->m_Link));
225 return &(pNode->m_Item);
240 PIA_ASSERTMSG(
false,
"buffer full");
243 Node* pNode = m_FreeList.PopBack();
244 new (&pNode->m_Item) T();
245 PushFrontNode(&(pNode->m_Link));
246 return &(pNode->m_Item);
263 Node* pNode = m_FreeList.PopBack();
264 new (&pNode->m_Item) T();
265 PushFrontNode(&(pNode->m_Link));
266 return &(pNode->m_Item);
279 T* BirthBefore(
const T* pBasis)
283 PIA_ASSERTMSG(
false,
"buffer full");
286 Node* pNode = m_FreeList.PopBack();
287 new (&pNode->m_Item) T();
288 InsertBeforeNode(&(ObjToNode(pBasis)->m_Link), &(pNode->m_Link));
289 return &(pNode->m_Item);
302 T* TryBirthBefore(
const T* pBasis)
308 Node* pNode = m_FreeList.PopBack();
309 new (&pNode->m_Item) T();
310 InsertBeforeNode(&(ObjToNode(pBasis)->m_Link), &(pNode->m_Link));
311 return &(pNode->m_Item);
324 T* BirthAfter(
const T* pBasis)
328 PIA_ASSERTMSG(
false,
"buffer full");
331 Node* pNode = m_FreeList.PopBack();
332 new (&pNode->m_Item) T();
333 InsertAfterNode(&(ObjToNode(pBasis)->m_Link), &(pNode->m_Link));
334 return &(pNode->m_Item);
347 T* TryBirthAfter(
const T* pBasis)
353 Node* pNode = m_FreeList.PopBack();
354 new (&pNode->m_Item) T();
355 InsertAfterNode(&(ObjToNode(pBasis)->m_Link), &(pNode->m_Link));
356 return &(pNode->m_Item);
369 Node* pNode = ObjToNode(pObj);
371 EraseNode(&(pNode->m_Link));
372 m_FreeList.PushFront(pNode);
384 ListNode* pLink = FrontNode();
389 return &(ListNodeToNode(pLink)->m_Item);
401 ListNode* pLink = BackNode();
406 return &(ListNodeToNode(pLink)->m_Item);
419 T* Prev(
const T* pObj)
421 ListNode* pPrevLink = ObjToNode(pObj)->m_Link.Prev();
422 if (pPrevLink == Terminator())
426 return &(ListNodeToNode(pPrevLink)->m_Item);
439 T* Next(
const T* pObj)
441 ListNode* pNextLink = ObjToNode(pObj)->m_Link.Next();
442 if (pNextLink == Terminator())
446 return &(ListNodeToNode(pNextLink)->m_Item);
457 bool IsInclude(
const T* pObj)
const 459 return IsIncludeNode(&(ObjToNode(pObj)->m_Link));
468 friend class ObjList<T>;
471 Iterator(
const ObjList<T>* pList,
typename ObjList<T>::Node* pNode)
472 : m_pList(pList), m_pNode(pNode)
477 Iterator& operator++()
479 m_pNode = m_pList->ListNodeToNode(m_pNode->m_Link.Next());
483 bool operator==(
const Iterator& x)
const 485 return m_pNode == x.m_pNode;
487 bool operator!=(
const Iterator& x)
const 489 return m_pNode != x.m_pNode;
494 return m_pNode->m_Item;
498 return &(m_pNode->m_Item);
502 const ObjList<T>* m_pList;
503 typename ObjList<T>::Node* m_pNode;
512 friend class ObjList<T>;
515 ConstIterator(
const ObjList<T>* pList,
typename ObjList<T>::Node* pNode)
516 : m_pList(pList), m_pNode(pNode)
521 ConstIterator& operator++()
523 m_pNode = m_pList->ListNodeToNode(m_pNode->m_Link.Next());
527 bool operator==(
const ConstIterator& x)
const 529 return m_pNode == x.m_pNode;
531 bool operator!=(
const ConstIterator& x)
const 533 return m_pNode != x.m_pNode;
536 const T& operator*()
const 538 return m_pNode->m_Item;
540 const T* operator->()
const 542 return &(m_pNode->m_Item);
546 const ObjList<T>* m_pList;
547 typename ObjList<T>::Node* m_pNode;
559 friend class ObjList<T>;
562 RobustIterator(
const ObjList<T>* pList,
typename ObjList<T>::Node* pNode)
563 : m_pList(pList), m_pNode(pNode)
565 m_pNextLink = m_pNode->m_Link.Next();
569 RobustIterator& operator++()
571 m_pNode = m_pList->ListNodeToNode(m_pNextLink);
572 m_pNextLink = m_pNode->m_Link.Next();
576 bool operator==(
const RobustIterator& x)
const 578 return m_pNode == x.m_pNode;
580 bool operator!=(
const RobustIterator& x)
const 582 return m_pNode != x.m_pNode;
587 return m_pNode->m_Item;
591 return &(m_pNode->m_Item);
595 const ObjList<T>* m_pList;
596 typename ObjList<T>::Node* m_pNode;
597 ListNode* m_pNextLink;
606 Iterator Begin()
const 608 return Iterator(
this, ListNodeToNode(Terminator()->Next()));
619 return Iterator(
this, ListNodeToNode(Terminator()));
628 ConstIterator ConstBegin()
const 630 return ConstIterator(
this, ListNodeToNode(Terminator()->Next()));
639 ConstIterator ConstEnd()
const 641 return ConstIterator(
this, ListNodeToNode(Terminator()));
650 RobustIterator RobustBegin()
const 652 return RobustIterator(
this, ListNodeToNode(Terminator()->Next()));
661 RobustIterator RobustEnd()
const 663 return RobustIterator(
this, ListNodeToNode(Terminator()));
667 static Node* ObjToNode(
const T* pObj)
669 return reinterpret_cast<Node*
>((
reinterpret_cast<u32
>(pObj)) - c_ItemOffset);
672 static Node* ListNodeToNode(
const ListNode* pListNode)
674 return reinterpret_cast<Node*
>((
reinterpret_cast<u32
>(pListNode)) - c_LinkOffset);
679 OffsetList<Node> m_FreeList;