Iterator.cpp

Go to the documentation of this file.
00001 /** @file Iterator.cpp
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 #ifndef DREAM_ITERATORCPP
00052 #define DREAM_ITERATORCPP
00053 
00054 #include "Iterator.h"
00055 
00056 namespace DREAM
00057 {
00058 
00059 /////////////////////////////////////////////////////////////////////////////
00060 //
00061 // Iterator
00062 //
00063 /////////////////////////////////////////////////////////////////////////////
00064 
00065 template <class item_type>
00066 Iterator <item_type>::Iterator (item_type* node_ptr)
00067 : node_ptr_ (node_ptr) 
00068 {
00069 };
00070 
00071 template <class item_type>
00072 Iterator <item_type>::Iterator (Iterator <item_type>& iter)
00073 : node_ptr_ (*iter)
00074 {
00075 }
00076 
00077 template <class item_type>
00078 inline bool Iterator <item_type>::operator== (const item_type* node_ptr)
00079 {
00080         return (node_ptr_ == node_ptr) ? true : false;
00081 }
00082 
00083 template <class item_type>
00084 inline bool Iterator <item_type>::operator== (Iterator <item_type>& iter)
00085 {
00086         return (node_ptr_ == *iter) ? true : false;
00087 }
00088 
00089 template <class item_type>
00090 inline bool Iterator <item_type>::operator== (Const_Iterator <item_type>& iter)
00091 {
00092         return (node_ptr_ == *iter) ? true : false;
00093 }
00094 
00095 template <class item_type>
00096 inline bool Iterator <item_type>::operator!= (const item_type* node_ptr)
00097 {
00098         return (node_ptr_ == node_ptr) ? false : true;
00099 }
00100 
00101 template <class item_type>
00102 inline bool Iterator <item_type>::operator!= (Iterator <item_type>& iter)
00103 {
00104         return (node_ptr_ == *iter) ? false : true;
00105 }
00106 
00107 template <class item_type>
00108 inline bool Iterator <item_type>::operator!= (Const_Iterator <item_type>& iter)
00109 {
00110         return (node_ptr_ == *iter) ? false : true;
00111 }
00112 
00113 template <class item_type>
00114 inline Iterator <item_type>& Iterator <item_type>::operator= (item_type* node_ptr)
00115 {
00116         node_ptr_ = node_ptr;
00117         return *this;
00118 }
00119 
00120 template <class item_type>
00121 inline Iterator <item_type>& Iterator <item_type>::operator= (Iterator <item_type>& iter)
00122 {
00123         node_ptr_ = *iter;
00124         return *this;
00125 }
00126 
00127 template <class item_type>
00128 inline item_type* Iterator <item_type>::operator* ()
00129 {
00130         return node_ptr_;
00131 }
00132 
00133 template <class item_type>
00134 inline item_type* Iterator <item_type>::operator-> ()
00135 {
00136         return node_ptr_;
00137 }
00138 
00139 template <class item_type>
00140 inline Iterator <item_type>& Iterator <item_type>::operator++ ()
00141 {
00142         if (node_ptr_)
00143         {
00144                 node_ptr_ = node_ptr_->iter_next ();
00145                 return *this;
00146         }
00147         else
00148                 return *this;
00149 }
00150 
00151 template <class item_type>
00152 inline Iterator <item_type>& Iterator <item_type>::operator-- ()
00153 {
00154         if (node_ptr_)
00155         {
00156                 node_ptr_ = node_ptr_->iter_previous ();
00157                 return *this;
00158         }
00159         else
00160                 return *this;
00161 }
00162 
00163 template <class item_type>
00164 Iterator <item_type> Iterator <item_type>::operator++ (int)
00165 {
00166         if (node_ptr_)
00167         {
00168                 item_type* return_pointer = node_ptr_;
00169                 node_ptr_ = node_ptr_->iter_next ();
00170                 // Need to create a temporary Iterator because the g++ compiler cannot figure out that it needs to call the constructor when we return the pointer...
00171                 Iterator <item_type> return_iterator (return_pointer);
00172                 return return_iterator;
00173         }
00174         else
00175                 return *this;
00176 }
00177 
00178 template <class item_type>
00179 Iterator <item_type> Iterator <item_type>::operator-- (int)
00180 {
00181         if (node_ptr_)
00182         {
00183                 item_type* return_pointer = node_ptr_;
00184                 node_ptr_ = node_ptr_->iter_previous ();
00185                 // Need to create a temporary Iterator because the g++ compiler cannot figure out that it needs to call the constructor when we return the pointer...
00186                 Iterator <item_type> return_iterator (return_pointer);
00187                 return return_iterator;
00188         }
00189         else
00190                 return *this;
00191 }
00192 
00193 template <class item_type>
00194 inline Iterator <item_type>& Iterator <item_type>::operator& ()
00195 {
00196         return this;
00197 }
00198 
00199 template <class item_type>
00200 inline Iterator <item_type>& Iterator <item_type>::operator& (int)
00201 {
00202         return this;
00203 }
00204 
00205 /////////////////////////////////////////////////////////////////////////////
00206 //
00207 // Const_Iterator
00208 //
00209 /////////////////////////////////////////////////////////////////////////////
00210 
00211 template <class item_type>
00212 Const_Iterator <item_type>::Const_Iterator (const item_type* node_ptr)
00213 : node_ptr_ (node_ptr) 
00214 {
00215 };
00216 
00217 template <class item_type>
00218 Const_Iterator <item_type>::Const_Iterator (Const_Iterator <item_type>& iter)
00219 : node_ptr_ (*iter)
00220 {
00221 }
00222 
00223 template <class item_type>
00224 Const_Iterator <item_type>::Const_Iterator (Iterator <item_type>& iter)
00225 : node_ptr_ (*iter)
00226 {
00227 }
00228 
00229 template <class item_type>
00230 inline bool Const_Iterator <item_type>::operator== (const item_type* node_ptr)
00231 {
00232         return (node_ptr_ == node_ptr) ? true : false;
00233 }
00234 
00235 template <class item_type>
00236 inline bool Const_Iterator <item_type>::operator== (Const_Iterator <item_type>& iter)
00237 {
00238         return (node_ptr_ == *iter) ? true : false;
00239 }
00240 
00241 template <class item_type>
00242 inline bool Const_Iterator <item_type>::operator== (Iterator <item_type>& iter)
00243 {
00244         return (node_ptr_ == *iter) ? true : false;
00245 }
00246 
00247 template <class item_type>
00248 inline bool Const_Iterator <item_type>::operator!= (const item_type* node_ptr)
00249 {
00250         return (node_ptr_ == node_ptr) ? false : true;
00251 }
00252 
00253 template <class item_type>
00254 inline bool Const_Iterator <item_type>::operator!= (Const_Iterator <item_type>& iter)
00255 {
00256         return (node_ptr_ == *iter) ? false : true;
00257 }
00258 
00259 template <class item_type>
00260 inline bool Const_Iterator <item_type>::operator!= (Iterator <item_type>& iter)
00261 {
00262         return (node_ptr_ == *iter) ? false : true;
00263 }
00264 
00265 template <class item_type>
00266 inline Const_Iterator <item_type>& Const_Iterator <item_type>::operator= (const item_type* node_ptr)
00267 {
00268         node_ptr_ = node_ptr;
00269         return *this;
00270 }
00271 
00272 template <class item_type>
00273 inline Const_Iterator <item_type>& Const_Iterator <item_type>::operator= (Const_Iterator <item_type>& iter)
00274 {
00275         node_ptr_ = *iter;
00276         return *this;
00277 }
00278 
00279 template <class item_type>
00280 inline Const_Iterator <item_type>& Const_Iterator <item_type>::operator= (Iterator <item_type>& iter)
00281 {
00282         node_ptr_ = *iter;
00283         return *this;
00284 }
00285 
00286 template <class item_type>
00287 inline const item_type* Const_Iterator <item_type>::operator* () const
00288 {
00289         return node_ptr_;
00290 }
00291 
00292 template <class item_type>
00293 inline const item_type* Const_Iterator <item_type>::operator-> () const
00294 {
00295         return node_ptr_;
00296 }
00297 
00298 template <class item_type>
00299 inline Const_Iterator <item_type>& Const_Iterator <item_type>::operator++ ()
00300 {
00301         if (node_ptr_)
00302         {
00303                 node_ptr_ = node_ptr_->iter_next ();
00304                 return *this;
00305         }
00306         else
00307                 return *this;
00308 }
00309 
00310 template <class item_type>
00311 inline Const_Iterator <item_type>& Const_Iterator <item_type>::operator-- ()
00312 {
00313         if (node_ptr_)
00314         {
00315                 node_ptr_ = node_ptr_->iter_previous ();
00316                 return *this;
00317         }
00318         else
00319                 return *this;
00320 }
00321 
00322 template <class item_type>
00323 Const_Iterator <item_type> Const_Iterator <item_type>::operator++ (int)
00324 {
00325         if (node_ptr_)
00326         {
00327                 const item_type* return_pointer = node_ptr_;
00328                 node_ptr_ = node_ptr_->iter_next ();
00329                 // Need to create a temporary Const_Iterator because the g++ compiler cannot figure out that it needs to call the constructor when we return the pointer...
00330                 Const_Iterator <item_type> return_iterator (return_pointer);
00331                 return return_iterator;
00332         }
00333         else
00334                 return *this;
00335 }
00336 
00337 template <class item_type>
00338 Const_Iterator <item_type> Const_Iterator <item_type>::operator-- (int)
00339 {
00340         if (node_ptr_ == NULL)
00341         {
00342                 const item_type* return_pointer = node_ptr_;
00343                 node_ptr_ = node_ptr_->iter_previous ();
00344                 // Need to create a temporary Const_Iterator because the g++ compiler cannot figure out that it needs to call the constructor when we return the pointer...
00345                 Const_Iterator <item_type> return_iterator (return_pointer);
00346                 return return_iterator;
00347         }
00348         else
00349                 return *this;
00350 }
00351 
00352 template <class item_type>
00353 inline Const_Iterator <item_type>& Const_Iterator <item_type>::operator& ()
00354 {
00355         return this;
00356 }
00357 
00358 template <class item_type>
00359 inline Const_Iterator <item_type>& Const_Iterator <item_type>::operator& (int)
00360 {
00361         return this;
00362 }
00363 
00364 };
00365 
00366 #endif

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