ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

list_intern.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_LIST_INTERN_H
00024 #define COMMON_LIST_INTERN_H
00025 
00026 #include "common/scummsys.h"
00027 
00028 namespace Common {
00029 
00030 template<typename T> class List;
00031 
00032 
00033 namespace ListInternal {
00034     struct NodeBase {
00035         NodeBase *_prev;
00036         NodeBase *_next;
00037     };
00038 
00039     template<typename T>
00040     struct Node : public NodeBase {
00041         T _data;
00042 
00043         Node(const T &x) : _data(x) {}
00044     };
00045 
00046     template<typename T> struct ConstIterator;
00047 
00048     template<typename T>
00049     struct Iterator {
00050         typedef Iterator<T> Self;
00051         typedef Node<T> *   NodePtr;
00052         typedef T &         ValueRef;
00053         typedef T *         ValuePtr;
00054         typedef T           ValueType;
00055 
00056         NodeBase *_node;
00057 
00058         Iterator() : _node(nullptr) {}
00059         explicit Iterator(NodeBase *node) : _node(node) {}
00060 
00061         // Prefix inc
00062         Self &operator++() {
00063             if (_node)
00064                 _node = _node->_next;
00065             return *this;
00066         }
00067         // Postfix inc
00068         Self operator++(int) {
00069             Self tmp(_node);
00070             ++(*this);
00071             return tmp;
00072         }
00073         // Prefix dec
00074         Self &operator--() {
00075             if (_node)
00076                 _node = _node->_prev;
00077             return *this;
00078         }
00079         // Postfix dec
00080         Self operator--(int) {
00081             Self tmp(_node);
00082             --(*this);
00083             return tmp;
00084         }
00085         ValueRef operator*() const {
00086             assert(_node);
00087             return static_cast<NodePtr>(_node)->_data;
00088         }
00089         ValuePtr operator->() const {
00090             return &(operator*());
00091         }
00092 
00093         bool operator==(const Self &x) const {
00094             return _node == x._node;
00095         }
00096 
00097         bool operator!=(const Self &x) const {
00098             return _node != x._node;
00099         }
00100     };
00101 
00102     template<typename T>
00103     struct ConstIterator {
00104         typedef ConstIterator<T>    Self;
00105         typedef const Node<T> * NodePtr;
00106         typedef const T &       ValueRef;
00107         typedef const T *       ValuePtr;
00108 
00109         const NodeBase *_node;
00110 
00111         ConstIterator() : _node(nullptr) {}
00112         explicit ConstIterator(const NodeBase *node) : _node(node) {}
00113         ConstIterator(const Iterator<T> &x) : _node(x._node) {}
00114 
00115         // Prefix inc
00116         Self &operator++() {
00117             if (_node)
00118                 _node = _node->_next;
00119             return *this;
00120         }
00121         // Postfix inc
00122         Self operator++(int) {
00123             Self tmp(_node);
00124             ++(*this);
00125             return tmp;
00126         }
00127         // Prefix dec
00128         Self &operator--() {
00129             if (_node)
00130                 _node = _node->_prev;
00131             return *this;
00132         }
00133         // Postfix dec
00134         Self operator--(int) {
00135             Self tmp(_node);
00136             --(*this);
00137             return tmp;
00138         }
00139         ValueRef operator*() const {
00140             assert(_node);
00141             return static_cast<NodePtr>(_node)->_data;
00142         }
00143         ValuePtr operator->() const {
00144             return &(operator*());
00145         }
00146 
00147         bool operator==(const Self &x) const {
00148             return _node == x._node;
00149         }
00150 
00151         bool operator!=(const Self &x) const {
00152             return _node != x._node;
00153         }
00154     };
00155 
00156 
00157     template<typename T>
00158     bool operator==(const Iterator<T>& a, const ConstIterator<T>& b) {
00159         return a._node == b._node;
00160     }
00161 
00162     template<typename T>
00163     bool operator!=(const Iterator<T>& a, const ConstIterator<T>& b) {
00164         return a._node != b._node;
00165     }
00166 }
00167 
00168 
00169 } // End of namespace Common
00170 
00171 #endif


Generated on Sat Feb 16 2019 05:00:55 for ResidualVM by doxygen 1.7.1
curved edge   curved edge