1 /* ScummVM - Graphic Adventure Engine
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #ifndef COMMON_LIST_INTERN_H
26 #define COMMON_LIST_INTERN_H
28 #include "common/scummsys.h"
32 template<typename T
> class List
;
35 namespace ListInternal
{
42 struct Node
: public NodeBase
{
45 Node(const T
&x
) : _data(x
) {}
48 template<typename T
> struct ConstIterator
;
52 typedef Iterator
<T
> Self
;
53 typedef Node
<T
> * NodePtr
;
59 Iterator() : _node(0) {}
60 explicit Iterator(NodeBase
*node
) : _node(node
) {}
69 Self
operator++(int) {
81 Self
operator--(int) {
86 ValueRef
operator*() const {
88 return static_cast<NodePtr
>(_node
)->_data
;
90 ValuePtr
operator->() const {
91 return &(operator*());
94 bool operator==(const Self
&x
) const {
95 return _node
== x
._node
;
98 bool operator!=(const Self
&x
) const {
99 return _node
!= x
._node
;
104 struct ConstIterator
{
105 typedef ConstIterator
<T
> Self
;
106 typedef const Node
<T
> * NodePtr
;
107 typedef const T
& ValueRef
;
108 typedef const T
* ValuePtr
;
110 const NodeBase
*_node
;
112 ConstIterator() : _node(0) {}
113 explicit ConstIterator(const NodeBase
*node
) : _node(node
) {}
114 ConstIterator(const Iterator
<T
> &x
) : _node(x
._node
) {}
119 _node
= _node
->_next
;
123 Self
operator++(int) {
131 _node
= _node
->_prev
;
135 Self
operator--(int) {
140 ValueRef
operator*() const {
142 return static_cast<NodePtr
>(_node
)->_data
;
144 ValuePtr
operator->() const {
145 return &(operator*());
148 bool operator==(const Self
&x
) const {
149 return _node
== x
._node
;
152 bool operator!=(const Self
&x
) const {
153 return _node
!= x
._node
;
159 bool operator==(const Iterator
<T
>& a
, const ConstIterator
<T
>& b
) {
160 return a
._node
== b
._node
;
164 bool operator!=(const Iterator
<T
>& a
, const ConstIterator
<T
>& b
) {
165 return a
._node
!= b
._node
;
170 } // End of namespace Common