CTR Pia  4.11.3
Game Communication Engine
common_ListBase.h
1 /*---------------------------------------------------------------------------*
2  Project: Pia
3  File: common_ListBase.h
4 
5  Copyright Nintendo. All rights reserved.
6 
7  These coded instructions, statements, and computer programs contain
8  proprietary information of Nintendo of America Inc. and/or Nintendo
9  Company Ltd., and are protected by Federal copyright law. They may
10  not be disclosed to third parties or copied or duplicated in any form,
11  in whole or in part, without the prior written consent of Nintendo.
12  *---------------------------------------------------------------------------*/
13 
14 
15 #pragma once
16 
17 #include <pia/common/common_definitions.h>
18 #include <pia/common/common_ListNode.h>
19 
20 
21 namespace nn
22 {
23 namespace pia
24 {
25 namespace common
26 {
27 
28 
29 /*!
30 @cond PRIVATE
31 @brief Represents the base class for lists.
32 */
33 class ListBase : public nn::pia::common::RootObject
34 {
35 public:
36 /*!
37 @brief Instantiates the object with default parameters (default constructor).
38 */
39  ListBase(void)
40  {
41  Init();
42  }
43 
44 
45 /*!
46 @brief Gets the number of elements in the list.
47 @return Returns the number of elements in the list.
48 */
49  u32 Size() const
50  {
51  return m_Size;
52  }
53 
54 
55 /*!
56 @brief Determines whether the list is empty.
57 @return Returns <tt>true</tt> if the list is empty.
58 */
59  bool IsEmpty() const
60  {
61  return (Size() == 0);
62  }
63 
64 
65 protected:
66  void Init();
67 
68  void InitListNode(ListNode* pNode)
69  {
70  pNode->InitListNode();
71  }
72 
73  void ClearNode();
74 
75  void InsertBeforeNode(ListNode* pBasis, ListNode* pNode);
76 
77  void InsertAfterNode(ListNode* pBasis, ListNode* pNode);
78 
79  void EraseNode(ListNode* pNode);
80 
81  bool IsIncludeNode(const ListNode* pNode) const;
82 
83 
84  void PushFrontNode(ListNode* pNode)
85  {
86  InsertAfterNode(&m_Terminator, pNode);
87  }
88 
89  void PushBackNode(ListNode* pNode)
90  {
91  InsertBeforeNode(&m_Terminator, pNode);
92  }
93 
94  ListNode* PopFrontNode();
95 
96  ListNode* PopBackNode();
97 
98 
99  ListNode* FrontNode() const
100  {
101  return (m_Size > 0) ? m_Terminator.m_pNext : NULL;
102  }
103 
104  ListNode* BackNode() const
105  {
106  return (m_Size > 0) ? m_Terminator.m_pPrev : NULL;
107  }
108 
109  void RotateNode(ListNode* pNode);
110 
111 
112  const ListNode* Terminator() const
113  {
114  return &m_Terminator;
115  }
116 
117 private:
118  // Copying is prohibited.
119  ListBase(const ListBase& rhs);
120  ListBase& operator=(const ListBase& rhs);
121 
122 private:
123  ListNode m_Terminator;
124  u32 m_Size;
125 };
126 //! @endcond
127 }
128 }
129 } // end of namespace nn::pia::common
Definition: assert.h:115
This is the common base class used inside the Pia library.
Definition: common_RootObject.h:40