/*---------------------------------------------------------------------------* Project: Horizon File: List.h Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo of America Inc. and/or Nintendo Company Ltd., and are protected by Federal copyright law. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. $Rev: 46365 $ *---------------------------------------------------------------------------*/ #ifndef NN_COMMON_SCENE_LIST_H_ #define NN_COMMON_SCENE_LIST_H_ namespace scene { template class Node { public: // Data T data; // Next node Node* pNextNode; }; template class List { public: // Iterator class iterator { public: // Constructor iterator(Node* pNode) { m_pNode = pNode; } // Return the data reference T operator*() { return m_pNode->data; } // Compare bool operator==(List::iterator it) { return (m_pNode == it.m_pNode); } // Compare bool operator!=(List::iterator it) { return (m_pNode != it.m_pNode); } // Later positioned increment void operator++(int) { m_pNode = m_pNode->pNextNode; } protected: Node* m_pNode; }; public: // Constructor List() { m_pHeadNode = NULL; m_pTailNode = NULL; } // Add to start void push_front(T data) { Node* pNode = new Node; pNode->data = data; pNode->pNextNode = NULL; if (m_pHeadNode == NULL) { m_pHeadNode = pNode; } if (m_pTailNode != NULL) { m_pTailNode->pNextNode = pNode; } m_pTailNode = pNode; } // Clear void clear() { Node* pCurNode = m_pHeadNode; while (pCurNode) { Node* pNextNode = pCurNode->pNextNode; delete pCurNode; pCurNode = pNextNode; } m_pHeadNode = NULL; m_pTailNode = NULL; } // Return start iterator List::iterator begin() { return iterator(m_pHeadNode); } // Return terminal iterator List::iterator end() { return iterator(NULL); } protected: // Start node Node* m_pHeadNode; // Terminal node Node* m_pTailNode; }; } // namespace scene #endif // NN_COMMON_SCENE_LIST_H_