PSCF v1.4.0
VertexIterator.tpp
1/*
2* PSCF - Polymer Self-Consistent Field
3*
4* Copyright 2015 - 2025, The Regents of the University of Minnesota
5* Distributed under the terms of the GNU General Public License.
6*/
7
8#include "VertexIterator.h"
9#include <pscf/chem/PolymerSpecies.h>
10#include <pscf/chem/Edge.h>
11
12namespace Pscf {
13
14 /*
15 * Constructor
16 */
17 template <typename WT>
19 : currentId_(-1),
20 targetId_(-1),
21 polymerPtr_(&polymer)
22 {}
23
24 /*
25 * Destructor
26 */
27 template <typename WT>
30
31 /*
32 * Initialize iterator.
33 */
34 template <typename WT>
35 void VertexIterator<WT>::begin(int sourceId, int targetId)
36 {
37 currentId_ = sourceId;
38 targetId_ = targetId;
39 }
40
41 /*
42 * Increment vertex - update current vertex to next one in path.
43 */
44 template <typename WT>
46 {
48 Pair<int> propId = polymerPtr_->path(currentId_, targetId_);
49 int edgeId = propId[0];
50 int dirId = propId[1];
51 UTIL_CHECK(edgeId >= 0);
52 UTIL_CHECK(edgeId < polymerPtr_->nBlock());
53 UTIL_CHECK(dirId >= 0);
54 UTIL_CHECK(dirId < 2);
55 Edge const & edge = polymerPtr_->edge(edgeId);
56 if (dirId == 0) {
57 currentId_ = edge.vertexId(1);
58 } else {
59 currentId_ = edge.vertexId(0);
60 }
61 return *this;
62 }
63
64 /*
65 * Get the current vertex id.
66 */
67 template <typename WT>
69 { return currentId_; }
70
71 /*
72 * Is the current vertex equal to the target:
73 */
74 template <typename WT>
76 {
77 return (bool)( currentId_ == targetId_ );
78 }
79
80 /*
81 * Is the current vertex not equal to the target.
82 */
83 template <typename WT>
85 {
86 return (bool)( currentId_ != targetId_ );
87 }
88
89}
Descriptor for a block within a block polymer.
Definition Edge.h:59
int vertexId(int i) const
Get the id of one associated vertex.
Definition Edge.h:296
Descriptor for a linear or acyclic branched block polymer.
bool notEnd() const
Return true iff currentId != targetId.
int currentId() const
Get index of the current vertex.
VertexIterator & operator++()
Increment operator - move to next vertex.
bool isEnd() const
Return true iff currentId == targetId.
VertexIterator(PolymerSpecies< WT > const &polymer)
Constructor.
~VertexIterator()
Destructor.
void begin(int sourceId, int targetId)
Initialize iterator.
An array of exactly 2 objects.
Definition Pair.h:24
#define UTIL_CHECK(condition)
Assertion macro suitable for serial or parallel production code.
Definition global.h:68
PSCF package top-level namespace.