hecl/FourCC: Tidy up constructors

Marks constructors as noexcept and explicitly defaults the copy
constructor/assignment and move constructor/assignment.
This commit is contained in:
Lioncash 2019-08-15 05:28:09 -04:00
parent 9dc1373201
commit 0f74cce2ca
1 changed files with 12 additions and 6 deletions

View File

@ -18,15 +18,20 @@ class FourCC {
protected: protected:
union { union {
char fcc[4]; char fcc[4];
uint32_t num; uint32_t num = 0;
}; };
public: public:
constexpr FourCC() /* Sentinel FourCC */ // Sentinel FourCC
: num(0) {} constexpr FourCC() noexcept = default;
constexpr FourCC(const FourCC& other) : num(other.num) {} constexpr FourCC(const FourCC& other) noexcept = default;
constexpr FourCC(const char* name) : num(*(uint32_t*)name) {} constexpr FourCC(FourCC&& other) noexcept = default;
constexpr FourCC(uint32_t n) : num(n) {} constexpr FourCC(const char* name) noexcept : num(*(uint32_t*)name) {}
constexpr FourCC(uint32_t n) noexcept : num(n) {}
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 num == other.num; }
bool operator!=(const FourCC& other) const { return num != other.num; } bool operator!=(const FourCC& other) const { return num != other.num; }
bool operator==(const char* other) const { return num == *(uint32_t*)other; } bool operator==(const char* other) const { return num == *(uint32_t*)other; }
@ -35,6 +40,7 @@ public:
bool operator!=(int32_t other) const { return num != uint32_t(other); } bool operator!=(int32_t other) const { return num != uint32_t(other); }
bool operator==(uint32_t other) const { return num == other; } bool operator==(uint32_t other) const { return num == other; }
bool operator!=(uint32_t other) const { return num != other; } bool operator!=(uint32_t other) const { return num != other; }
std::string toString() const { return std::string(fcc, 4); } std::string toString() const { return std::string(fcc, 4); }
uint32_t toUint32() const { return num; } uint32_t toUint32() const { return num; }
const char* getChars() const { return fcc; } const char* getChars() const { return fcc; }