-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathNodeIteratorBase.cc
More file actions
118 lines (98 loc) · 3.89 KB
/
NodeIteratorBase.cc
File metadata and controls
118 lines (98 loc) · 3.89 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
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
//---------------------------------Spheral++----------------------------------//
// NodeIteratorBase -- This is a helper class for the DataBase. This is the
// base class for the node iterators. This class implements the basic methods,
// most importantly how to index by such iterators into Fields/FieldLists.
// Based on the old NodeIDIterator class.
//
// Created by J. Michael Owen, Mon Mar 17 13:11:19 PST 2003
//----------------------------------------------------------------------------//
#include "NodeIteratorBase.hh"
#include "NodeList/FluidNodeList.hh"
#include <algorithm>
#include <cstdlib>
using std::vector;
namespace Spheral {
//------------------------------------------------------------------------------
// Default constructor.
//------------------------------------------------------------------------------
template<typename Dimension>
NodeIteratorBase<Dimension>::
NodeIteratorBase():
mNodeID(0),
mFieldID(0),
mNodeListBegin(),
mNodeListEnd(),
mNodeListItr() {
}
//------------------------------------------------------------------------------
// Copy constructor
//------------------------------------------------------------------------------
template<typename Dimension>
NodeIteratorBase<Dimension>::
NodeIteratorBase(const NodeIteratorBase<Dimension>& rhs):
mNodeID(rhs.mNodeID),
mFieldID(rhs.mFieldID),
mNodeListBegin(rhs.mNodeListBegin),
mNodeListEnd(rhs.mNodeListEnd),
mNodeListItr(rhs.mNodeListItr) {
ENSURE(valid());
}
//------------------------------------------------------------------------------
// Destructor
//------------------------------------------------------------------------------
template<typename Dimension>
NodeIteratorBase<Dimension>::
~NodeIteratorBase() {
}
//------------------------------------------------------------------------------
// Assignment
//------------------------------------------------------------------------------
template<typename Dimension>
NodeIteratorBase<Dimension>&
NodeIteratorBase<Dimension>::
operator=(const NodeIteratorBase<Dimension>& rhs) {
if (&rhs != this) {
mNodeID = rhs.mNodeID;
mFieldID = rhs.mFieldID;
mNodeListBegin = rhs.mNodeListBegin;
mNodeListEnd = rhs.mNodeListEnd;
mNodeListItr = rhs.mNodeListItr;
}
ENSURE(valid());
return *this;
}
//------------------------------------------------------------------------------
// Return a pointer to the NodeList cast as a FluidNodeList.
//------------------------------------------------------------------------------
template<typename Dimension>
const FluidNodeList<Dimension>*
NodeIteratorBase<Dimension>::
fluidNodeListPtr() const {
const FluidNodeList<Dimension>* result = dynamic_cast<const FluidNodeList<Dimension>*>(nodeListPtr());
ENSURE(result != 0);
return result;
}
//------------------------------------------------------------------------------
// Base valid test.
//------------------------------------------------------------------------------
template<typename Dimension>
bool
NodeIteratorBase<Dimension>::
valid() const {
// We want real NodeList iterators.
// const bool validNodeListIterators = (mNodeListItr != typename vector<NodeList<Dimension>*>::const_iterator() &&
// mNodeListBegin != typename vector<NodeList<Dimension>*>::const_iterator() &&
// mNodeListEnd != typename vector<NodeList<Dimension>*>::const_iterator());
// Test if the NodeList iterator is in the appropriate range.
const bool nodeListRange = (mNodeListItr >= mNodeListBegin &&
mNodeListItr <= mNodeListEnd);
// Are we on a valid NodeList?
if (nodeListRange && mNodeListItr < mNodeListEnd) {
const bool nodeIDTest = mNodeID >= 0 && mNodeID < (int)nodeListPtr()->numNodes();
const bool fieldIDTest = mFieldID == distance(mNodeListBegin, mNodeListItr);
return nodeListRange && nodeIDTest && fieldIDTest;
} else {
return nodeListRange;
}
}
}