From 9e7661eb7aeaa296b39b53cdb4efe0f158777117 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 15 Aug 2019 06:17:24 -0400 Subject: [PATCH] hecl/FourCC: Make rest of FourCC interface constexpr where applicable Finally, we can make the rest of the interface constexpr, except for toString(). --- hecl/include/hecl/FourCC.hpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/hecl/include/hecl/FourCC.hpp b/hecl/include/hecl/FourCC.hpp index bff7b72d2..8950799d0 100644 --- a/hecl/include/hecl/FourCC.hpp +++ b/hecl/include/hecl/FourCC.hpp @@ -32,22 +32,22 @@ public: constexpr FourCC& operator=(const FourCC&) noexcept = default; constexpr FourCC& operator=(FourCC&&) noexcept = default; - bool operator==(const FourCC& other) const { return num == other.num; } - bool operator!=(const FourCC& other) const { return !operator==(other); } - bool operator==(const char* other) const { - return std::memcmp(fcc, other, sizeof(fcc)) == 0; + constexpr bool operator==(const FourCC& other) const { return num == other.num; } + constexpr bool operator!=(const FourCC& other) const { return !operator==(other); } + constexpr bool operator==(const char* other) const { + return other[0] == fcc[0] && other[1] == fcc[1] && other[2] == fcc[2] && other[3] == fcc[3]; } - bool operator!=(const char* other) const { return !operator==(other); } - bool operator==(int32_t other) const { return num == uint32_t(other); } - bool operator!=(int32_t other) const { return !operator==(other); } - bool operator==(uint32_t other) const { return num == other; } - bool operator!=(uint32_t other) const { return !operator==(other); } + constexpr bool operator!=(const char* other) const { return !operator==(other); } + constexpr bool operator==(int32_t other) const { return num == uint32_t(other); } + constexpr bool operator!=(int32_t other) const { return !operator==(other); } + constexpr bool operator==(uint32_t other) const { return num == other; } + constexpr bool operator!=(uint32_t other) const { return !operator==(other); } std::string toString() const { return std::string(std::begin(fcc), std::end(fcc)); } - uint32_t toUint32() const { return num; } - const char* getChars() const { return fcc; } - char* getChars() { return fcc; } - bool IsValid() const { return num != 0; } + constexpr uint32_t toUint32() const { return num; } + constexpr const char* getChars() const { return fcc; } + constexpr char* getChars() { return fcc; } + constexpr bool IsValid() const { return num != 0; } }; #define FOURCC(chars) FourCC(SBIG(chars))