summaryrefslogtreecommitdiffstats
path: root/source/core/slang-semantic-version.h
diff options
context:
space:
mode:
authorTheresa Foley <10618364+tangent-vector@users.noreply.github.com>2025-05-12 10:28:05 -0700
committerGitHub <noreply@github.com>2025-05-12 17:28:05 +0000
commit4c76b275907cf2d764f3fc51468d1c58635a10c1 (patch)
tree201a353c2b64b258760c370e641821ec5f6eff85 /source/core/slang-semantic-version.h
parent6b286bfbdf85e40cac1ee325384f535df969938a (diff)
Cleanups related to RIFF support (#7041)
Diffstat (limited to 'source/core/slang-semantic-version.h')
-rw-r--r--source/core/slang-semantic-version.h43
1 files changed, 32 insertions, 11 deletions
diff --git a/source/core/slang-semantic-version.h b/source/core/slang-semantic-version.h
index 0bb467ab7..096606e08 100644
--- a/source/core/slang-semantic-version.h
+++ b/source/core/slang-semantic-version.h
@@ -12,7 +12,7 @@ struct SemanticVersion
{
typedef SemanticVersion ThisType;
- typedef uint64_t IntegerType;
+ typedef UInt64 RawValue;
SemanticVersion()
: m_major(0), m_minor(0), m_patch(0)
@@ -34,14 +34,22 @@ struct SemanticVersion
/// All zeros means nothing is set
bool isSet() const { return m_major || m_minor || m_patch; }
- IntegerType toInteger() const
+ RawValue getRawValue() const
{
- return (IntegerType(m_major) << 48) | (IntegerType(m_minor) << 32) | m_patch;
+ return (RawValue(m_major) << 48) | (RawValue(m_minor) << 32) | m_patch;
}
- void setFromInteger(IntegerType v)
+ void setRawValue(RawValue v)
{
set(int(v >> 48), int((v >> 32) & 0xffff), int(v & 0xffffffff));
}
+
+ static SemanticVersion fromRaw(RawValue rawValue)
+ {
+ SemanticVersion result;
+ result.setRawValue(rawValue);
+ return result;
+ }
+
void set(int major, int minor, int patch = 0)
{
SLANG_ASSERT(major >= 0 && minor >= 0 && patch >= 0);
@@ -52,7 +60,7 @@ struct SemanticVersion
}
/// Get hash value
- HashCode getHashCode() const { return Slang::getHashCode(toInteger()); }
+ HashCode getHashCode() const { return Slang::getHashCode(getRawValue()); }
static SlangResult parse(const UnownedStringSlice& value, SemanticVersion& outVersion);
static SlangResult parse(
@@ -63,16 +71,29 @@ struct SemanticVersion
static ThisType getEarliest(const ThisType* versions, Count count);
static ThisType getLatest(const ThisType* versions, Count count);
+ /// Determine if this version is backwards-compatible with `otherVersion`.
+ ///
+ /// Examples of when to apply this:
+ ///
+ /// * Code for this version is asked to load data produced by `otherVersion`.
+ ///
+ /// * Code for this version is asked if it provides the API of `otherVersion`.
+ ///
+ /// This uses the rules of semantic versioning, so it should only
+ /// be applied to versions that obey those rules.
+ ///
+ bool isBackwardsCompatibleWith(const ThisType& otherVersion) const;
+
void append(StringBuilder& buf) const;
- bool operator>(const ThisType& rhs) const { return toInteger() > rhs.toInteger(); }
- bool operator>=(const ThisType& rhs) const { return toInteger() >= rhs.toInteger(); }
+ bool operator>(const ThisType& rhs) const { return getRawValue() > rhs.getRawValue(); }
+ bool operator>=(const ThisType& rhs) const { return getRawValue() >= rhs.getRawValue(); }
- bool operator<(const ThisType& rhs) const { return toInteger() < rhs.toInteger(); }
- bool operator<=(const ThisType& rhs) const { return toInteger() <= rhs.toInteger(); }
+ bool operator<(const ThisType& rhs) const { return getRawValue() < rhs.getRawValue(); }
+ bool operator<=(const ThisType& rhs) const { return getRawValue() <= rhs.getRawValue(); }
- bool operator==(const ThisType& rhs) const { return toInteger() == rhs.toInteger(); }
- bool operator!=(const ThisType& rhs) const { return toInteger() != rhs.toInteger(); }
+ bool operator==(const ThisType& rhs) const { return getRawValue() == rhs.getRawValue(); }
+ bool operator!=(const ThisType& rhs) const { return getRawValue() != rhs.getRawValue(); }
uint16_t m_major;
uint16_t m_minor;