Mercurial > hg > svcore
diff 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 |
line wrap: on
line diff
--- a/base/ById.h Mon Jun 24 14:28:17 2019 +0100 +++ b/base/ById.h Tue Jun 25 15:29:34 2019 +0100 @@ -26,10 +26,24 @@ template <typename T> struct SvId { + int id; + enum { + // The value NO_ID (-1) is never allocated by WithId + NO_ID = -1 + }; + + SvId() : id(NO_ID) {} + + SvId(const SvId &) =default; + SvId &operator=(const SvId &) =default; + + bool operator==(const SvId &other) const { return id == other.id; } bool operator<(const SvId &other) const { return id < other.id; } + bool isNone() const { return id == NO_ID; } + QString toString() const { return QString("%1").arg(id); } @@ -66,8 +80,12 @@ int i = nextId; if (nextId == INT_MAX) { nextId = INT_MIN; + } else { + ++nextId; + if (nextId == 0 || nextId == Id::NO_ID) { + throw std::runtime_error("Internal ID limit exceeded!"); + } } - ++nextId; return i; } };