|
Blender
V2.59
|
00001 /* 00002 * $Id: GEN_List.h 35158 2011-02-25 11:49:19Z jesterking $ 00003 * ***** BEGIN GPL LICENSE BLOCK ***** 00004 * 00005 * This program is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU General Public License 00007 * as published by the Free Software Foundation; either version 2 00008 * of the License, or (at your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 * GNU General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software Foundation, 00017 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 * 00019 * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV. 00020 * All rights reserved. 00021 * 00022 * The Original Code is: all of this file. 00023 * 00024 * Contributor(s): none yet. 00025 * 00026 * ***** END GPL LICENSE BLOCK ***** 00027 */ 00028 00034 #ifndef GEN_LIST_H 00035 #define GEN_LIST_H 00036 00037 class GEN_Link { 00038 public: 00039 GEN_Link() : m_next(0), m_prev(0) {} 00040 GEN_Link(GEN_Link *next, GEN_Link *prev) : m_next(next), m_prev(prev) {} 00041 00042 GEN_Link *getNext() const { return m_next; } 00043 GEN_Link *getPrev() const { return m_prev; } 00044 00045 bool isHead() const { return m_prev == 0; } 00046 bool isTail() const { return m_next == 0; } 00047 00048 void insertBefore(GEN_Link *link) { 00049 m_next = link; 00050 m_prev = link->m_prev; 00051 m_next->m_prev = this; 00052 m_prev->m_next = this; 00053 } 00054 00055 void insertAfter(GEN_Link *link) { 00056 m_next = link->m_next; 00057 m_prev = link; 00058 m_next->m_prev = this; 00059 m_prev->m_next = this; 00060 } 00061 00062 void remove() { 00063 m_next->m_prev = m_prev; 00064 m_prev->m_next = m_next; 00065 } 00066 00067 private: 00068 GEN_Link *m_next; 00069 GEN_Link *m_prev; 00070 }; 00071 00072 class GEN_List { 00073 public: 00074 GEN_List() : m_head(&m_tail, 0), m_tail(0, &m_head) {} 00075 00076 GEN_Link *getHead() const { return m_head.getNext(); } 00077 GEN_Link *getTail() const { return m_tail.getPrev(); } 00078 00079 void addHead(GEN_Link *link) { link->insertAfter(&m_head); } 00080 void addTail(GEN_Link *link) { link->insertBefore(&m_tail); } 00081 00082 private: 00083 GEN_Link m_head; 00084 GEN_Link m_tail; 00085 }; 00086 00087 #endif 00088