comparison base/Event.h @ 1627:1c21ddac220e single-point

Seems we can do just as well with a vector of events themselves
author Chris Cannam
date Mon, 11 Mar 2019 14:49:13 +0000
parents 895186c43fce
children abc188026a48
comparison
equal deleted inserted replaced
1626:895186c43fce 1627:1c21ddac220e
277 h ^= qHash(m_frame); 277 h ^= qHash(m_frame);
278 h ^= qHash(m_duration); 278 h ^= qHash(m_duration);
279 if (m_haveReferenceFrame) h ^= qHash(m_referenceFrame); 279 if (m_haveReferenceFrame) h ^= qHash(m_referenceFrame);
280 return h; 280 return h;
281 } 281 }
282
283 static sv_id_t getId(const Event &ev) {
284 sv_id_t id;
285 if (!m_ids.contains(ev)) {
286 id = m_nextId;
287 ++m_nextId;
288 m_ids[ev] = id;
289 m_rids[id] = ev;
290 return id;
291 } else {
292 return m_ids.value(ev);
293 }
294 }
295
296 static Event getEventForId(sv_id_t id) {
297 if (!m_rids.contains(id)) {
298 throw std::runtime_error("unknown event id");
299 } else {
300 return m_rids.value(id);
301 }
302 }
303 282
304 private: 283 private:
305 // The order of fields here is chosen to minimise overall size of struct. 284 // The order of fields here is chosen to minimise overall size of struct.
306 // We potentially store very many of these objects. 285 // We potentially store very many of these objects.
307 // If you change something, check what difference it makes to packing. 286 // If you change something, check what difference it makes to packing.
312 float m_level; 291 float m_level;
313 sv_frame_t m_frame; 292 sv_frame_t m_frame;
314 sv_frame_t m_duration; 293 sv_frame_t m_duration;
315 sv_frame_t m_referenceFrame; 294 sv_frame_t m_referenceFrame;
316 QString m_label; 295 QString m_label;
317
318 static sv_id_t m_nextId;
319 static QHash<Event, sv_id_t> m_ids;
320 static QHash<sv_id_t, Event> m_rids;
321 }; 296 };
322 297
323 inline uint qHash(const Event &e, uint seed = 0) { 298 inline uint qHash(const Event &e, uint seed = 0) {
324 return e.hash(seed); 299 return e.hash(seed);
325 } 300 }