Mesh Oriented datABase  (version 5.5.1)
An array-based unstructured mesh library
SetIterator.hpp
Go to the documentation of this file.
1 #ifndef MB_SETITERATOR_HPP
2 #define MB_SETITERATOR_HPP
3 
4 #include "moab/Interface.hpp"
5 
6 namespace moab
7 {
8 
9 class Core;
10 
11 /** \class Meshset iterator
12  * \brief A class to iterator over MOAB Meshsets
13  */
15 {
16  public:
17  friend class Core;
18 
19  //! destructor
20  virtual ~SetIterator();
21 
22  //! get the ent set for this iterator
23  inline EntityHandle ent_set() const
24  {
25  return entSet;
26  };
27 
28  //! get the chunk size of this iterator
29  inline unsigned int chunk_size() const
30  {
31  return chunkSize;
32  };
33 
34  //! get the entity type for this iterator
35  inline EntityType ent_type() const
36  {
37  return entType;
38  };
39 
40  //! get the dimension for this iterator
41  inline int ent_dimension() const
42  {
43  return entDimension;
44  };
45 
46  /** \brief get the next chunkSize entities
47  * Return the next chunkSize entities.
48  * \param arr Array of entities returned.
49  * \param atend Returns true if iterator is at the end of iterable values, otherwise false
50  */
51  virtual ErrorCode get_next_arr( std::vector< EntityHandle >& arr, bool& atend ) = 0;
52 
53  //! reset the iterator to the beginning of the set
54  virtual ErrorCode reset() = 0;
55 
56  protected:
57  /** \brief Constructor
58  * \param core MOAB Core instance
59  * \param ent_set EntitySet to which this iterator corresponds
60  * \param chunk_size Chunk size of this iterator
61  * \param ent_type Entity type for this iterator
62  * \param ent_dim Entity dimension for this iterator
63  */
64  inline SetIterator( Core* core,
65  EntityHandle eset,
66  unsigned int chunk_sz,
67  EntityType ent_tp,
68  int ent_dim,
69  bool check_valid = false )
70  : myCore( core ), entSet( eset ), chunkSize( chunk_sz ), entType( ent_tp ), entDimension( ent_dim ),
71  checkValid( check_valid ){};
72 
73  //! Core instance
75 
76  //! handle for entity set corresponding to this iterator
78 
79  //! chunk size of this iterator
80  unsigned int chunkSize;
81 
82  //! entity type this iterator iterates over
83  EntityType entType;
84 
85  //! dimension this iterator iterates over
87 
88  //! check for entity validity before returning handles
89  bool checkValid;
90 };
91 
92 /** \class Set-type set iterator
93  * \brief A class to iterator over MOAB set-type meshsets
94  */
96 {
97  public:
98  friend class Core;
99 
100  /** \brief Destructor
101  */
102  virtual ~RangeSetIterator();
103 
104  /** \brief get the next chunkSize entities
105  * Return the next chunkSize entities.
106  * \param arr Array of entities returned.
107  * \param atend Returns true if iterator is at the end of iterable values, otherwise false
108  */
109  virtual ErrorCode get_next_arr( std::vector< EntityHandle >& arr, bool& atend );
110 
111  //! reset the iterator to the beginning of the set
112  virtual ErrorCode reset();
113 
114  protected:
115  /** \brief Constructor
116  * \param core MOAB Core instance
117  * \param ent_set EntitySet to which this iterator corresponds
118  * \param chunk_size Chunk size of this iterator
119  * \param ent_type Entity type for this iterator
120  * \param ent_dim Entity dimension for this iterator
121  */
122  RangeSetIterator( Core* core,
124  int chunk_size,
125  EntityType ent_type,
126  int ent_dimension,
127  bool check_valid = false );
128 
129  private:
130  ErrorCode get_next_by_type( const EntityHandle*& ptr, int count, std::vector< EntityHandle >& arr, bool& atend );
131 
133  int count,
134  std::vector< EntityHandle >& arr,
135  bool& atend );
136 
137  //! Build the special pair vector for the root set
139 
140  //! Current iterator position, 0 if at beginning
142 
143  //! Special range pair ptr for root set
145 
146  //! Number of range pairs
147  int numPairs;
148 };
149 
150 /** \class List-type set iterator
151  * \brief A class to iterator over MOAB list-type meshsets
152  */
154 {
155  public:
156  friend class Core;
157 
158  /** \brief get the next chunkSize entities
159  * Return the next chunkSize entities.
160  * \param arr Array of entities returned.
161  * \param atend Returns true if iterator is at the end of iterable values, otherwise false
162  */
163  virtual ErrorCode get_next_arr( std::vector< EntityHandle >& arr, bool& atend );
164 
165  //! reset the iterator to the beginning of the set
166  virtual ErrorCode reset();
167 
168  //! decrement the position by the specified number; returns MB_FAILURE if resulting index is < 0
169  inline ErrorCode decrement( int num );
170 
171  protected:
172  /** \brief Constructor
173  * \param core MOAB Core instance
174  * \param ent_set EntitySet to which this iterator corresponds
175  * \param chunk_size Chunk size of this iterator
176  * \param ent_type Entity type for this iterator
177  * \param ent_dim Entity dimension for this iterator
178  */
179  inline VectorSetIterator( Core* core,
180  EntityHandle eset,
181  int chunk_sz,
182  EntityType ent_tp,
183  int ent_dim,
184  bool check_valid = false )
185  : SetIterator( core, eset, chunk_sz, ent_tp, ent_dim, check_valid ), iterPos( 0 )
186  {
187  }
188 
189  private:
190  //! Current iterator position, 0 if at beginning
191  int iterPos;
192 };
193 
195 {
196  iterPos -= num;
197  return ( iterPos < 0 ? MB_FAILURE : MB_SUCCESS );
198 }
199 
200 } // namespace moab
201 
202 #endif