Mercurial > hg > svcore
comparison base/ById.h @ 1735:d91ff235e69d by-id
Some messing with Model and AlignmentModel
author | Chris Cannam |
---|---|
date | Tue, 25 Jun 2019 15:29:34 +0100 |
parents | 601851995f4b |
children | d9082ed16931 |
comparison
equal
deleted
inserted
replaced
1733:c3b5564cfb78 | 1735:d91ff235e69d |
---|---|
24 #include <QMutex> | 24 #include <QMutex> |
25 #include <QString> | 25 #include <QString> |
26 | 26 |
27 template <typename T> | 27 template <typename T> |
28 struct SvId { | 28 struct SvId { |
29 | |
29 int id; | 30 int id; |
30 | 31 |
32 enum { | |
33 // The value NO_ID (-1) is never allocated by WithId | |
34 NO_ID = -1 | |
35 }; | |
36 | |
37 SvId() : id(NO_ID) {} | |
38 | |
39 SvId(const SvId &) =default; | |
40 SvId &operator=(const SvId &) =default; | |
41 | |
42 bool operator==(const SvId &other) const { return id == other.id; } | |
31 bool operator<(const SvId &other) const { return id < other.id; } | 43 bool operator<(const SvId &other) const { return id < other.id; } |
44 | |
45 bool isNone() const { return id == NO_ID; } | |
32 | 46 |
33 QString toString() const { | 47 QString toString() const { |
34 return QString("%1").arg(id); | 48 return QString("%1").arg(id); |
35 } | 49 } |
36 }; | 50 }; |
64 static QMutex mutex; | 78 static QMutex mutex; |
65 QMutexLocker locker(&mutex); | 79 QMutexLocker locker(&mutex); |
66 int i = nextId; | 80 int i = nextId; |
67 if (nextId == INT_MAX) { | 81 if (nextId == INT_MAX) { |
68 nextId = INT_MIN; | 82 nextId = INT_MIN; |
83 } else { | |
84 ++nextId; | |
85 if (nextId == 0 || nextId == Id::NO_ID) { | |
86 throw std::runtime_error("Internal ID limit exceeded!"); | |
87 } | |
69 } | 88 } |
70 ++nextId; | |
71 return i; | 89 return i; |
72 } | 90 } |
73 }; | 91 }; |
74 | 92 |
75 template <typename Item, typename Id> | 93 template <typename Item, typename Id> |