1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#ifndef MB_SETITERATOR_HPP
#define MB_SETITERATOR_HPP

#include "moab/Interface.hpp"

namespace moab
{

class Core;

/** \class Meshset iterator
 * \brief A class to iterator over MOAB Meshsets
 */
class SetIterator
{
  public:
    friend class Core;

    //! destructor
    virtual ~SetIterator();

    //! get the ent set for this iterator
    inline EntityHandle ent_set() const
    {
        return entSet;
    };

    //! get the chunk size of this iterator
    inline unsigned int chunk_size() const
    {
        return chunkSize;
    };

    //! get the entity type for this iterator
    inline EntityType ent_type() const
    {
        return entType;
    };

    //! get the dimension for this iterator
    inline int ent_dimension() const
    {
        return entDimension;
    };

    /** \brief get the next chunkSize entities
     * Return the next chunkSize entities.
     * \param arr Array of entities returned.
     * \param atend Returns true if iterator is at the end of iterable values, otherwise false
     */
    virtual ErrorCode get_next_arr( std::vector< EntityHandle >& arr, bool& atend ) = 0;<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class

    //! reset the iterator to the beginning of the set
    virtual ErrorCode reset() = 0;<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class<--- Virtual function in base class

  protected:
    /** \brief Constructor
     * \param core MOAB Core instance
     * \param ent_set EntitySet to which this iterator corresponds
     * \param chunk_size Chunk size of this iterator
     * \param ent_type Entity type for this iterator
     * \param ent_dim Entity dimension for this iterator
     */
    inline SetIterator( Core* core,
                        EntityHandle eset,
                        unsigned int chunk_sz,
                        EntityType ent_tp,
                        int ent_dim,
                        bool check_valid = false )
        : myCore( core ), entSet( eset ), chunkSize( chunk_sz ), entType( ent_tp ), entDimension( ent_dim ),
          checkValid( check_valid ){};

    //! Core instance
    Core* myCore;

    //! handle for entity set corresponding to this iterator
    EntityHandle entSet;

    //! chunk size of this iterator
    unsigned int chunkSize;

    //! entity type this iterator iterates over
    EntityType entType;

    //! dimension this iterator iterates over
    int entDimension;

    //! check for entity validity before returning handles
    bool checkValid;
};

/** \class Set-type set iterator
 * \brief A class to iterator over MOAB set-type meshsets
 */
class RangeSetIterator : public SetIterator
{
  public:
    friend class Core;

    /** \brief Destructor
     */
    virtual ~RangeSetIterator();

    /** \brief get the next chunkSize entities
     * Return the next chunkSize entities.
     * \param arr Array of entities returned.
     * \param atend Returns true if iterator is at the end of iterable values, otherwise false
     */
    virtual ErrorCode get_next_arr( std::vector< EntityHandle >& arr, bool& atend );<--- Function in derived class<--- Function in derived class

    //! reset the iterator to the beginning of the set
    virtual ErrorCode reset();<--- Function in derived class<--- Function in derived class

  protected:
    /** \brief Constructor
     * \param core MOAB Core instance
     * \param ent_set EntitySet to which this iterator corresponds
     * \param chunk_size Chunk size of this iterator
     * \param ent_type Entity type for this iterator
     * \param ent_dim Entity dimension for this iterator
     */
    RangeSetIterator( Core* core,
                      EntityHandle ent_set,
                      int chunk_size,
                      EntityType ent_type,
                      int ent_dimension,
                      bool check_valid = false );

  private:
    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 );

    //! Build the special pair vector for the root set
    ErrorCode build_pair_vec();

    //! Current iterator position, 0 if at beginning
    EntityHandle iterPos;

    //! Special range pair ptr for root set
    EntityHandle* pairPtr;

    //! Number of range pairs
    int numPairs;
};

/** \class List-type set iterator
 * \brief A class to iterator over MOAB list-type meshsets
 */
class VectorSetIterator : public SetIterator
{
  public:
    friend class Core;

    /** \brief get the next chunkSize entities
     * Return the next chunkSize entities.
     * \param arr Array of entities returned.
     * \param atend Returns true if iterator is at the end of iterable values, otherwise false
     */
    virtual ErrorCode get_next_arr( std::vector< EntityHandle >& arr, bool& atend );<--- Function in derived class<--- Function in derived class

    //! reset the iterator to the beginning of the set
    virtual ErrorCode reset();<--- Function in derived class<--- Function in derived class

    //! decrement the position by the specified number; returns MB_FAILURE if resulting index is < 0
    inline ErrorCode decrement( int num );

  protected:
    /** \brief Constructor
     * \param core MOAB Core instance
     * \param ent_set EntitySet to which this iterator corresponds
     * \param chunk_size Chunk size of this iterator
     * \param ent_type Entity type for this iterator
     * \param ent_dim Entity dimension for this iterator
     */
    inline VectorSetIterator( Core* core,
                              EntityHandle eset,
                              int chunk_sz,
                              EntityType ent_tp,
                              int ent_dim,
                              bool check_valid = false )
        : SetIterator( core, eset, chunk_sz, ent_tp, ent_dim, check_valid ), iterPos( 0 )
    {
    }

  private:
    //! Current iterator position, 0 if at beginning
    int iterPos;
};

inline ErrorCode VectorSetIterator::decrement( int num )
{
    iterPos -= num;
    return ( iterPos < 0 ? MB_FAILURE : MB_SUCCESS );
}

}  // namespace moab

#endif