moab
moab::RangeSetIterator Class Reference

#include <SetIterator.hpp>

Inheritance diagram for moab::RangeSetIterator:
moab::SetIterator

List of all members.

Public Member Functions

virtual ~RangeSetIterator ()
 Destructor.
virtual ErrorCode get_next_arr (std::vector< EntityHandle > &arr, bool &atend)
 get the next chunkSize entities Return the next chunkSize entities.
virtual ErrorCode reset ()
 reset the iterator to the beginning of the set

Protected Member Functions

 RangeSetIterator (Core *core, EntityHandle ent_set, int chunk_size, EntityType ent_type, int ent_dimension, bool check_valid=false)
 Constructor.

Private Member Functions

ErrorCode get_next_by_type (const EntityHandle *&ptr, int count, std::vector< EntityHandle > &arr, bool &atend)
ErrorCode get_next_by_dimension (const EntityHandle *&ptr, int count, std::vector< EntityHandle > &arr, bool &atend)
ErrorCode build_pair_vec ()
 Build the special pair vector for the root set.

Private Attributes

EntityHandle iterPos
 Current iterator position, 0 if at beginning.
EntityHandlepairPtr
 Special range pair ptr for root set.
int numPairs
 Number of range pairs.

Friends

class Core

Detailed Description

Definition at line 82 of file SetIterator.hpp.


Constructor & Destructor Documentation

Destructor.

Definition at line 36 of file SetIterator.cpp.

{
  if (pairPtr) delete [] pairPtr;
  numPairs = 0;
}
moab::RangeSetIterator::RangeSetIterator ( Core core,
EntityHandle  ent_set,
int  chunk_size,
EntityType  ent_type,
int  ent_dimension,
bool  check_valid = false 
) [protected]

Constructor.

Parameters:
coreMOAB Core instance
ent_setEntitySet to which this iterator corresponds
chunk_sizeChunk size of this iterator
ent_typeEntity type for this iterator
ent_dimEntity dimension for this iterator

Definition at line 21 of file SetIterator.cpp.

        : SetIterator(core, eset, chunk_sz, ent_tp, ent_dim, check_valid),
          iterPos(0), pairPtr(NULL), numPairs(0)
{
  if (!eset) {
      // special case for the root set, have to keep a local array
    ErrorCode rval = build_pair_vec();
    assert(MB_SUCCESS == rval);

      // empty statement to avoid warning
    (void)(rval);
  }
}

Member Function Documentation

Build the special pair vector for the root set.

Definition at line 42 of file SetIterator.cpp.

{
    // shouldn't be here unless we're iterating the root set
  assert(!entSet);
  
  Range all_ents;
  ErrorCode rval = myCore->get_entities_by_handle(0, all_ents);
  if (MB_SUCCESS != rval) return rval;

  if (pairPtr) delete [] pairPtr;
  pairPtr = new EntityHandle[2*all_ents.psize()];
  Range::const_pair_iterator pi;
  int i;
  for (pi = all_ents.const_pair_begin(), i = 0;
       pi != all_ents.const_pair_end(); pi++, i+=2) {
    pairPtr[i] = (*pi).first;
    pairPtr[i+1] = (*pi).second;
  }
  numPairs = all_ents.psize();

  return MB_SUCCESS;
}
ErrorCode moab::RangeSetIterator::get_next_arr ( std::vector< EntityHandle > &  arr,
bool &  atend 
) [virtual]

get the next chunkSize entities Return the next chunkSize entities.

Parameters:
arrArray of entities returned.
atendReturns true if iterator is at the end of iterable values, otherwise false

Implements moab::SetIterator.

Definition at line 65 of file SetIterator.cpp.

{
  atend = false;  

  int count;
  const EntityHandle *ptr;
  WriteUtilIface *iface;
  std::vector<EntityHandle> tmp_arr;
  std::vector<EntityHandle> *tmp_ptr = &arr;
  if (checkValid) tmp_ptr = &tmp_arr;
  ErrorCode rval;
  if (!pairPtr) {
    Interface *mbImpl = dynamic_cast<Interface*>(myCore);
    rval = mbImpl->query_interface(iface);
    if (MB_SUCCESS != rval) return rval;
  
    rval = iface->get_entity_list_pointers( &entSet, 1, &ptr, WriteUtilIface::CONTENTS, &count);
    if (MB_SUCCESS != rval) return rval;
    mbImpl->release_interface(iface);
  }
  else {
    if (checkValid) {
      rval = build_pair_vec();
      if (MB_SUCCESS != rval) return rval;
    }
    ptr = pairPtr;
    count = 2*numPairs;
  }
  assert(!(count%2));
  if (!count) {
    atend = true;
    return MB_SUCCESS;
  }

  if (-1 == entDimension) rval = get_next_by_type(ptr, count, *tmp_ptr, atend);
  else rval = get_next_by_dimension(ptr, count, *tmp_ptr, atend);
  if (MB_SUCCESS != rval) return rval;
  
  if (checkValid) {
    for (std::vector<EntityHandle>::iterator vit = tmp_ptr->begin(); vit != tmp_ptr->end(); vit++) {
      if (myCore->is_valid(*vit)) arr.push_back(*vit);
    }
  }
    
  return MB_SUCCESS;
}
ErrorCode moab::RangeSetIterator::get_next_by_dimension ( const EntityHandle *&  ptr,
int  count,
std::vector< EntityHandle > &  arr,
bool &  atend 
) [private]

Definition at line 160 of file SetIterator.cpp.

{
    // iterating by dimension - type should be maxtype
  if (entType != MBMAXTYPE) {
    Error *error;
    dynamic_cast<Interface*>(myCore)->query_interface(error);
    error->set_last_error("Both dimension and type should not be set on an iterator.");
    return MB_FAILURE;
  }
    
  unsigned int num_ret = 0;
  size_t idx = 0;
    // initialize to first relevant handle
  while ((int)idx < count &&
         (iterPos > ptr[idx+1] ||
          (!iterPos && entDimension > CN::Dimension(TYPE_FROM_HANDLE(ptr[idx+1])))))
    idx += 2;
  if ((int)idx == count || CN::Dimension(TYPE_FROM_HANDLE(ptr[idx])) > entDimension) {
    atend = true;
    return MB_SUCCESS;
  }
  if (!iterPos) iterPos = ptr[idx];
  else if (CN::Dimension(TYPE_FROM_HANDLE(ptr[idx])) < entDimension)
    iterPos = CREATE_HANDLE(CN::TypeDimensionMap[entDimension].first,1);
  
    // idx points to start of subrange, iterPos in that subrange
  do {
    EntityHandle next = ptr[idx+1];
    if (CN::Dimension(TYPE_FROM_HANDLE(next)) != entDimension) 
      next = LAST_HANDLE(CN::TypeDimensionMap[entDimension].second);
    unsigned int this_ret = chunkSize-num_ret;
    unsigned int to_end = next - iterPos + 1;
    if (to_end < this_ret) this_ret = to_end;
    std::copy(MeshSet::hdl_iter(iterPos), MeshSet::hdl_iter(iterPos + this_ret),
              std::back_inserter(arr));
    if (this_ret == to_end) {
      idx += 2;
      iterPos = ((int)idx < count ? ptr[idx] : 0);
    }
    else iterPos += this_ret;

    num_ret += this_ret;
  }
  while ((int)idx < count && num_ret < chunkSize && 
         iterPos && CN::Dimension(TYPE_FROM_HANDLE(iterPos)) == entDimension);

  if (!iterPos || CN::Dimension(TYPE_FROM_HANDLE(iterPos)) != entDimension) atend = true;

  return MB_SUCCESS;
}
ErrorCode moab::RangeSetIterator::get_next_by_type ( const EntityHandle *&  ptr,
int  count,
std::vector< EntityHandle > &  arr,
bool &  atend 
) [private]

Definition at line 113 of file SetIterator.cpp.

{
  unsigned int num_ret = 0;
  bool max_type = (entType == MBMAXTYPE);
  size_t idx = 0;
    // initialize to first relevant handle
  while ((int)idx < count &&
         (iterPos > ptr[idx+1] ||
          (!max_type && !iterPos && CREATE_HANDLE(entType, ID_FROM_HANDLE(iterPos)) > ptr[idx+1])))
    idx += 2;
  if ((int)idx == count || TYPE_FROM_HANDLE(ptr[idx]) > entType) {
    atend = true;
    return MB_SUCCESS;
  }
  if (!iterPos && max_type) iterPos = ptr[idx];
  else if (!iterPos && 
           TYPE_FROM_HANDLE(ptr[idx]) <= entType &&
           TYPE_FROM_HANDLE(ptr[idx+1]) >= entType) {
    iterPos = std::max(CREATE_HANDLE(entType,1), ptr[idx]);
  }
  
    // idx points to start of subrange, iterPos in that subrange
  do {
    EntityHandle next = ptr[idx+1];
    if (TYPE_FROM_HANDLE(next) != entType && !max_type) next = LAST_HANDLE(entType);
    unsigned int this_ret = chunkSize-num_ret;
    unsigned int to_end = next - iterPos + 1;
    if (to_end < this_ret) this_ret = to_end;
    std::copy(MeshSet::hdl_iter(iterPos), MeshSet::hdl_iter(iterPos + this_ret),
              std::back_inserter(arr));
    if (this_ret == to_end) {
      idx += 2;
      iterPos = ((int)idx < count ? ptr[idx] : 0);
    }
    else iterPos += this_ret;

    num_ret += this_ret;
  }
  while ((int)idx < count && num_ret < chunkSize && 
         iterPos && (max_type || TYPE_FROM_HANDLE(iterPos) == entType));

  if (!iterPos || (!max_type && TYPE_FROM_HANDLE(iterPos) != entType)) atend = true;

  return MB_SUCCESS;
}

reset the iterator to the beginning of the set

Implements moab::SetIterator.

Definition at line 212 of file SetIterator.cpp.

{
  iterPos = 0; 
  return MB_SUCCESS;
}

Friends And Related Function Documentation

friend class Core [friend]

Reimplemented from moab::SetIterator.

Definition at line 85 of file SetIterator.hpp.


Member Data Documentation

Current iterator position, 0 if at beginning.

Definition at line 124 of file SetIterator.hpp.

Number of range pairs.

Definition at line 130 of file SetIterator.hpp.

Special range pair ptr for root set.

Definition at line 127 of file SetIterator.hpp.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines