Iterator.h

Go to the documentation of this file.
00001 /* Depends: A generic dependency tracker in C++
00002  * Copyright (c) 2004-2007, Ronald Landheer-Cieslak
00003  * All rights reserved
00004  * 
00005  * This is free software. You may distribute it and/or modify it and
00006  * distribute modified forms provided that the following terms are met:
00007  *
00008  * * Redistributions of the source code must retain the above copyright
00009  *   notice, this list of conditions and the following disclaimer;
00010  * * Redistributions in binary form must reproduce the above copyright
00011  *   notice, this list of conditions and the following disclaimer in
00012  *   the documentation and/or other materials provided with the distribution;
00013  * * None of the names of the authors of this software may be used to endorse
00014  *   or promote this software, derived software or any distribution of this 
00015  *   software or any distribution of which this software is part, without 
00016  *   prior written permission from the authors involved;
00017  * * Unless you have received a written statement from Ronald Landheer-Cieslak
00018  *   that says otherwise, the terms of the GNU General Public License, as 
00019  *   published by the Free Software Foundation, version 2 or (at your option)
00020  *   any later version, also apply.
00021  * 
00022  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00023  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00024  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00025  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00026  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00027  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00028  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00029  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00030  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00031  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  * POSSIBILITY OF SUCH DAMAGE.
00033  */
00036 #ifndef _depends_details_iterator_h
00037 #define _depends_details_iterator_h
00038 
00039 #include <iterator>
00040 #include "Node.h"
00041 
00042 namespace Depends
00043 {
00044         namespace Details
00045         {
00047                 struct reverse_tag {};
00048                 
00050                 template <class ValueType, typename ReferenceType, typename PointerType, typename ScoreType, typename IteratorType>
00051                 struct IteratorBase : public std::iterator<std::forward_iterator_tag, ValueType, ptrdiff_t, PointerType, ReferenceType>
00052                 {
00053                         typedef IteratorBase<ValueType, ValueType&, ValueType*, ScoreType, IteratorType> iterator;
00054                         typedef IteratorBase<ValueType, const ValueType&, const ValueType*, ScoreType, IteratorType> const_iterator;
00055                         typedef Node<ValueType, ScoreType> node_type;
00056                         
00057                         IteratorBase(const IteratorType & i) : iter_(i) {}
00058                         IteratorBase(const iterator & i) : iter_(i.iter_) {}
00059 
00060                         ReferenceType operator*() const { return (*iter_)->value_; }
00061                         PointerType operator->() const { return &((*iter_)->value_); }
00062 
00063                         bool operator==(const IteratorBase & i) const { return iter_ == i.iter_; }
00064                         bool operator!=(const IteratorBase & i) const { return iter_ != i.iter_; }
00065 
00066                         const node_type * node() const { return *iter_; }
00067                         node_type * node() { return *iter_; }
00068 
00069                         IteratorType iter_;
00070                 };
00071 
00073                 template <class ValueType, typename ReferenceType, typename PointerType, typename ScoreType, typename IteratorType>
00074                 struct Iterator : public IteratorBase<ValueType, ReferenceType, PointerType, ScoreType, IteratorType>
00075                 {
00076                         typedef Iterator<ValueType, ValueType&, ValueType*, ScoreType, IteratorType> iterator;
00077                         typedef Iterator<ValueType, const ValueType&, const ValueType*, ScoreType, IteratorType> const_iterator;
00078                         typedef IteratorBase<ValueType, ReferenceType, PointerType, ScoreType, IteratorType> super;
00079                         
00080                         Iterator(const IteratorType & i) : IteratorBase<ValueType, ReferenceType, PointerType, ScoreType, IteratorType>(i) {}
00081                         Iterator(const iterator & i) : IteratorBase<ValueType, ReferenceType, PointerType, ScoreType, IteratorType>(i) {}
00082 
00083                         Iterator & operator++() { ++(super::iter_); return *this; };
00084                         Iterator operator++(int) { Iterator tmp = *this; ++(super::iter_); return tmp; };
00085 
00086                         Iterator & operator--() { --(super::iter_); return *this; };
00087                         Iterator operator--(int) { Iterator tmp = *this; --(super::iter_); return tmp; };
00088                 };
00089 
00091                 template <class ValueType, typename ReferenceType, typename PointerType, typename ScoreType, typename IteratorType>
00092                 struct ReverseIterator : public IteratorBase<ValueType, ReferenceType, PointerType, ScoreType, IteratorType>
00093                 {
00094                         typedef ReverseIterator<ValueType, ValueType&, ValueType*, ScoreType, IteratorType> iterator;
00095                         typedef ReverseIterator<ValueType, const ValueType&, const ValueType*, ScoreType, IteratorType> const_iterator;
00096                         typedef IteratorBase<ValueType, ReferenceType, PointerType, ScoreType, IteratorType> super;
00097                         
00098                         ReverseIterator(const IteratorType & i) : IteratorBase<ValueType, ReferenceType, PointerType, ScoreType, IteratorType>(i) {}
00099                         ReverseIterator(const iterator & i) : IteratorBase<ValueType, ReferenceType, PointerType, ScoreType, IteratorType>(i) {}
00100 
00101                         ReverseIterator & operator++() { ++(super::iter_); return *this; };
00102                         ReverseIterator operator++(int) { ReverseIterator tmp = *this; ++(super::iter_); return tmp; };
00103 
00104                         ReverseIterator & operator--() { --(super::iter_); return *this; };
00105                         ReverseIterator operator--(int) { ReverseIterator tmp = *this; --(super::iter_); return tmp; };
00106                 };
00107         }
00108 }
00109 
00110 #endif
00111 

Generated on Sat Aug 11 11:55:55 2007 for Depends by  doxygen 1.5.1