1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     ut_LinkList.cpp
4 
5   Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain proprietary
8   information of Nintendo and/or its licensed developers and are protected by
9   national and international copyright laws. They may not be disclosed to third
10   parties or copied or duplicated in any form, in whole or in part, without the
11   prior written consent of Nintendo.
12 
13   The content herein is highly confidential and should be handled accordingly.
14 
15   $Revision: $
16  *---------------------------------------------------------------------------*/
17 
18 #include "precompiled.h"
19 
20 #include <nw/ut/ut_LinkList.h>
21 
22 namespace nw {
23 namespace ut {
24 namespace internal {
25 
26 //--------------------------------------------------------------------------
27 LinkListImpl::iterator
erase(iterator it)28 LinkListImpl::erase(iterator it)
29 {
30     NW_ASSERT(it.m_pPointer != &m_BaseNode);
31     iterator itNext = it;
32     (void)++itNext;
33     return erase(it,itNext);
34 }
35 
36 
37 //--------------------------------------------------------------------------
38 LinkListImpl::iterator
erase(iterator itFirst,iterator itLast)39 LinkListImpl::erase(iterator itFirst,iterator itLast)
40 {
41     Node* pIt = itFirst.m_pPointer;
42     Node* const pItLast = itLast.m_pPointer;
43     Node* pNext;
44 
45     for ( ; pIt != pItLast ; pIt = pNext)
46     {
47         pNext = pIt->m_pNext;
48         (void)erase(pIt);
49     }
50 
51     return itLast;
52 }
53 
54 //--------------------------------------------------------------------------
55 void
reverse(void)56 LinkListImpl::reverse(void)
57 {
58     if (empty()) { return; }
59 
60     Node* p = m_BaseNode.m_pNext;
61     Node* pNext;
62 
63     Initialize_();
64 
65     for ( ; p != &m_BaseNode ; p = pNext )
66     {
67         pNext = p->m_pNext;
68         p->m_pNext = NULL;
69         p->m_pPrev = NULL;
70         push_front(p);
71     }
72 }
73 
74 //--------------------------------------------------------------------------
75 LinkListImpl::iterator
insert(iterator it,pointer p)76 LinkListImpl::insert(iterator it, pointer p)
77 {
78     NW_NULL_ASSERT(p);
79     Node *const pIt = it.m_pPointer;
80     NW_NULL_ASSERT(pIt);
81 
82     Node *const pItPrev = pIt->m_pPrev;
83     NW_NULL_ASSERT(pItPrev);
84 
85     NW_ASSERT(p->m_pNext == NULL);
86     NW_ASSERT(p->m_pPrev == NULL);
87     p->m_pNext = pIt;
88     p->m_pPrev = pItPrev;
89 
90     pIt->m_pPrev = p;
91     pItPrev->m_pNext = p;
92 
93     ++m_Size;
94     return iterator(p);
95 }
96 
97 
98 //--------------------------------------------------------------------------
99 LinkListImpl::iterator
erase(pointer p)100 LinkListImpl::erase(pointer p)
101 {
102     NW_ASSERT(!empty());
103     NW_NULL_ASSERT(p);
104     NW_ASSERT(p != &m_BaseNode);
105 
106     Node* const pNext = p->m_pNext;
107     Node* const pPrev = p->m_pPrev;
108 
109     NW_NULL_ASSERT(pNext);
110     pNext->m_pPrev = pPrev;
111     NW_NULL_ASSERT(pPrev);
112     pPrev->m_pNext = pNext;
113     --m_Size;
114 
115     p->m_pNext = NULL;
116     p->m_pPrev = NULL;
117 
118     return iterator(pNext);
119 }
120 
121 }  // namespace internal
122 }  // namespace ut
123 }  // namespace nw
124