Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members  

iterator.hh

00001 /*
00002 *  Name:         iterator.hh
00003 *  Author:       Francisco Vides Fernandez
00004 *  Contributor:  Rafael Jesus Alcantara Perez
00005 *  Summary:      Definition of a general iterator template
00006 *  Date:         $Date: 2003/10/06 13:21:35 $
00007 *  Revision:     $Revision: 1.1 $
00008 *
00009 *  Copyright (C) 2000-2001  Francisco Vides Fernandez <pax@dedalo-ing.com>
00010 *
00011 *  This program is free software; you can redistribute it and/or modify
00012 *  it under the terms of the GNU General Public License as published by
00013 *  the Free Software Foundation; either version 2 of the License, or
00014 *  (at your option) any later version.
00015 *
00016 *  This program is distributed in the hope that it will be useful,
00017 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019 *  GNU General Public License for more details.
00020 *
00021 *  You should have received a copy of the GNU General Public License
00022 *  along with this program; if not, write to the Free Software
00023 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
00024 *  MA 02111-1307, USA.
00025 */
00026 
00027 #ifndef _UESQL_ITERATOR__
00028 #define _UESQL_ITERATOR__
00029 
00030 #include <cstdio>
00031 #include <iterator>
00032 #include <mpcl/exceptions.hh>
00033 
00034 
00036 namespace uesqlc
00037 {
00038 
00039   template <typename TMyQuery>
00040   class TIterator :
00041     public std::iterator <std::input_iterator_tag, typename TMyQuery::value_type>
00042   {
00043 
00044     public:
00045       
00046       typedef
00047         typename std::iterator <std::input_iterator_tag, typename TMyQuery::value_type>::iterator_category 
00048         iterator_category;
00049       
00050       typedef
00051         typename std::iterator <std::input_iterator_tag, typename TMyQuery::value_type>::value_type
00052         value_type;
00053 
00054       typedef
00055         typename std::iterator <std::input_iterator_tag, typename TMyQuery::value_type>::difference_type
00056         difference_type;
00057 
00058       typedef
00059         typename std::iterator <std::input_iterator_tag, typename TMyQuery::value_type>::pointer
00060         pointer;
00061 
00062       typedef
00063         typename std::iterator <std::input_iterator_tag, typename TMyQuery::value_type>::reference
00064         reference;
00065       
00066 
00067     protected:
00068       
00070       long int   liCurrent;
00071 
00072       TMyQuery*   ptQuery;
00073 
00074 
00075     private:
00076       
00078       TIterator (void)   :
00079         liCurrent (0)    , 
00080         ptQuery   (NULL) {}
00081 
00082 
00083     public:
00084 
00085       //
00086       //  C O N S T R U C T O R S
00087       //
00088 
00089       TIterator (const TIterator& rktIterator) :
00090         liCurrent (rktIterator.liCurrent)      , 
00091         ptQuery   (rktIterator.ptQuery)        {}
00092 
00093       TIterator (TMyQuery* ptQUERY) :
00094         liCurrent (0)               ,
00095         ptQuery   (ptQUERY)         {}
00096       
00097       TIterator& operator = (const TIterator& rktITERATOR)
00098       {
00099         liCurrent = rktITERATOR.liCurrent;
00100         ptQuery   = rktITERATOR.ptQuery;
00101         return *this;
00102       }
00103 
00104       TIterator& operator ++ (void)
00105       {
00106         liCurrent++;
00107         return *this;
00108       }
00109 
00110       TIterator operator ++ (int)
00111       {
00112         TIterator   tRet (*this);
00113 
00114         liCurrent++;
00115         return tRet;
00116       }
00117 
00118       std::size_t operator - (const TIterator& rktITERATOR) const
00119       {
00120         std::size_t   tRet;
00121         if ( liCurrent >= rktITERATOR.liCurrent )
00122         {
00123           tRet = liCurrent - rktITERATOR.liCurrent;
00124         }
00125         else
00126         {
00127           throw mpcl::TExceptionEL_Constraint ( "size constraint error in TIterator::operator - " ,
00128                                                 __FILE__                                          ,
00129                                                 __LINE__                                          );
00130         }
00131         return tRet; 
00132       }
00133 
00134       void setPastTheEnd (void)
00135       {
00136         liCurrent = ptQuery->size();
00137       }
00138 
00139 
00140     public:
00141 
00142       //
00143       //  S E L E C T O R S
00144       //
00145       
00146       bool isPastTheEnd (void) const
00147       {
00148         return liCurrent >= (long int) ptQuery->size();
00149       }
00150 
00151       bool operator == (const TIterator& rktITERATOR) const
00152       {
00153         bool   gRet = false;
00154 
00155         if ( ( isPastTheEnd() && rktITERATOR.isPastTheEnd() ) ||
00156              ( liCurrent == rktITERATOR.liCurrent )            )
00157         {
00158           gRet = true;
00159         }
00160         return gRet;
00161       }
00162 
00163       bool operator != (const TIterator& rktITERATOR) const
00164       {
00165         return !( operator == (rktITERATOR) );
00166       }
00167 
00168       pointer  operator -> () const
00169       {
00170         return &(operator*());
00171       }
00172 
00173       reference operator * (void) const
00174       {
00175         return (*ptQuery) [liCurrent];
00176       }
00177 
00178   };  // class TIterator
00179 
00180 }  // namespace uesqlc
00181 
00182 
00183 #endif  // _UESQL_ITERATOR__

Generated on Mon Oct 13 02:40:10 2003 for UESQLC by doxygen1.2.18