Salome HOME
Add iterator, wrapper over SMDS_Iterator, adding std-like operators *, ++ etc
authoreap <eap@opencascade.com>
Tue, 9 Feb 2010 11:02:53 +0000 (11:02 +0000)
committereap <eap@opencascade.com>
Tue, 9 Feb 2010 11:02:53 +0000 (11:02 +0000)
+ SMDS_StdIterator.hxx

src/SMDS/Makefile.am
src/SMDS/SMDS_StdIterator.hxx [new file with mode: 0644]

index 7f409877e4de91e07af1ac55f1ef86e24f814e0e..44cc174f2615fd6618e583998ffc934a6dae9420 100644 (file)
@@ -62,7 +62,8 @@ salomeinclude_HEADERS = \
        SMDS_QuadraticVolumeOfNodes.hxx \
        SMDS_SetIterator.hxx \
        SMESH_SMDS.hxx \
-       SMDS_MeshInfo.hxx
+       SMDS_MeshInfo.hxx \
+       SMDS_StdIterator.hxx
 
 
 # Libraries targets
diff --git a/src/SMDS/SMDS_StdIterator.hxx b/src/SMDS/SMDS_StdIterator.hxx
new file mode 100644 (file)
index 0000000..97c4ae9
--- /dev/null
@@ -0,0 +1,74 @@
+//  Copyright (C) 2007-2008  CEA/DEN, EDF R&D, OPEN CASCADE
+//
+//  Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
+//  CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
+//
+//  This library is free software; you can redistribute it and/or
+//  modify it under the terms of the GNU Lesser General Public
+//  License as published by the Free Software Foundation; either
+//  version 2.1 of the License.
+//
+//  This library is distributed in the hope that it will be useful,
+//  but WITHOUT ANY WARRANTY; without even the implied warranty of
+//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+//  Lesser General Public License for more details.
+//
+//  You should have received a copy of the GNU Lesser General Public
+//  License along with this library; if not, write to the Free Software
+//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+//  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
+//
+//  SMESH SMDS : implementaion of Salome mesh data structure
+//
+// File      : SMDS_StdIterator.hxx
+// Created   : Fri Feb  5 11:03:46 2010
+// Author    : Edward AGAPOV (eap)
+
+
+#ifndef __SMDS_StdIterator_HXX__
+#define __SMDS_StdIterator_HXX__
+
+
+///////////////////////////////////////////////////////////////////////////////
+/*!
+ * \brief Wrapper over pointer to SMDS_Iterator, like SMDS_ElemIteratorPtr, enabling
+ *   its usage in std-like way: provide operators ++, *,  etc.
+ */
+///////////////////////////////////////////////////////////////////////////////
+
+template<typename VALUE, class PtrSMDSIterator, class EqualVALUE = std::equal_to<VALUE> >
+class SMDS_StdIterator : public std::iterator< std::input_iterator_tag, VALUE >
+{
+  VALUE           _value;
+  PtrSMDSIterator _piterator;
+  EqualVALUE      _EqualVALUE;
+
+public:
+  typedef SMDS_StdIterator<VALUE, PtrSMDSIterator> _Self;
+
+  // constructor to use as return from begin()
+  SMDS_StdIterator( PtrSMDSIterator pItr )
+    : _value( pItr->more() ? (VALUE)(pItr->next()) : 0 ), _piterator(pItr)
+  {}
+  // constructor to use as return from end()
+  SMDS_StdIterator(): _value( 0 )
+  {}
+
+  /// Return the current object
+  VALUE operator*() const
+  { return _value; }
+
+  //  Step to the next one
+  _Self&
+  operator++()
+  { _value = _piterator->more() ? VALUE( _piterator->next()) : 0; return *this; }
+
+  // Test of end
+  bool
+  operator!=(const _Self& __x) const
+  { return !_EqualVALUE( _value, __x._value); }
+
+};
+
+#endif