Iterator.h

Go to the documentation of this file.
00001 /** @file Iterator.h
00002 * @author Gabor Madl
00003 * @date Created 10/2006
00004 * @brief Iterator template class.
00005 *
00006 *
00007 * =================================================================
00008 * DREAM License v2.0
00009 * 
00010 * DREAM - Distributed Real-time Embedded Analysis Method
00011 * http://dre.sourceforge.net.
00012 * Copyright (c) 2005-2007 Gabor Madl, All Rights Reserved.
00013 * 
00014 * This file is part of DREAM.
00015 * 
00016 * DREAM is free software; you can redistribute it and/or modify it
00017 * under the terms of the GNU General Public License version 2 as
00018 * published by the Free Software Foundation. No future versions of
00019 * the GPL license may be automatically applied to DREAM. It is in
00020 * the sole discretion of the copyright holder to determine whether
00021 * DREAM may be released under a different license or terms. There
00022 * are no restrictions on the use of DREAM for any purpose.
00023 * 
00024 * DREAM is distributed in the hope that it will be useful,
00025 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00026 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00027 * GNU General Public License for more details.
00028 * 
00029 * You should have received a copy of the GNU General Public License
00030 * along with this program; if not, write to the Free Software
00031 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00032 * MA 02110-1301, USA.
00033 * 
00034 * By submitting comments, suggestions, code, code snippets,
00035 * techniques (including that of usage), and algorithms, submitters
00036 * acknowledge that they have the right to do so, that any such
00037 * submissions are given freely and unreservedly, and that they
00038 * waive any claims to copyright or ownership. In addition,
00039 * submitters acknowledge that any such submission might become
00040 * part of the copyright maintained on the overall body of code,
00041 * which comprises DREAM. By making a submission, submitter agrees
00042 * to these terms. Furthermore, submitters acknowledge that the
00043 * incorporation or modification of such submissions is entirely
00044 * at the discretion of the moderators of the DREAM project.
00045 * 
00046 * DREAM links to the Libxml2 third party library. Please see 
00047 * COPYING-libxml for the copyright information of Libxml2.
00048 * =================================================================
00049 */
00050 
00051 #if (_MSC_VER >= 1400)                          // VC8+
00052 #pragma warning (disable:4996)          // Disable all deprecation warnings
00053 #endif 
00054 
00055 #ifndef DREAM_ITERATOR
00056 #define DREAM_ITERATOR
00057 
00058 #include<iostream>
00059 
00060 namespace DREAM
00061 {
00062 
00063 template <class item_type>
00064 class Const_Iterator;
00065 
00066 /** Iterator class for DREAM::AVLTree. */
00067 template <class item_type>
00068 class Iterator
00069 {
00070 public:
00071         /** Constructor. */
00072         Iterator () {};
00073 
00074         /** Constructor. */
00075         Iterator (item_type* node_ptr);
00076 
00077         /** Constructor. */
00078         Iterator (Iterator <item_type>& iter);
00079 
00080         /** Equivalence operator. */
00081         bool operator== (const item_type* node_ptr);
00082 
00083         /** Equivalence operator. */
00084         bool operator== (Iterator <item_type>& iter);
00085 
00086         /** Equivalence operator. */
00087         bool operator== (Const_Iterator <item_type>& iter);
00088 
00089         /** Equivalence operator. */
00090         bool operator!= (const item_type* node_ptr);
00091 
00092         /** Equivalence operator. */
00093         bool operator!= (Iterator <item_type>& iter);
00094 
00095         /** Equivalence operator. */
00096         bool operator!= (Const_Iterator <item_type>& iter);
00097 
00098         /** Assignment operator. */
00099         Iterator <item_type>& operator= (item_type* node_ptr);
00100 
00101         /** Assignment operator. */
00102         Iterator <item_type>& operator= (Iterator <item_type>& iter);
00103 
00104         /** * operator. */
00105         item_type* operator* ();
00106 
00107         /**->operator. */
00108         item_type* operator-> ();
00109 
00110         /** prefix ++ operator. */
00111         Iterator <item_type>& operator++ ();
00112 
00113         /** prefix -- operator. */
00114         Iterator <item_type>& operator-- ();
00115 
00116         /** postfix ++ operator. */
00117         Iterator <item_type> operator++ (int);
00118 
00119         /** postfix -- operator. */
00120         Iterator <item_type> operator-- (int);
00121 
00122         /** & operator. */
00123         Iterator <item_type>& operator& ();
00124 
00125         /** & operator. */
00126         Iterator <item_type>& operator& (int);
00127 
00128 protected:
00129 
00130         /** Pointer to the current node in the AVLTree. */
00131         item_type* node_ptr_;
00132 };
00133 
00134 
00135 
00136 /** Iterator class for DREAM::AVLTree. */
00137 template <class item_type>
00138 class Const_Iterator
00139 {
00140 public:
00141         /** Constructor. */
00142         Const_Iterator () {};
00143 
00144         /** Constructor. */
00145         Const_Iterator (const item_type* node_ptr);
00146 
00147         /** Constructor. */
00148         Const_Iterator (Const_Iterator <item_type>& iter);
00149 
00150         /** Constructor. */
00151         Const_Iterator (Iterator <item_type>& iter);
00152 
00153         /** Equivalence operator. */
00154         bool operator== (const item_type* node_ptr);
00155 
00156         /** Equivalence operator. */
00157         bool operator== (Const_Iterator <item_type>& iter);
00158 
00159         /** Equivalence operator. */
00160         bool operator== (Iterator <item_type>& iter);
00161 
00162         /** Equivalence operator. */
00163         bool operator!= (const item_type* node_ptr);
00164 
00165         /** Equivalence operator. */
00166         bool operator!= (Const_Iterator <item_type>& iter);
00167 
00168         /** Equivalence operator. */
00169         bool operator!= (Iterator <item_type>& iter);
00170 
00171         /** Assignment operator. */
00172         Const_Iterator <item_type>& operator= (const item_type* node_ptr);
00173 
00174         /** Assignment operator. */
00175         Const_Iterator <item_type>& operator= (Const_Iterator <item_type>& iter);
00176 
00177         /** Assignment operator. */
00178         Const_Iterator <item_type>& operator= (Iterator <item_type>& iter);
00179 
00180         /** * operator. */
00181         const item_type* operator* () const;
00182 
00183         /**->operator. */
00184         const item_type* operator-> () const;
00185 
00186         /** ++ operator. */
00187         Const_Iterator <item_type>& operator++ ();
00188 
00189         /** -- operator. */
00190         Const_Iterator <item_type>& operator-- ();
00191 
00192         /** postfix ++ operator. */
00193         Const_Iterator <item_type> operator++ (int);
00194 
00195         /** postfix -- operator. */
00196         Const_Iterator <item_type> operator-- (int);
00197 
00198         /** & operator. */
00199         Const_Iterator <item_type>& operator& ();
00200 
00201         /** & operator. */
00202         Const_Iterator <item_type>& operator& (int);
00203 
00204 protected:
00205 
00206         /** Pointer to the current node in the AVLTree. */
00207         const item_type* node_ptr_;
00208 };
00209 
00210 template <class item_type, class operation>
00211 void for_each (item_type begin_iter, item_type end_iter, operation op)
00212 {
00213         item_type iter;
00214         for (iter = begin_iter; iter != end_iter; iter++)
00215         {
00216                 op (**iter);
00217         }
00218 }
00219 
00220 };
00221 
00222 #endif

Generated on Fri Jul 27 18:30:03 2007 for DREAM by  doxygen 1.5.1