Mercurial > hg > svcore
comparison base/EventSeries.cpp @ 1632:0890c10e5129 single-point
Add some more handy methods
author | Chris Cannam |
---|---|
date | Tue, 12 Mar 2019 14:52:11 +0000 |
parents | b2048f350906 |
children | 6ac92836cd86 |
comparison
equal
deleted
inserted
replaced
1631:b2048f350906 | 1632:0890c10e5129 |
---|---|
22 | 22 |
23 int | 23 int |
24 EventSeries::count() const | 24 EventSeries::count() const |
25 { | 25 { |
26 if (m_events.size() > INT_MAX) { | 26 if (m_events.size() > INT_MAX) { |
27 throw std::runtime_error("too many events"); | 27 throw std::logic_error("too many events"); |
28 } | 28 } |
29 return int(m_events.size()); | 29 return int(m_events.size()); |
30 } | 30 } |
31 | 31 |
32 void | 32 void |
269 } | 269 } |
270 | 270 |
271 return cover; | 271 return cover; |
272 } | 272 } |
273 | 273 |
274 bool | |
275 EventSeries::getEventPreceding(const Event &e, Event &preceding) const | |
276 { | |
277 auto pitr = lower_bound(m_events.begin(), m_events.end(), e); | |
278 if (pitr == m_events.end() || *pitr != e) { | |
279 return false; | |
280 } | |
281 if (pitr == m_events.begin()) { | |
282 return false; | |
283 } | |
284 --pitr; | |
285 preceding = *pitr; | |
286 return true; | |
287 } | |
288 | |
289 bool | |
290 EventSeries::getEventFollowing(const Event &e, Event &following) const | |
291 { | |
292 auto pitr = lower_bound(m_events.begin(), m_events.end(), e); | |
293 if (pitr == m_events.end() || *pitr != e) { | |
294 return false; | |
295 } | |
296 ++pitr; | |
297 if (pitr == m_events.end()) { | |
298 return false; | |
299 } | |
300 following = *pitr; | |
301 return true; | |
302 } | |
303 | |
304 Event | |
305 EventSeries::getEventByIndex(int index) const | |
306 { | |
307 if (index < 0 || index >= count()) { | |
308 throw std::logic_error("index out of range"); | |
309 } | |
310 return m_events[index]; | |
311 } | |
312 | |
274 void | 313 void |
275 EventSeries::toXml(QTextStream &out, | 314 EventSeries::toXml(QTextStream &out, |
276 QString indent, | 315 QString indent, |
277 QString extraAttributes) const | 316 QString extraAttributes) const |
278 { | 317 { |