Blender  V2.59
CTR_List.cpp
Go to the documentation of this file.
00001 /*
00002  * $Id: CTR_List.cpp 35146 2011-02-25 10:45:31Z 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 #include "CTR_List.h"
00035 
00036 
00037 CTR_Link::
00038 CTR_Link(
00039 ) : 
00040         m_next(0), 
00041         m_prev(0) 
00042 {
00043 }
00044 
00045 CTR_Link::
00046 CTR_Link(
00047         CTR_Link *next,
00048         CTR_Link *prev
00049 ) : 
00050         m_next(next), 
00051         m_prev(prev) 
00052 {
00053 }
00054 
00055         CTR_Link *
00056 CTR_Link::
00057 getNext(
00058 ) const {
00059         return m_next; 
00060 }
00061 
00062         CTR_Link *
00063 CTR_Link::
00064 getPrev(
00065 ) const { 
00066         return m_prev; 
00067 }  
00068 
00069         bool 
00070 CTR_Link::
00071 isHead(
00072 ) const { 
00073         return m_prev == 0; 
00074 }
00075 
00076         bool 
00077 CTR_Link::
00078 isTail(
00079 ) const { 
00080         return m_next == 0; 
00081 }
00082 
00083         void 
00084 CTR_Link::
00085 insertBefore(
00086         CTR_Link *link
00087 ) {
00088     m_next         = link;
00089     m_prev         = link->m_prev;
00090     m_next->m_prev = this;
00091     m_prev->m_next = this;
00092 } 
00093 
00094         void 
00095 CTR_Link::
00096 insertAfter(
00097         CTR_Link *link
00098 ) {
00099     m_next         = link->m_next;
00100     m_prev         = link;
00101     m_next->m_prev = this;
00102     m_prev->m_next = this;
00103 } 
00104 
00105         void 
00106 CTR_Link::
00107 remove(
00108 ) { 
00109     m_next->m_prev = m_prev; 
00110     m_prev->m_next = m_next;
00111 }
00112 
00113 
00114 CTR_List::
00115 CTR_List(
00116 ) : 
00117         m_head(&m_tail, 0), 
00118         m_tail(0, &m_head) 
00119 {
00120 }
00121 
00122         CTR_Link *
00123 CTR_List::
00124 getHead(
00125 ) const { 
00126         return m_head.getNext(); 
00127 }
00128 
00129         CTR_Link *
00130 CTR_List::
00131 getTail(
00132 ) const { 
00133         return m_tail.getPrev();
00134 } 
00135 
00136         void 
00137 CTR_List::
00138 addHead(
00139         CTR_Link *link
00140 ) { 
00141         link->insertAfter(&m_head); 
00142 }
00143 
00144         void 
00145 CTR_List::
00146 addTail(
00147         CTR_Link *link
00148 ) { 
00149         link->insertBefore(&m_tail); 
00150 }
00151