00001 /* 00002 * 00003 * Copyright (C) 2003-2010, OFFIS e.V. 00004 * All rights reserved. See COPYRIGHT file for details. 00005 * 00006 * This software and supporting documentation were developed by 00007 * 00008 * OFFIS e.V. 00009 * R&D Division Health 00010 * Escherweg 2 00011 * D-26121 Oldenburg, Germany 00012 * 00013 * 00014 * Module: ofstd 00015 * 00016 * Author: Thomas Wilkens 00017 * 00018 * Purpose: Template class which represents an iterator class for corres- 00019 * ponding set data structures in ofstd. 00020 * 00021 * Last Update: $Author: joergr $ 00022 * Update Date: $Date: 2010-10-14 13:15:50 $ 00023 * CVS/RCS Revision: $Revision: 1.4 $ 00024 * Status: $State: Exp $ 00025 * 00026 * CVS/RCS Log at end of file 00027 * 00028 */ 00029 00030 #ifndef OFSETIT_H 00031 #define OFSETIT_H 00032 00033 #include "dcmtk/config/osconfig.h" 00034 #include "dcmtk/ofstd/oftypes.h" 00035 #include "dcmtk/ofstd/ofset.h" 00036 00051 template <class T> class OFSetIterator 00052 { 00053 protected: 00055 OFSet<T> &ofset; 00057 unsigned int pos; 00058 00059 public: 00063 OFSetIterator( OFSet<T> &ofsetv ) 00064 : ofset( ofsetv ), pos( 0 ) 00065 { 00066 } 00067 00070 virtual ~OFSetIterator() 00071 { 00072 } 00073 00076 void ResetBeginning() 00077 { 00078 pos = 0; 00079 } 00080 00083 void ResetEnd() 00084 { 00085 unsigned int num = ofset.NumberOfElements(); 00086 00087 if( num == 0 ) 00088 pos = 0; 00089 else 00090 pos = num - 1; 00091 } 00092 00096 T *Object() 00097 { 00098 if( pos == ofset.NumberOfElements() ) 00099 return( NULL ); 00100 else 00101 return( &ofset[pos] ); 00102 } 00103 00106 void Next() 00107 { 00108 if( pos < ofset.NumberOfElements() ) 00109 pos++; 00110 } 00111 00114 void Prev() 00115 { 00116 unsigned int num = ofset.NumberOfElements(); 00117 00118 if( pos == 0 || pos == num ) 00119 pos = num; 00120 else 00121 pos--; 00122 } 00123 00128 OFBool operator==( const OFSetIterator<T> &other ) const 00129 { 00130 // two iterators are considered to be identical, if and only if they operate on the 00131 // exact same set (identical addresses) and they currently refer to the same element 00132 if( &ofset == &other.ofset && pos == other.pos ) 00133 return( OFTrue ); 00134 else 00135 return( OFFalse ); 00136 } 00137 00142 OFBool operator!=( const OFSetIterator<T> &other ) const 00143 { 00144 return( !( *this == other ) ); 00145 } 00146 }; 00147 00148 #endif 00149 00150 /* 00151 ** CVS/RCS Log: 00152 ** $Log: ofsetit.h,v $ 00153 ** Revision 1.4 2010-10-14 13:15:50 joergr 00154 ** Updated copyright header. Added reference to COPYRIGHT file. 00155 ** 00156 ** Revision 1.3 2010-10-05 08:36:51 joergr 00157 ** Fixed various Doxygen API documentation issues. 00158 ** 00159 ** Revision 1.2 2005/12/08 16:06:02 meichel 00160 ** Changed include path schema for all DCMTK header files 00161 ** 00162 ** Revision 1.1 2003/08/20 14:45:25 wilkens 00163 ** Added new class OFSetIterator, an iterator class for OFxxxSet data structures. 00164 ** 00165 ** 00166 */