Back to index

salome-smesh  6.5.0
SMDS_SetIterator.hxx
Go to the documentation of this file.
00001 // Copyright (C) 2007-2012  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 
00023 //  SMESH SMDS : implementaion of Salome mesh data structure
00024 // File      : SMDS_SetIterator.hxx
00025 // Created   : Mon Feb 27 16:57:43 2006
00026 // Author    : Edward AGAPOV (eap)
00027 //
00028 #ifndef SMDS_SetIterator_HeaderFile
00029 #define SMDS_SetIterator_HeaderFile
00030 
00031 #include "SMDS_Iterator.hxx"
00032 
00036 
00037 namespace SMDS {
00038 
00039   template<typename VALUE,typename VALUE_SET_ITERATOR>
00040   struct SimpleAccessor {
00041     static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) *it; }
00042   };
00043 
00044   template<typename VALUE,typename VALUE_SET_ITERATOR>
00045   struct KeyAccessor {
00046     static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->first; }
00047   };
00048 
00049   template<typename VALUE,typename VALUE_SET_ITERATOR>
00050   struct ValueAccessor {
00051     static VALUE value(VALUE_SET_ITERATOR it) { return (VALUE) it->second; }
00052   };
00053 }
00054 
00061 
00062 template<typename VALUE,
00063          typename VALUE_SET_ITERATOR,
00064          typename ACCESOR=SMDS::SimpleAccessor<VALUE,VALUE_SET_ITERATOR> >
00065 class SMDS_SetIterator : public SMDS_Iterator<VALUE>
00066 {
00067 protected:
00068   VALUE_SET_ITERATOR _beg, _end;
00069 public:
00070   SMDS_SetIterator(const VALUE_SET_ITERATOR & begin,
00071                    const VALUE_SET_ITERATOR & end)
00072   { init ( begin, end ); }
00073 
00075   virtual void init(const VALUE_SET_ITERATOR & begin,
00076                     const VALUE_SET_ITERATOR & end)
00077   { _beg = begin; _end = end; }
00078 
00080   virtual bool more() { return _beg != _end; }
00081 
00083   virtual VALUE next() { return ACCESOR::value( _beg++ ); }
00084 };
00085 
00089 
00090 #include <map>
00094 template<typename M>
00095 struct SMDS_mapIterator : public SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator,
00096                                                    SMDS::ValueAccessor<typename M::mapped_type,
00097                                                                        typename M::const_iterator> > {
00098   typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_iterator,
00099                             SMDS::ValueAccessor<typename M::mapped_type,
00100                                                 typename M::const_iterator> > parent_type;
00101   SMDS_mapIterator(const M& m):parent_type(m.begin(),m.end()) {}
00102 };
00106 template<typename M>
00107 struct SMDS_mapReverseIterator : public SMDS_SetIterator< typename M::mapped_type,
00108                                                           typename M::const_reverse_iterator,
00109                                                           SMDS::ValueAccessor<typename M::mapped_type,
00110                                                                               typename M::const_reverse_iterator> > {
00111   typedef SMDS_SetIterator< typename M::mapped_type, typename M::const_reverse_iterator,
00112                             SMDS::ValueAccessor<typename M::mapped_type,
00113                                                 typename M::const_reverse_iterator> > parent_type;
00114   SMDS_mapReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {}
00115 };
00119 template<typename M>
00120 struct SMDS_mapKeyIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
00121                                                       SMDS::KeyAccessor<typename M::key_type,
00122                                                                         typename M::const_iterator> > {
00123   typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
00124                             SMDS::KeyAccessor<typename M::key_type,
00125                                               typename M::const_iterator> > parent_type;
00126   SMDS_mapKeyIterator(const M& m):parent_type(m.begin(),m.end()) {}
00127 };
00131 template<typename M>
00132 struct SMDS_mapKeyReverseIterator : public SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
00133                                                             SMDS::KeyAccessor<typename M::key_type,
00134                                                                               typename M::const_iterator> > {
00135   typedef SMDS_SetIterator< typename M::key_type, typename M::const_iterator,
00136                             SMDS::KeyAccessor<typename M::key_type,
00137                                               typename M::const_iterator> > parent_type;
00138   SMDS_mapKeyReverseIterator(const M& m):parent_type(m.rbegin(),m.rend()) {}
00139 };
00140 
00142 // useful specifications
00144 
00145 #include <vector>
00146 
00147 class SMDS_MeshElement;
00148 class SMDS_MeshNode;
00149 
00150 typedef const SMDS_MeshElement* SMDS_pElement;
00151 typedef const SMDS_MeshNode*    SMDS_pNode;
00152 
00153 // element iterators
00154 
00155 typedef SMDS_SetIterator< SMDS_pElement, std::vector< SMDS_pElement >::const_iterator>
00156 SMDS_ElementVectorIterator;
00157 
00158 
00159 typedef SMDS_SetIterator< SMDS_pElement, SMDS_pElement const *>
00160 SMDS_ElementArrayIterator;
00161 
00162 
00163 typedef SMDS_SetIterator< SMDS_pElement, std::vector< SMDS_pNode >::const_iterator>
00164 SMDS_NodeVectorElemIterator;
00165 
00166 
00167 typedef SMDS_SetIterator< SMDS_pElement, SMDS_pNode const * >
00168 SMDS_NodeArrayElemIterator;
00169 
00170 // node iterators
00171 
00172 typedef SMDS_SetIterator< SMDS_pNode, std::vector< SMDS_pNode >::const_iterator >
00173 SMDS_NodeVectorIterator;
00174 
00175 
00176 typedef SMDS_SetIterator< SMDS_pNode, SMDS_pNode const * >
00177 SMDS_NodeArrayIterator;
00178 
00179 
00180 #endif