Changeset 3300

Show
Ignore:
Timestamp:
11/06/09 17:39:17 (2 weeks ago)
Author:
kraftche
Message:

add operator-(iter,iter) that counts distance between MBRange iterators

Location:
MOAB/trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • MOAB/trunk/MBRange.cpp

    r3297 r3300  
    234234MBRange::iterator MBRange::insert( MBRange::iterator hint, MBEntityHandle val ) 
    235235{ 
    236  
    237   // if this is empty, just add it and return an iterator to it 
     236  // don't allow zero-valued handles in MBRange 
    238237  if(val == 0) 
    239238    return end(); 
    240239 
     240  // if this is empty, just add it and return an iterator to it 
    241241  if(&mHead == mHead.mNext) 
    242242  { 
     
    734734} 
    735735 
     736   
     737MBEntityID  
     738operator-( const MBRange::const_iterator& it2, const MBRange::const_iterator& it1 ) 
     739{ 
     740  assert( !it2.mValue || *it2 >= *it1 ); 
     741  if (it2.mNode == it1.mNode) { 
     742    return *it2 - *it1; 
     743  } 
     744 
     745  MBEntityID result = it1.mNode->second - it1.mValue + 1; 
     746  for (MBRange::PairNode* n = it1.mNode->mNext; n != it2.mNode; n = n->mNext) 
     747    result += n->second - n->first + 1; 
     748  if (it2.mValue) // (it2.mNode != &mHead) 
     749    result += it2.mValue - it2.mNode->first; 
     750  return result; 
     751} 
     752 
     753 
    736754MBRange::const_iterator MBRange::lower_bound(MBRange::const_iterator first, 
    737755                                             MBRange::const_iterator last, 
  • MOAB/trunk/MBRange.hpp

    r3297 r3300  
    421421    friend class pair_iterator; 
    422422    friend class const_pair_iterator; 
     423    friend MBEntityID operator-( const const_iterator&, const const_iterator& ); 
    423424  public: 
    424425    //! default constructor - intialize base default constructor 
     
    686687operator-( MBEntityID step, const MBRange::const_iterator& it ) 
    687688  { MBRange::const_iterator tmp(it); return tmp -= step; } 
     689   
     690MBEntityID  
     691operator-(  const MBRange::const_iterator& it1, const MBRange::const_iterator& it2 ); 
    688692 
    689693//! Use as you would an STL back_inserter