1 // padthv1_list.h
2 //
3 /****************************************************************************
4    Copyright (C) 2012, rncbc aka Rui Nuno Capela. All rights reserved.
5 
6    This program is free software; you can redistribute it and/or
7    modify it under the terms of the GNU General Public License
8    as published by the Free Software Foundation; either version 2
9    of the License, or (at your option) any later version.
10 
11    This program is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14    GNU General Public License for more details.
15 
16    You should have received a copy of the GNU General Public License along
17    with this program; if not, write to the Free Software Foundation, Inc.,
18    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 
20 *****************************************************************************/
21 
22 #ifndef __padthv1_list_h
23 #define __padthv1_list_h
24 
25 
26 //-------------------------------------------------------------------------
27 // padthv1_list - generic double-linked list node.
28 
29 template<typename T>
30 class padthv1_list
31 {
32 public:
33 
padthv1_list()34 	padthv1_list() : m_prev(0), m_next(0) {}
35 
append(T * p)36 	void append(T *p)
37 	{
38 		p->m_prev = m_prev;
39 		p->m_next = 0;
40 
41 		if (m_prev)
42 			m_prev->m_next = p;
43 		else
44 			m_next = p;
45 
46 		m_prev = p;
47 	}
48 
remove(T * p)49 	void remove(T *p)
50 	{
51 		if (p->m_prev)
52 			p->m_prev->m_next = p->m_next;
53 		else
54 			m_next = p->m_next;
55 
56 		if (p->m_next)
57 			p->m_next->m_prev = p->m_prev;
58 		else
59 			m_prev = p->m_prev;
60 	}
61 
prev()62 	T *prev() const { return m_prev; }
next()63 	T *next() const { return m_next; }
64 
65 private:
66 
67 	T *m_prev;
68 	T *m_next;
69 };
70 
71 
72 #endif	// __padthv1_list_h
73 
74 // end of padthv1_list.h
75