comparison base/EventSeries.cpp @ 1798:13bd41bd8a17

Some work on making Model classes thread-safe in typical use - and documenting this. Some of the implementations are simpler now that EventSeries is thread-safe
author Chris Cannam
date Tue, 01 Oct 2019 11:22:48 +0100
parents ff8c57c364a0
children c546429d4c2f
comparison
equal deleted inserted replaced
1797:e8b552549225 1798:13bd41bd8a17
542 542
543 Event 543 Event
544 EventSeries::getEventByIndex(int index) const 544 EventSeries::getEventByIndex(int index) const
545 { 545 {
546 QMutexLocker locker(&m_mutex); 546 QMutexLocker locker(&m_mutex);
547 547 if (!in_range_for(m_events, index)) {
548 if (index < 0 || index >= count()) {
549 throw std::logic_error("index out of range"); 548 throw std::logic_error("index out of range");
550 } 549 }
551 return m_events[index]; 550 return m_events[index];
552 } 551 }
553 552
554 int 553 int
555 EventSeries::getIndexForEvent(const Event &e) const 554 EventSeries::getIndexForEvent(const Event &e) const
556 { 555 {
557 QMutexLocker locker(&m_mutex); 556 QMutexLocker locker(&m_mutex);
558
559 auto pitr = lower_bound(m_events.begin(), m_events.end(), e); 557 auto pitr = lower_bound(m_events.begin(), m_events.end(), e);
560 auto d = distance(m_events.begin(), pitr); 558 auto d = distance(m_events.begin(), pitr);
561 if (d < 0 || d > INT_MAX) return 0; 559 if (d < 0 || d > INT_MAX) return 0;
562 return int(d); 560 return int(d);
563 } 561 }