Advanced Multi-Physics (AMP)
On-Line Documentation
MeshIterator.h
Go to the documentation of this file.
1#ifndef included_AMP_MeshIterators
2#define included_AMP_MeshIterators
3
4#include "AMP/mesh/MeshElement.h"
5
6#include <iterator>
7#include <memory>
8
9
10namespace AMP::IO {
11class RestartManager;
12}
13
14
15namespace AMP::Mesh {
16
17
18class MeshIterator;
19
20
27{
28};
29
30
41{
42public: // iterator_traits
43 using iterator_category = std::random_access_iterator_tag;
45 using difference_type = ptrdiff_t;
48
49
50public:
52 enum class Type : uint8_t { Forward = 1, Bidirectional = 2, RandomAccess = 3 };
53
54
55public:
57 inline Type type() const { return d_iteratorType; }
58
60 inline uint64_t getID() const { return d_typeHash; }
61
63 inline size_t empty() const { return d_size == 0; }
64
66 inline size_t size() const { return d_size; }
67
69 inline size_t pos() const { return d_pos; }
70
72 inline const MeshElement *operator->() const { return d_element; }
73
75 inline const MeshElement &operator*() const { return *d_element; }
76
78 inline MeshIteratorEnd end() const { return MeshIteratorEnd(); }
79
81 inline bool operator==( MeshIteratorEnd ) const { return d_pos == d_size; }
82
84 inline bool operator!=( MeshIteratorEnd ) const { return d_pos != d_size; }
85
86public:
88 virtual ~MeshIteratorBase() = default;
89
91 virtual std::string className() const = 0;
92
94 virtual void setPos( size_t ) = 0;
95
96 // Increment
98
99 // Decrement
101
102 // Arithmetic operator+=
103 virtual MeshIteratorBase &operator+=( int N ) = 0;
104
106 virtual bool operator==( const MeshIteratorBase &rhs ) const = 0;
107
109 virtual bool operator!=( const MeshIteratorBase &rhs ) const = 0;
110
112 virtual MeshIterator begin() const = 0;
113
115 virtual std::unique_ptr<MeshIteratorBase> clone() const = 0;
116
117
118public: // Write/read restart data
120 virtual void writeRestart( int64_t ) const = 0;
122
123
124protected:
125 MeshIteratorBase() = default;
130
131
132protected:
134 uint32_t d_typeHash = 0;
135 size_t d_size = 0;
136 size_t d_pos = 0;
137 const MeshElement *d_element = nullptr;
138};
139
140
149class MeshIterator final
150{
151public: // iterator_traits
152 using iterator_category = std::random_access_iterator_tag;
154 using difference_type = ptrdiff_t;
158
159
160public:
162 template<class T, typename... Args>
163 static MeshIterator create( Args... args )
164 {
165 return MeshIterator( new T( std::forward<Args>( args )... ) );
166 }
167
170
172 MeshIterator( std::unique_ptr<MeshIteratorBase> &&p ) : it( p.release() ) {}
173
176
179
182
185
187 MeshIterator &operator=( std::unique_ptr<MeshIteratorBase> && );
188
190 ~MeshIterator() { delete it; }
191
193 inline std::string className() const { return it->className(); }
194
196 inline MeshIterator begin() const { return it->begin(); }
197
199 inline MeshIteratorEnd end() const { return MeshIteratorEnd(); }
200
207 {
208 it->operator++();
209 return *this;
210 }
211
219 {
220 it->operator--();
221 return *this;
222 }
223
233 inline MeshIterator &operator+=( int N )
234 {
235 it->operator+=( N );
236 return *this;
237 }
238
247
249 inline bool operator==( const MeshIterator &rhs ) const { return *it == *rhs.it; }
250
252 inline bool operator==( MeshIteratorEnd rhs ) const { return *it == rhs; }
253
255 inline bool operator==( const MeshIteratorBase &rhs ) const { return *it == rhs; }
256
258 inline bool operator!=( const MeshIterator &rhs ) const { return *it != *rhs.it; }
259
261 inline bool operator!=( MeshIteratorEnd rhs ) const { return *it != rhs; }
262
264 inline bool operator!=( const MeshIteratorBase &rhs ) const { return *it != rhs; }
265
267 inline Type type() const { return it->type(); }
268
270 inline uint64_t getID() const { return it->getID(); }
271
273 inline MeshIteratorBase *rawIterator() { return it; }
274
276 inline const MeshIteratorBase *rawIterator() const { return it; }
277
279 inline bool empty() const { return it->empty(); }
280
282 inline size_t size() const { return it->size(); }
283
285 inline size_t pos() const { return it->pos(); }
286
288 inline void setPos( size_t i ) { it->setPos( i ); }
289
291 inline bool operator<( const MeshIterator &rhs ) const { return pos() < rhs.pos(); }
292
294 inline bool operator<=( const MeshIterator &rhs ) const { return pos() <= rhs.pos(); }
295
297 inline bool operator>( const MeshIterator &rhs ) const { return pos() > rhs.pos(); }
298
300 inline bool operator>=( const MeshIterator &rhs ) const { return pos() >= rhs.pos(); }
301
303 inline const MeshElement &operator*() const { return it->operator*(); }
304
306 inline const MeshElement *operator->() const { return it->operator->(); }
307
309 inline const MeshElement *get() const { return it->operator->(); }
310
317
325
335 MeshIterator operator+( int N ) const;
336
345
353 MeshIterator operator-( int N ) const;
354
363
372
381
382
383public: // Advanced functions (use with caution)
386
397
398
399public: // Write/read restart data
401 void writeRestart( int64_t fid ) const;
402 MeshIterator( int64_t fid );
403
404
405protected:
406 MeshIteratorBase *it = nullptr; // A pointer to the derived class
407};
408
409
410} // namespace AMP::Mesh
411
412
413#endif
Class to manage reading/writing restart data.
A base class used to iterate over elements in a Mesh.
size_t d_size
Size of the iterator.
virtual MeshIteratorBase & operator++()=0
size_t pos() const
Return the current position (from the beginning) in the iterator.
const MeshElement * d_element
Pointer to the current element.
Type d_iteratorType
Type of iterator.
MeshIteratorBase(const MeshIteratorBase &)=delete
MeshIteratorBase & operator=(MeshIteratorBase &&)=delete
std::random_access_iterator_tag iterator_category
Type type() const
Return the iterator type.
MeshIteratorBase & operator=(const MeshIteratorBase &)=delete
size_t d_pos
Position of the iterator.
size_t empty() const
Return the number of elements in the iterator.
virtual MeshIterator begin() const =0
Return an iterator to the beginning.
virtual std::string className() const =0
Return the class name.
bool operator!=(MeshIteratorEnd) const
Check if two iterators are not equal.
const MeshElement & operator*() const
Dereference the iterator.
virtual MeshIteratorBase & operator--()=0
virtual bool operator!=(const MeshIteratorBase &rhs) const =0
Check if two iterators are not equal.
Type
Enum for the type of iterator supported.
MeshIteratorBase(int64_t, AMP::IO::RestartManager *)
virtual ~MeshIteratorBase()=default
Virtual destructor.
virtual void setPos(size_t)=0
Set the position in the iterator.
virtual std::unique_ptr< MeshIteratorBase > clone() const =0
Clone the iterator.
virtual void registerChildObjects(AMP::IO::RestartManager *) const =0
bool operator==(MeshIteratorEnd) const
Check if two iterators are equal.
uint32_t d_typeHash
Unique hash for the type.
const MeshElement * operator->() const
Dereference the iterator.
MeshIteratorBase(MeshIteratorBase &&)=delete
virtual MeshIteratorBase & operator+=(int N)=0
virtual void writeRestart(int64_t) const =0
size_t size() const
Return the number of elements in the iterator.
uint64_t getID() const
Return a unique hash id.
virtual bool operator==(const MeshIteratorBase &rhs) const =0
Check if two iterators are equal.
MeshIteratorEnd end() const
Return an iterator to the end (use tombstone class)
A base class used to represent the end iterator.
A class used to iterate over elements in a Mesh.
MeshIteratorBase * rawIterator()
Return the raw iterator (may be this)
bool operator>(const MeshIterator &rhs) const
Operator >
bool empty() const
Check if the iterator is empty.
std::random_access_iterator_tag iterator_category
MeshIterator & operator-=(const MeshIterator &it)
Arithmetic operator-=.
MeshIteratorBase * it
const MeshElement & operator*() const
Dereference the iterator.
MeshIterator & operator=(MeshIterator &&)
Move operator.
MeshIterator(int64_t fid)
MeshIterator()
Empty MeshIterator constructor.
MeshIterator & operator+=(const MeshIterator &it)
Arithmetic operator+=.
MeshIterator(MeshIterator &&)
Move constructor.
size_t pos() const
Return the current position (from the beginning) in the iterator.
static MeshIterator create(Args... args)
Create a mesh iterator.
MeshIterator & operator=(std::unique_ptr< MeshIteratorBase > &&)
Assignment operator.
MeshIteratorEnd end() const
Return an iterator to the end (use tombstone class)
const MeshIteratorBase * rawIterator() const
Return the raw iterator (may be this)
MeshIterator(const MeshIterator &)
Copy constructor.
bool operator==(MeshIteratorEnd rhs) const
Check if two iterators are equal.
void registerChildObjects(AMP::IO::RestartManager *manager) const
MeshIterator operator+(const MeshIterator &it) const
Arithmetic operator+.
MeshIterator(MeshIteratorBase *p)
Constructor that takes ownership of the raw pointer.
MeshIterator & operator+=(int N)
Arithmetic operator+=.
MeshIterator(std::unique_ptr< MeshIteratorBase > &&p)
Default constructor.
MeshIteratorBase * release()
Return a pointer to the underlying and release ownership.
bool operator!=(MeshIteratorEnd rhs) const
Check if two iterators are not equal.
void setPos(size_t i)
Set the position in the iterator.
bool operator!=(const MeshIteratorBase &rhs) const
Check if two iterators are not equal.
MeshIterator operator+(int N) const
Arithmetic operator+.
MeshIterator & operator-=(int N)
Arithmetic operator-=.
std::string className() const
Return the class name.
bool operator<(const MeshIterator &rhs) const
Operator <.
MeshIterator begin() const
Return an iterator to the beginning.
void writeRestart(int64_t fid) const
bool operator==(const MeshIteratorBase &rhs) const
Check if two iterators are equal.
bool operator<=(const MeshIterator &rhs) const
Operator <=.
const MeshElement * get() const
Dereference the iterator.
bool operator==(const MeshIterator &rhs) const
Check if two iterators are equal.
bool operator>=(const MeshIterator &rhs) const
Operator >=.
uint64_t getID() const
Return a unique hash id.
size_t size() const
Return the number of elements in the iterator.
MeshIterator operator-(int N) const
Arithmetic operator-.
MeshIterator & operator--()
Pre-Decrement.
MeshIterator operator++(int)
Post-Increment.
MeshIterator operator--(int)
Post-Decrement.
Type type() const
Return the iterator type.
bool operator!=(const MeshIterator &rhs) const
Check if two iterators are not equal.
MeshIterator operator-(const MeshIterator &it) const
Arithmetic operator-.
const MeshElement * operator->() const
Dereference the iterator.
MeshIterator & operator=(const MeshIterator &)
Assignment operator.
MeshIterator & operator++()
Pre-Increment.
~MeshIterator()
Deconstructor.



Advanced Multi-Physics (AMP)
Oak Ridge National Laboratory
Idaho National Laboratory
Los Alamos National Laboratory
This page automatically produced from the
source code by doxygen
Last updated: Tue Mar 10 2026 13:06:40.
Comments on this page