ofsetit.h

00001 /*
00002  *
00003  *  Copyright (C) 2003-2005, OFFIS
00004  *
00005  *  This software and supporting documentation were developed by
00006  *
00007  *    Kuratorium OFFIS e.V.
00008  *    Healthcare Information and Communication Systems
00009  *    Escherweg 2
00010  *    D-26121 Oldenburg, Germany
00011  *
00012  *  THIS SOFTWARE IS MADE AVAILABLE,  AS IS,  AND OFFIS MAKES NO  WARRANTY
00013  *  REGARDING  THE  SOFTWARE,  ITS  PERFORMANCE,  ITS  MERCHANTABILITY  OR
00014  *  FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES  OR
00015  *  ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY AND
00016  *  PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
00017  *
00018  *  Module:  ofstd
00019  *
00020  *  Author:  Thomas Wilkens
00021  *
00022  *  Purpose: Template class which represents an iterator class for corres-
00023  *           ponding set data structures in ofstd.
00024  *
00025  *  Last Update:      $Author: meichel $
00026  *  Update Date:      $Date: 2005/12/08 16:06:02 $
00027  *  Source File:      $Source: /share/dicom/cvs-depot/dcmtk/ofstd/include/dcmtk/ofstd/ofsetit.h,v $
00028  *  CVS/RCS Revision: $Revision: 1.2 $
00029  *  Status:           $State: Exp $
00030  *
00031  *  CVS/RCS Log at end of file
00032  *
00033  */
00034 
00035 #ifndef OFSetIterator_h
00036 #define OFSetIterator_h
00037 
00038 #include "dcmtk/config/osconfig.h"
00039 #include "dcmtk/ofstd/oftypes.h"
00040 #include "dcmtk/ofstd/ofset.h"
00041 
00056 template <class T> class OFSetIterator
00057 {
00058   protected:
00059     OFSet<T> &ofset;
00060     unsigned int pos;
00061 
00062   public:
00066     OFSetIterator( OFSet<T> &ofsetv )
00067         : ofset( ofsetv ), pos( 0 )
00068       {
00069       }
00070 
00073     virtual ~OFSetIterator()
00074       {
00075       }
00076 
00079     void ResetBeginning()
00080       {
00081         pos = 0;
00082       }
00083 
00086     void ResetEnd()
00087       {
00088         unsigned int num = ofset.NumberOfElements();
00089 
00090         if( num == 0 )
00091           pos = 0;
00092         else
00093           pos = num - 1;
00094       }
00095 
00099     T *Object()
00100       {
00101         if( pos == ofset.NumberOfElements() )
00102           return( NULL );
00103         else
00104           return( &ofset[pos] );
00105       }
00106 
00109     void Next()
00110       {
00111         if( pos < ofset.NumberOfElements() )
00112           pos++;
00113       }
00114 
00117     void Prev()
00118       {
00119         unsigned int num = ofset.NumberOfElements();
00120 
00121         if( pos == 0 || pos == num )
00122           pos = num;
00123         else
00124           pos--;
00125       }
00126 
00131     OFBool operator==( const OFSetIterator<T> &other ) const
00132       {
00133         // two iterators are considered to be identical, if and only if they operate on the
00134         // exact same set (identical addresses) and they currently refer to the same element
00135         if( &ofset == &other.ofset && pos == other.pos )
00136           return( OFTrue );
00137         else
00138           return( OFFalse );
00139       }
00140 
00145     OFBool operator!=( const OFSetIterator<T> &other ) const
00146       {
00147         return( !( *this == other ) );
00148       }
00149 };
00150 
00151 #endif
00152 
00153 /*
00154 ** CVS/RCS Log:
00155 ** $Log: ofsetit.h,v $
00156 ** Revision 1.2  2005/12/08 16:06:02  meichel
00157 ** Changed include path schema for all DCMTK header files
00158 **
00159 ** Revision 1.1  2003/08/20 14:45:25  wilkens
00160 ** Added new class OFSetIterator, an iterator class for OFxxxSet data structures.
00161 **
00162 **
00163 **
00164 */


Generated on 20 Dec 2005 for OFFIS DCMTK Version 3.5.4 by Doxygen 1.4.5