comparison data/model/Model.h @ 1731:601851995f4b by-id

Introduce Model to ById
author Chris Cannam
date Fri, 21 Jun 2019 13:37:00 +0100
parents 78fe29adfd16
children 87b4c596c0ef
comparison
equal deleted inserted replaced
1729:abd8b9673028 1731:601851995f4b
17 #define SV_MODEL_H 17 #define SV_MODEL_H
18 18
19 #include <vector> 19 #include <vector>
20 #include <QObject> 20 #include <QObject>
21 21
22 #include "base/ById.h"
22 #include "base/XmlExportable.h" 23 #include "base/XmlExportable.h"
23 #include "base/Playable.h" 24 #include "base/Playable.h"
24 #include "base/BaseTypes.h" 25 #include "base/BaseTypes.h"
25 #include "base/DataExportOptions.h" 26 #include "base/DataExportOptions.h"
26 27
27 class ZoomConstraint; 28 class ZoomConstraint;
28 class AlignmentModel; 29 class AlignmentModel;
29 30
30 typedef int ModelId;
31
32 /** 31 /**
33 * Model is the base class for all data models that represent any sort 32 * Model is the base class for all data models that represent any sort
34 * of data on a time scale based on an audio frame rate. 33 * of data on a time scale based on an audio frame rate.
35 */ 34 */
36
37 class Model : public QObject, 35 class Model : public QObject,
36 public WithId<Model>,
38 public XmlExportable, 37 public XmlExportable,
39 public Playable 38 public Playable
40 { 39 {
41 Q_OBJECT 40 Q_OBJECT
42 41
130 * Return true if this is a sparse model. 129 * Return true if this is a sparse model.
131 */ 130 */
132 virtual bool isSparse() const { return false; } 131 virtual bool isSparse() const { return false; }
133 132
134 /** 133 /**
135 * Return an id for this model. The id is guaranteed to be a
136 * unique identifier for this model among all models that may ever
137 * exist within this single run of the application.
138 */
139 ModelId getId() const { return m_id; }
140
141 /**
142 * Mark the model as abandoning. This means that the application 134 * Mark the model as abandoning. This means that the application
143 * no longer needs it, so it can stop doing any background 135 * no longer needs it, so it can stop doing any background
144 * calculations it may be involved in. Note that as far as the 136 * calculations it may be involved in. Note that as far as the
145 * model API is concerned, this does nothing more than tell the 137 * model API is concerned, this does nothing more than tell the
146 * model to return true from isAbandoning(). The actual response 138 * model to return true from isAbandoning(). The actual response
337 */ 329 */
338 void aboutToBeDeleted(); 330 void aboutToBeDeleted();
339 331
340 protected: 332 protected:
341 Model() : 333 Model() :
342 m_id(getNextId()),
343 m_sourceModel(0), 334 m_sourceModel(0),
344 m_alignment(0), 335 m_alignment(0),
345 m_abandoning(false), 336 m_abandoning(false),
346 m_aboutToDelete(false), 337 m_aboutToDelete(false),
347 m_extendTo(0) { } 338 m_extendTo(0) { }
348 339
349 // Not provided. 340 // Not provided.
350 Model(const Model &); 341 Model(const Model &);
351 Model &operator=(const Model &); 342 Model &operator=(const Model &);
352 343
353 const ModelId m_id;
354 Model *m_sourceModel; 344 Model *m_sourceModel;
355 AlignmentModel *m_alignment; 345 AlignmentModel *m_alignment;
356 QString m_typeUri; 346 QString m_typeUri;
357 bool m_abandoning; 347 bool m_abandoning;
358 bool m_aboutToDelete; 348 bool m_aboutToDelete;
359 sv_frame_t m_extendTo; 349 sv_frame_t m_extendTo;
360
361 int getNextId();
362 }; 350 };
363 351
352 typedef Model::Id ModelId;
353 typedef StaticById<Model, ModelId> ModelById;
354
364 #endif 355 #endif