+/*!
+ * Template class used for iteration on vector of elements which can resize
+ * during iteration. The iterator returns only elements present upon its creation.
+ */
+template <class ELEM, typename TSET> class MySetIterator : public SMDS_Iterator<ELEM>
+{
+protected:
+ int _iCur, _iEnd, _iDelta;
+ const TSET& _table;
+public:
+ MySetIterator(const TSET& table, bool reverse): _table( table )
+ {
+ if ( reverse )
+ {
+ _iCur = _table.size()-1;
+ _iEnd = -1;
+ _iDelta = -1;
+ }
+ else
+ {
+ _iCur = 0;
+ _iEnd = _table.size();
+ _iDelta = 1;
+ }
+ if ( more() && !_table[ _iCur ])
+ next();
+ }
+
+ virtual bool more()
+ {
+ return ( _iEnd - _iCur ) * _iDelta > 0;
+ }
+
+ virtual ELEM next()
+ {
+ ELEM e = more() ? _table[ _iCur ] : 0;
+ _iCur += _iDelta;
+ while ( more() && !_table[ _iCur ])
+ _iCur += _iDelta;
+ return e;
+ }
+};
+
+// =====================
+// class MyIterator
+// =====================
+
+template<typename VALUE> class MyIterator : public SMDS_Iterator<VALUE>
+{
+public:
+ MyIterator (const TSubMeshSet& theSubMeshes)
+ : myMore(false), mySubIt( theSubMeshes.begin() ), mySubEnd( theSubMeshes.end() )
+ {}
+ bool more()
+ {
+ while (( !myElemIt.get() || !myElemIt->more() ) && mySubIt != mySubEnd)
+ {
+ myElemIt = getElements(*mySubIt);
+ mySubIt++;
+ }
+ myMore = myElemIt.get() && myElemIt->more();
+ return myMore;
+ }
+ VALUE next()
+ {
+ VALUE elem = 0;
+ if ( myMore )
+ elem = myElemIt->next();
+ return elem;
+ }
+protected:
+ virtual boost::shared_ptr< SMDS_Iterator<VALUE> >
+ getElements(const SMESHDS_SubMesh*) const = 0;
+
+private:
+ bool myMore;
+ TSubMeshSet::const_iterator mySubIt, mySubEnd;
+ boost::shared_ptr< SMDS_Iterator<VALUE> > myElemIt;
+};
+
+// =====================
+// class MyElemIterator
+// =====================
+
+class MyElemIterator: public MyIterator<const SMDS_MeshElement*>
+{
+public:
+ MyElemIterator (const TSubMeshSet& theSubMeshes)
+ :MyIterator<const SMDS_MeshElement*>( theSubMeshes ) {}
+ SMDS_ElemIteratorPtr getElements(const SMESHDS_SubMesh* theSubMesh) const
+ { return theSubMesh->GetElements(); }
+};
+
+// =====================
+// class MyNodeIterator
+// =====================
+
+class MyNodeIterator: public MyIterator<const SMDS_MeshNode*>
+{
+public:
+ MyNodeIterator (const TSubMeshSet& theSubMeshes)
+ :MyIterator<const SMDS_MeshNode*>( theSubMeshes ) {}
+ SMDS_NodeIteratorPtr getElements(const SMESHDS_SubMesh* theSubMesh) const
+ { return theSubMesh->GetNodes(); }
+};
+