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 | //StiKTNIterator.h
//M.L. Miller (Yale Software)
//12/01
/*! \class StiKTNIterator
This class is an STL compliant forward iterator that will traverse from
the leaf of a tree upward to a root.
\author M.L. Miller (Yale Software)
\note We use the defualt copy/assignment generated by compiler.
\note Singularity (i.e., 'end') is represented by setting mNode=0.
\note StiKTNIterator is a non-virtual class.
*/
#ifndef StiKTNIterator_HH
#define StiKTNIterator_HH
#include <assert.h>
#include "StiKalmanTrackNode.h"
typedef StiKalmanTrackNode KTN_t;
class StiKTNIterator;
typedef StiKTNIterator StiKTNBidirectionalIterator;
//This is a temp hack to get around old gcc ansi-non-compliant STL implementation
class StiKTNIterator
{
public:
///ctr-dstr
StiKTNIterator(KTN_t* leaf=0,int dir=0) : mDir(dir),mNode( leaf) {};
StiKTNIterator(KTN_t& leaf ,int dir=0) : mDir(dir),mNode(&leaf) {};
StiKTNIterator begin();
StiKTNIterator rbegin();
///equality:
bool operator==(const StiKTNIterator& rhs) const;
///inequlity
bool operator!=(const StiKTNIterator& rhs) const;
////Dereference
KTN_t& operator*();
KTN_t* operator()();
///prefix
StiKTNIterator& operator++ ();
///postfix
StiKTNIterator operator++(int);
///prefix
StiKTNIterator& operator-- ();
///postfix
StiKTNIterator operator--(int);
///We demarcate the end of the traversal via a singular iterator
static const StiKTNIterator& end();
static const StiKTNIterator& rend();
static StiKTNIterator begin(KTN_t* fist);
static StiKTNIterator rbegin(KTN_t* last);
private:
int mDir;
KTN_t* mNode;
};
class StiKTNForwardIterator: public StiKTNIterator{
public:
StiKTNForwardIterator(KTN_t* leaf=0) : StiKTNIterator(leaf,1){};
StiKTNForwardIterator(KTN_t& leaf ) : StiKTNIterator(leaf,1){};
static const StiKTNForwardIterator& end();
};
//inlines --
inline bool StiKTNIterator::operator==(const StiKTNIterator& rhs) const
{
return mNode==rhs.mNode;
}
inline bool StiKTNIterator::operator!=(const StiKTNIterator& rhs) const
{
return !(mNode==rhs.mNode);
}
inline KTN_t& StiKTNIterator::operator*()
{
return *mNode;
}
inline KTN_t* StiKTNIterator::operator()()
{
return mNode;
}
//prefix
/*! In the case where the prefix operator increments beyond the root of the tree,
the pointer to mNode is set to 0. This demarcates the end of the traversal.
*/
inline StiKTNIterator& StiKTNIterator::operator-- ()
{
mDir = !mDir;
++(*this);
mDir = !mDir;
return *this;
}
//postfix
/*! In the case where the prefix operator increments beyond the root of the tree,
the pointer to mNode is set to 0. This demarcates the end of the traversal.
*/
inline StiKTNIterator StiKTNIterator::operator++(int)
{
StiKTNIterator temp = *this;
++(*this);
return temp;<--- Reference to auto variable returned.
}
//prefix
/*! In the case where the prefix operator increments beyond the last leaf of the tree,
the pointer to mNode is set to -. This demarcates the end of traversal.
*/
inline StiKTNIterator& StiKTNIterator::operator++ ()
{
assert(mNode);
if(!mDir) { //forward direction
mNode = static_cast<KTN_t*>(mNode->getNextNode());
} else { //backward direction
mNode = static_cast<KTN_t*>(mNode->getPrevNode());
}
return *this;
}
//postfix decrement
/*! In the case where the prefix operator increments beyond the root of the tree,
the pointer to mNode is set to 0. This demarcates the end of the traversal.
*/
inline StiKTNIterator StiKTNIterator::operator--(int)
{
StiKTNIterator temp = *this;
--(*this);
return temp;
}
inline StiKTNIterator StiKTNIterator::begin(KTN_t* fist)
{
return StiKTNIterator(fist,0);
}
inline StiKTNIterator StiKTNIterator::rbegin(KTN_t* last)
{
return StiKTNIterator(last,1);
}
inline StiKTNIterator StiKTNIterator::begin()
{
assert(mNode);
KTN_t* fist = (KTN_t*)mNode->getFirstNode();
return StiKTNIterator(fist,0);
}
inline StiKTNIterator StiKTNIterator::rbegin()
{
assert(mNode);
KTN_t* last = (KTN_t*)mNode->getLastNode();
return StiKTNIterator(last,1);
}
#endif
|