# HG changeset patch # User Chris Cannam # Date 1536057095 -3600 # Node ID a250a54c11cc4350475096002076b7a6899ec792 # Parent d7fdc77252c69239cad4077672a478cd4636b2ca# Parent 9d37c8cf96860cb5dea530cad363b42f18598f11 Merge from branch avoid-pointer-keys diff -r d7fdc77252c6 -r a250a54c11cc data/model/Model.cpp --- a/data/model/Model.cpp Mon Sep 03 16:15:03 2018 +0100 +++ b/data/model/Model.cpp Tue Sep 04 11:31:35 2018 +0100 @@ -40,6 +40,20 @@ } } +int +Model::getNextId() +{ + static int nextId = 0; + static QMutex mutex; + QMutexLocker locker(&mutex); + int i = nextId; + if (nextId == INT_MAX) { + nextId = INT_MIN; + } + ++nextId; + return i; +} + void Model::setSourceModel(Model *model) { diff -r d7fdc77252c6 -r a250a54c11cc data/model/Model.h --- a/data/model/Model.h Mon Sep 03 16:15:03 2018 +0100 +++ b/data/model/Model.h Tue Sep 04 11:31:35 2018 +0100 @@ -13,8 +13,8 @@ COPYING included with this distribution for more information. */ -#ifndef _MODEL_H_ -#define _MODEL_H_ +#ifndef SV_MODEL_H +#define SV_MODEL_H #include #include @@ -27,6 +27,8 @@ class ZoomConstraint; class AlignmentModel; +typedef int ModelId; + /** * Model is the base class for all data models that represent any sort * of data on a time scale based on an audio frame rate. @@ -98,6 +100,13 @@ * Return true if this is a sparse model. */ virtual bool isSparse() const { return false; } + + /** + * Return an id for this model. The id is guaranteed to be a + * unique identifier for this model among all models that may ever + * exist within this single run of the application. + */ + ModelId getId() const { return m_id; } /** * Mark the model as abandoning. This means that the application @@ -291,7 +300,8 @@ void aboutToBeDeleted(); protected: - Model() : + Model() : + m_id(getNextId()), m_sourceModel(0), m_alignment(0), m_abandoning(false), @@ -301,11 +311,14 @@ Model(const Model &); Model &operator=(const Model &); + const ModelId m_id; Model *m_sourceModel; AlignmentModel *m_alignment; QString m_typeUri; bool m_abandoning; bool m_aboutToDelete; + + int getNextId(); }; #endif