![]() |
Mesh Oriented datABase
(version 5.4.1)
Array-based unstructured mesh datastructure
|
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,
00065 EntityHandle eset,
00066 unsigned int chunk_sz,
00067 EntityType ent_tp,
00068 int ent_dim,
00069 bool check_valid = false )
00070 : myCore( core ), entSet( eset ), chunkSize( chunk_sz ), entType( ent_tp ), entDimension( ent_dim ),
00071 checkValid( check_valid ){};
00072
00073 //! Core instance
00074 Core* myCore;
00075
00076 //! handle for entity set corresponding to this iterator
00077 EntityHandle entSet;
00078
00079 //! chunk size of this iterator
00080 unsigned int chunkSize;
00081
00082 //! entity type this iterator iterates over
00083 EntityType entType;
00084
00085 //! dimension this iterator iterates over
00086 int entDimension;
00087
00088 //! check for entity validity before returning handles
00089 bool checkValid;
00090 };
00091
00092 /** \class Set-type set iterator
00093 * \brief A class to iterator over MOAB set-type meshsets
00094 */
00095 class RangeSetIterator : public SetIterator
00096 {
00097 public:
00098 friend class Core;
00099
00100 /** \brief Destructor
00101 */
00102 virtual ~RangeSetIterator();
00103
00104 /** \brief get the next chunkSize entities
00105 * Return the next chunkSize entities.
00106 * \param arr Array of entities returned.
00107 * \param atend Returns true if iterator is at the end of iterable values, otherwise false
00108 */
00109 virtual ErrorCode get_next_arr( std::vector< EntityHandle >& arr, bool& atend );
00110
00111 //! reset the iterator to the beginning of the set
00112 virtual ErrorCode reset();
00113
00114 protected:
00115 /** \brief Constructor
00116 * \param core MOAB Core instance
00117 * \param ent_set EntitySet to which this iterator corresponds
00118 * \param chunk_size Chunk size of this iterator
00119 * \param ent_type Entity type for this iterator
00120 * \param ent_dim Entity dimension for this iterator
00121 */
00122 RangeSetIterator( Core* core,
00123 EntityHandle ent_set,
00124 int chunk_size,
00125 EntityType ent_type,
00126 int ent_dimension,
00127 bool check_valid = false );
00128
00129 private:
00130 ErrorCode get_next_by_type( const EntityHandle*& ptr, int count, std::vector< EntityHandle >& arr, bool& atend );
00131
00132 ErrorCode get_next_by_dimension( const EntityHandle*& ptr,
00133 int count,
00134 std::vector< EntityHandle >& arr,
00135 bool& atend );
00136
00137 //! Build the special pair vector for the root set
00138 ErrorCode build_pair_vec();
00139
00140 //! Current iterator position, 0 if at beginning
00141 EntityHandle iterPos;
00142
00143 //! Special range pair ptr for root set
00144 EntityHandle* pairPtr;
00145
00146 //! Number of range pairs
00147 int numPairs;
00148 };
00149
00150 /** \class List-type set iterator
00151 * \brief A class to iterator over MOAB list-type meshsets
00152 */
00153 class VectorSetIterator : public SetIterator
00154 {
00155 public:
00156 friend class Core;
00157
00158 /** \brief get the next chunkSize entities
00159 * Return the next chunkSize entities.
00160 * \param arr Array of entities returned.
00161 * \param atend Returns true if iterator is at the end of iterable values, otherwise false
00162 */
00163 virtual ErrorCode get_next_arr( std::vector< EntityHandle >& arr, bool& atend );
00164
00165 //! reset the iterator to the beginning of the set
00166 virtual ErrorCode reset();
00167
00168 //! decrement the position by the specified number; returns MB_FAILURE if resulting index is < 0
00169 inline ErrorCode decrement( int num );
00170
00171 protected:
00172 /** \brief Constructor
00173 * \param core MOAB Core instance
00174 * \param ent_set EntitySet to which this iterator corresponds
00175 * \param chunk_size Chunk size of this iterator
00176 * \param ent_type Entity type for this iterator
00177 * \param ent_dim Entity dimension for this iterator
00178 */
00179 inline VectorSetIterator( Core* core,
00180 EntityHandle eset,
00181 int chunk_sz,
00182 EntityType ent_tp,
00183 int ent_dim,
00184 bool check_valid = false )
00185 : SetIterator( core, eset, chunk_sz, ent_tp, ent_dim, check_valid ), iterPos( 0 )
00186 {
00187 }
00188
00189 private:
00190 //! Current iterator position, 0 if at beginning
00191 int iterPos;
00192 };
00193
00194 inline ErrorCode VectorSetIterator::decrement( int num )
00195 {
00196 iterPos -= num;
00197 return ( iterPos < 0 ? MB_FAILURE : MB_SUCCESS );
00198 }
00199
00200 } // namespace moab
00201
00202 #endif