GData_iterator.cpp
7.31 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
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
177
178
179
180
181
/***************************************************************************
* GData_iterator.cpp - Iterator class of data class *
* ----------------------------------------------------------------------- *
* copyright (C) 2009 by Jurgen Knodlseder *
* ----------------------------------------------------------------------- *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* ----------------------------------------------------------------------- *
***************************************************************************/
/**
* @file GData_iterator.cpp
* @brief GData::iterator class implementation.
* @author J. Knodlseder
*/
/* __ Includes ___________________________________________________________ */
#include "GData.hpp"
/* __ Method name definitions ____________________________________________ */
/* __ Macros _____________________________________________________________ */
/* __ Coding definitions _________________________________________________ */
/* __ Debug definitions __________________________________________________ */
/*==========================================================================
= =
= GData::iterator constructors/destructors =
= =
==========================================================================*/
/***********************************************************************//**
* @brief Void iterator constructor
***************************************************************************/
GData::iterator::iterator()
{
// Initialise iterator
m_data = NULL;
m_index = 0;
m_obs = NULL;
m_event = GEvents::iterator();
m_end = GEvents::iterator();
// Return
return;
}
/***********************************************************************//**
* @brief Iterator constructor based on specific GData object
***************************************************************************/
GData::iterator::iterator(GData *data)
{
// Initialise iterator
m_data = data;
m_index = 0;
m_obs = NULL;
m_event = GEvents::iterator();
m_end = GEvents::iterator();
// Return
return;
}
/*==========================================================================
= =
= GData::iterator operators =
= =
==========================================================================*/
/***********************************************************************//**
* @brief Iterator prefix operator
*
* The iterator skips any empty observations (i.e. NULL observation pointer)
* and all observations with 0 events.
***************************************************************************/
GData::iterator& GData::iterator::operator++(void)
{
// Only iterate if we have a valid data pointer
if (m_data != NULL) {
// Increment event iterator
m_event++;
// If end of observation is reached then set iterator to first event of
// next valid observation
if (m_event == m_end) {
// Find next valid observation
while (m_index < m_data->m_num) {
// Go to next observation
m_index++;
// If we still have an observation then set now the iterator
// to the first event from this observation ...
if (m_index < m_data->m_num) {
// Get next observation. Skip if empty
m_obs = m_data->m_obs[m_index];
if (m_obs == NULL)
continue;
// Skip observation if it contains no events
if (m_obs->events() == NULL)
continue;
// Set iterator to first event of current observation. Exit
// only if we have events in that observation
m_event = m_obs->events()->begin();
m_end = m_obs->events()->end();
if (m_event != m_end)
break;
} // endif: we still had an observation
} // endwhile: searched for next valid observation
// If observations are exhausted then set iterator to signal the end
if (m_index >= m_data->m_num) {
m_index = m_data->m_num;
m_obs = NULL;
m_event = GEvents::iterator();
m_end = GEvents::iterator();
}
} // endif: end of observation has been reached
} // endif: we had a valid data pointer
// Return
return *this;
}
/***********************************************************************//**
* @brief Iterator postfix operator
***************************************************************************/
GData::iterator GData::iterator::operator++(int junk)
{
// Save actual iterator
GData::iterator actual = *this;
// Increment using prefix iterator
++(*this);
// Return actual iterator
return actual;
}
/*==========================================================================
= =
= GData::iterator public methods =
= =
==========================================================================*/
/*==========================================================================
= =
= GData::iterator private methods =
= =
==========================================================================*/
/*==========================================================================
= =
= GData::iterator friends =
= =
==========================================================================*/
/*==========================================================================
= =
= Other functions used by GData::iterator =
= =
==========================================================================*/