SALOME - SMESH
SMDS_SetIterator.hxx
Go to the documentation of this file.
00001 //  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
00002 //
00003 //  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
00004 //  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
00005 //
00006 //  This library is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU Lesser General Public
00008 //  License as published by the Free Software Foundation; either
00009 //  version 2.1 of the License.
00010 //
00011 //  This library is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 //  Lesser General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU Lesser General Public
00017 //  License along with this library; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
00019 //
00020 //  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
00021 //
00022 //  SMESH SMDS : implementaion of Salome mesh data structure
00023 // File      : SMDS_SetIterator.hxx
00024 // Created   : Mon Feb 27 16:57:43 2006
00025 // Author    : Edward AGAPOV (eap)
00026 //
00027 #ifndef SMDS_SetIterator_HeaderFile
00028 #define SMDS_SetIterator_HeaderFile
00029 
00030 #include "SMDS_Iterator.hxx"
00031 
00035 
00036 namespace SMDS {
00037 
00038   template<typename VALUE,typename VALUE_SET_ITERATOR>
00039   struct SimpleAccessor {
00040     static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) *it; }
00041   };
00042 
00043   template<typename VALUE,typename VALUE_SET_ITERATOR>
00044   struct KeyAccessor {
00045     static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->first; }
00046   };
00047 
00048   template<typename VALUE,typename VALUE_SET_ITERATOR>
00049   struct ValueAccessor {
00050     static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->second; }
00051   };
00052 }
00053 
00060 
00061 template<typename VALUE,
00062          typename VALUE_SET_ITERATOR,
00063          typename ACCESOR=SMDS::SimpleAccessor<VALUE,VALUE_SET_ITERATOR> >
00064 class SMDS_SetIterator : public SMDS_Iterator<VALUE>
00065 {
00066 protected:
00067   VALUE_SET_ITERATOR _beg, _end;
00068 public:
00069   SMDS_SetIterator(const VALUE_SET_ITERATOR & begin,
00070                    const VALUE_SET_ITERATOR & end)
00071   { init ( begin, end ); }
00072 
00074   virtual void init(const VALUE_SET_ITERATOR & begin,
00075                     const VALUE_SET_ITERATOR & end)
00076   { _beg = begin; _end = end; }
00077 
00079   virtual bool more() { return _beg != _end; }
00080 
00082   virtual VALUE next() { return ACCESOR::value( _beg++ ); }
00083 };
00084 
00088 
00089 #include <map>
00093 template<typename M>
00094 struct SMDS_mapIterator : public SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator,
00095                                                    SMDS::ValueAccessor<typename M::mapped_type,
00096                                                                        typename M::const_iterator> > {
00097   typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator,
00098                             SMDS::ValueAccessor<typename M::mapped_type,
00099                                                 typename M::const_iterator> > parent_type;
00100   SMDS_mapIterator(const M& m):parent_type(m.begin(),m.end()) {}
00101 };
00105 template<typename M>
00106 struct SMDS_mapReverseIterator : public SMDS_SetIterator< typename M::mapped_type,
00107                                                           typename M::const_reverse_iterator,
00108                                                           SMDS::ValueAccessor<typename M::mapped_type,
00109                                                                               typename M::const_reverse_iterator> > {
00110   typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_reverse_iterator,
00111                             SMDS::ValueAccessor<typename M::mapped_type,
00112                                                 typename M::const_reverse_iterator> > parent_type;
00113   SMDS_mapReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {}
00114 };
00118 template<typename M>
00119 struct SMDS_mapKeyIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
00120                                                       SMDS::KeyAccessor<typename M::key_type,
00121                                                                         typename M::const_iterator> > {
00122   typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
00123                             SMDS::KeyAccessor<typename M::key_type,
00124                                               typename M::const_iterator> > parent_type;
00125   SMDS_mapKeyIterator(const M& m):parent_type(m.begin(),m.end()) {}
00126 };
00130 template<typename M>
00131 struct SMDS_mapKeyReverseIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
00132                                                             SMDS::KeyAccessor<typename M::key_type,
00133                                                                               typename M::const_iterator> > {
00134   typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
00135                             SMDS::KeyAccessor<typename M::key_type,
00136                                               typename M::const_iterator> > parent_type;
00137   SMDS_mapKeyReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {}
00138 };
00139 
00141 // useful specifications
00143 
00144 #include <vector>
00145 
00146 class SMDS_MeshElement;
00147 class SMDS_MeshNode;
00148 
00149 typedef const SMDS_MeshElement* SMDS_pElement;
00150 typedef const SMDS_MeshNode*    SMDS_pNode;
00151 
00152 // element iterators
00153 
00154 typedef SMDS_SetIterator< SMDS_pElement, std::vector< SMDS_pElement >::const_iterator>
00155 SMDS_ElementVectorIterator;
00156 
00157 
00158 typedef SMDS_SetIterator< SMDS_pElement, SMDS_pElement const *>
00159 SMDS_ElementArrayIterator;
00160 
00161 
00162 typedef SMDS_SetIterator< SMDS_pElement, std::vector< SMDS_pNode >::const_iterator>
00163 SMDS_NodeVectorElemIterator;
00164 
00165 
00166 typedef SMDS_SetIterator< SMDS_pElement, SMDS_pNode const * >
00167 SMDS_NodeArrayElemIterator;
00168 
00169 // node iterators
00170 
00171 typedef SMDS_SetIterator< SMDS_pNode, std::vector< SMDS_pNode >::const_iterator >
00172 SMDS_NodeVectorIterator;
00173 
00174 
00175 typedef SMDS_SetIterator< SMDS_pNode, SMDS_pNode const * >
00176 SMDS_NodeArrayIterator;
00177 
00178 
00179 #endif