MOAB: Mesh Oriented datABase  (version 5.2.1)
SetIterator.hpp
Go to the documentation of this file.
00001 #ifndef MB_SETITERATOR_HPP
00002 #define MB_SETITERATOR_HPP
00003 
00004 #include "moab/Interface.hpp"
00005 
00006 namespace moab
00007 {
00008 
00009 class Core;
00010 
00011 /** \class Meshset iterator
00012  * \brief A class to iterator over MOAB Meshsets
00013  */
00014 class SetIterator
00015 {
00016   public:
00017     friend class Core;
00018 
00019     //! destructor
00020     virtual ~SetIterator();
00021 
00022     //! get the ent set for this iterator
00023     inline EntityHandle ent_set() const
00024     {
00025         return entSet;
00026     };
00027 
00028     //! get the chunk size of this iterator
00029     inline unsigned int chunk_size() const
00030     {
00031         return chunkSize;
00032     };
00033 
00034     //! get the entity type for this iterator
00035     inline EntityType ent_type() const
00036     {
00037         return entType;
00038     };
00039 
00040     //! get the dimension for this iterator
00041     inline int ent_dimension() const
00042     {
00043         return entDimension;
00044     };
00045 
00046     /** \brief get the next chunkSize entities
00047      * Return the next chunkSize entities.
00048      * \param arr Array of entities returned.
00049      * \param atend Returns true if iterator is at the end of iterable values, otherwise false
00050      */
00051     virtual ErrorCode get_next_arr( std::vector< EntityHandle >& arr, bool& atend ) = 0;
00052 
00053     //! reset the iterator to the beginning of the set
00054     virtual ErrorCode reset() = 0;
00055 
00056   protected:
00057     /** \brief Constructor
00058      * \param core MOAB Core instance
00059      * \param ent_set EntitySet to which this iterator corresponds
00060      * \param chunk_size Chunk size of this iterator
00061      * \param ent_type Entity type for this iterator
00062      * \param ent_dim Entity dimension for this iterator
00063      */
00064     inline SetIterator( Core* core, EntityHandle eset, unsigned int chunk_sz, EntityType ent_tp, int ent_dim,
00065                         bool check_valid = false )
00066         : myCore( core ), entSet( eset ), chunkSize( chunk_sz ), entType( ent_tp ), entDimension( ent_dim ),
00067           checkValid( check_valid ){};
00068 
00069     //! Core instance
00070     Core* myCore;
00071 
00072     //! handle for entity set corresponding to this iterator
00073     EntityHandle entSet;
00074 
00075     //! chunk size of this iterator
00076     unsigned int chunkSize;
00077 
00078     //! entity type this iterator iterates over
00079     EntityType entType;
00080 
00081     //! dimension this iterator iterates over
00082     int entDimension;
00083 
00084     //! check for entity validity before returning handles
00085     bool checkValid;
00086 };
00087 
00088 /** \class Set-type set iterator
00089  * \brief A class to iterator over MOAB set-type meshsets
00090  */
00091 class RangeSetIterator : public SetIterator
00092 {
00093   public:
00094     friend class Core;
00095 
00096     /** \brief Destructor
00097      */
00098     virtual ~RangeSetIterator();
00099 
00100     /** \brief get the next chunkSize entities
00101      * Return the next chunkSize entities.
00102      * \param arr Array of entities returned.
00103      * \param atend Returns true if iterator is at the end of iterable values, otherwise false
00104      */
00105     virtual ErrorCode get_next_arr( std::vector< EntityHandle >& arr, bool& atend );
00106 
00107     //! reset the iterator to the beginning of the set
00108     virtual ErrorCode reset();
00109 
00110   protected:
00111     /** \brief Constructor
00112      * \param core MOAB Core instance
00113      * \param ent_set EntitySet to which this iterator corresponds
00114      * \param chunk_size Chunk size of this iterator
00115      * \param ent_type Entity type for this iterator
00116      * \param ent_dim Entity dimension for this iterator
00117      */
00118     RangeSetIterator( Core* core, EntityHandle ent_set, int chunk_size, EntityType ent_type, int ent_dimension,
00119                       bool check_valid = false );
00120 
00121   private:
00122     ErrorCode get_next_by_type( const EntityHandle*& ptr, int count, std::vector< EntityHandle >& arr, bool& atend );
00123 
00124     ErrorCode get_next_by_dimension( const EntityHandle*& ptr, int count, std::vector< EntityHandle >& arr,
00125                                      bool& atend );
00126 
00127     //! Build the special pair vector for the root set
00128     ErrorCode build_pair_vec();
00129 
00130     //! Current iterator position, 0 if at beginning
00131     EntityHandle iterPos;
00132 
00133     //! Special range pair ptr for root set
00134     EntityHandle* pairPtr;
00135 
00136     //! Number of range pairs
00137     int numPairs;
00138 };
00139 
00140 /** \class List-type set iterator
00141  * \brief A class to iterator over MOAB list-type meshsets
00142  */
00143 class VectorSetIterator : public SetIterator
00144 {
00145   public:
00146     friend class Core;
00147 
00148     /** \brief get the next chunkSize entities
00149      * Return the next chunkSize entities.
00150      * \param arr Array of entities returned.
00151      * \param atend Returns true if iterator is at the end of iterable values, otherwise false
00152      */
00153     virtual ErrorCode get_next_arr( std::vector< EntityHandle >& arr, bool& atend );
00154 
00155     //! reset the iterator to the beginning of the set
00156     virtual ErrorCode reset();
00157 
00158     //! decrement the position by the specified number; returns MB_FAILURE if resulting index is < 0
00159     inline ErrorCode decrement( int num );
00160 
00161   protected:
00162     /** \brief Constructor
00163      * \param core MOAB Core instance
00164      * \param ent_set EntitySet to which this iterator corresponds
00165      * \param chunk_size Chunk size of this iterator
00166      * \param ent_type Entity type for this iterator
00167      * \param ent_dim Entity dimension for this iterator
00168      */
00169     inline VectorSetIterator( Core* core, EntityHandle eset, int chunk_sz, EntityType ent_tp, int ent_dim,
00170                               bool check_valid = false )
00171         : SetIterator( core, eset, chunk_sz, ent_tp, ent_dim, check_valid ), iterPos( 0 )
00172     {
00173     }
00174 
00175   private:
00176     //! Current iterator position, 0 if at beginning
00177     int iterPos;
00178 };
00179 
00180 inline ErrorCode VectorSetIterator::decrement( int num )
00181 {
00182     iterPos -= num;
00183     return ( iterPos < 0 ? MB_FAILURE : MB_SUCCESS );
00184 }
00185 
00186 }  // namespace moab
00187 
00188 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines