-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparticleiterator.cpp
More file actions
91 lines (75 loc) · 2.18 KB
/
particleiterator.cpp
File metadata and controls
91 lines (75 loc) · 2.18 KB
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
#include "bucket.h"
namespace Physics {
Bucket::neighbour_iterator::neighbour_iterator(Bucket *bucket)
:
bucket_iter(bucket->neighbours.begin()),
bucket_end(bucket->neighbours.end()),
particle_iter((*bucket_iter)->particles.begin()),
particle_end((*bucket_iter)->particles.end()),
valid(true)
{
// Make sure particle_iter points to an actual particle
while (particle_iter == particle_end and bucket_iter != bucket_end)
operator++();
}
Bucket::neighbour_iterator::neighbour_iterator(Bucket *bucket, bool isend)
:
bucket_iter(--bucket->neighbours.end()),
bucket_end(bucket->neighbours.end()),
particle_iter((*bucket_iter)->particles.end()),
particle_end((*bucket_iter++)->particles.end()),
valid(false)
{}
Bucket::neighbour_iterator::neighbour_iterator(Bucket::neighbour_iterator const &other)
:
bucket_iter(other.bucket_iter),
bucket_end(other.bucket_end),
particle_iter(other.particle_iter),
particle_end(other.particle_end),
valid(other.valid)
{}
Bucket::neighbour_iterator &Bucket::neighbour_iterator::operator++()
{
if (++particle_iter != particle_end)
return *this;
while (++bucket_iter != bucket_end)
{
particle_iter = (*bucket_iter)->particles.begin();
particle_end = (*bucket_iter)->particles.end();
if (particle_iter != particle_end)
return *this;
}
valid = false;
return *this;
}
Bucket::neighbour_iterator const Bucket::neighbour_iterator::operator++(int)
{
neighbour_iterator tmp(*this);
operator++();
return tmp;
}
bool Bucket::neighbour_iterator::operator==(neighbour_iterator const &other) const
{
return particle_iter == other.particle_iter;
}
bool Bucket::neighbour_iterator::operator!=(neighbour_iterator const &other) const
{
return particle_iter != other.particle_iter;
}
Particle *Bucket::neighbour_iterator::operator*()
{
return *particle_iter;
}
Particle **Bucket::neighbour_iterator::operator->()
{
return &(*particle_iter);
}
Bucket::neighbour_iterator Bucket::begin()
{
return Bucket::neighbour_iterator(this);
}
Bucket::neighbour_iterator Bucket::end()
{
return Bucket::neighbour_iterator(this, true);
}
}