[MOAB-dev] r3300 - MOAB/trunk

kraftche at cae.wisc.edu kraftche at cae.wisc.edu
Fri Nov 6 17:39:18 CST 2009


Author: kraftche
Date: 2009-11-06 17:39:17 -0600 (Fri, 06 Nov 2009)
New Revision: 3300

Modified:
   MOAB/trunk/MBRange.cpp
   MOAB/trunk/MBRange.hpp
Log:
add operator-(iter,iter) that counts distance between MBRange iterators

Modified: MOAB/trunk/MBRange.cpp
===================================================================
--- MOAB/trunk/MBRange.cpp	2009-11-06 22:29:04 UTC (rev 3299)
+++ MOAB/trunk/MBRange.cpp	2009-11-06 23:39:17 UTC (rev 3300)
@@ -233,11 +233,11 @@
 
 MBRange::iterator MBRange::insert( MBRange::iterator hint, MBEntityHandle val )
 {
-
-  // if this is empty, just add it and return an iterator to it
+  // don't allow zero-valued handles in MBRange
   if(val == 0)
     return end();
 
+  // if this is empty, just add it and return an iterator to it
   if(&mHead == mHead.mNext)
   {
     mHead.mNext = mHead.mPrev = alloc_pair(&mHead, &mHead, val, val);
@@ -733,6 +733,24 @@
   }
 }
 
+  
+MBEntityID 
+operator-( const MBRange::const_iterator& it2, const MBRange::const_iterator& it1 )
+{
+  assert( !it2.mValue || *it2 >= *it1 );
+  if (it2.mNode == it1.mNode) {
+    return *it2 - *it1;
+  }
+
+  MBEntityID result = it1.mNode->second - it1.mValue + 1;
+  for (MBRange::PairNode* n = it1.mNode->mNext; n != it2.mNode; n = n->mNext)
+    result += n->second - n->first + 1;
+  if (it2.mValue) // (it2.mNode != &mHead)
+    result += it2.mValue - it2.mNode->first;
+  return result;
+}
+
+
 MBRange::const_iterator MBRange::lower_bound(MBRange::const_iterator first,
                                              MBRange::const_iterator last,
                                              MBEntityHandle val)

Modified: MOAB/trunk/MBRange.hpp
===================================================================
--- MOAB/trunk/MBRange.hpp	2009-11-06 22:29:04 UTC (rev 3299)
+++ MOAB/trunk/MBRange.hpp	2009-11-06 23:39:17 UTC (rev 3300)
@@ -420,6 +420,7 @@
     friend class MBRange;
     friend class pair_iterator;
     friend class const_pair_iterator;
+    friend MBEntityID operator-( const const_iterator&, const const_iterator& );
   public:
     //! default constructor - intialize base default constructor
     const_iterator() : mNode(NULL), mValue(0) {}
@@ -685,6 +686,9 @@
 inline MBRange::const_iterator 
 operator-( MBEntityID step, const MBRange::const_iterator& it )
   { MBRange::const_iterator tmp(it); return tmp -= step; }
+  
+MBEntityID 
+operator-(  const MBRange::const_iterator& it1, const MBRange::const_iterator& it2 );
 
 //! Use as you would an STL back_inserter
 /**



More information about the moab-dev mailing list