2
0
mirror of https://github.com/AxioDL/metaforce.git synced 2025-07-01 22:53:32 +00:00

hecl/FourCC: Eliminate magic values in DNAFourCC

This commit is contained in:
Lioncash 2019-08-15 06:06:53 -04:00
parent 1382bbf365
commit 2f9010bc9f

View File

@ -43,7 +43,7 @@ public:
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 !operator==(other); } bool operator!=(uint32_t other) const { return !operator==(other); }
std::string toString() const { return std::string(fcc, 4); } std::string toString() const { return std::string(std::begin(fcc), std::end(fcc)); }
uint32_t toUint32() const { return num; } uint32_t toUint32() const { return num; }
const char* getChars() const { return fcc; } const char* getChars() const { return fcc; }
char* getChars() { return fcc; } char* getChars() { return fcc; }
@ -63,25 +63,25 @@ public:
AT_DECL_EXPLICIT_DNA_YAML AT_DECL_EXPLICIT_DNA_YAML
}; };
template <> template <>
inline void DNAFourCC::Enumerate<BigDNA::Read>(typename Read::StreamT& r) { inline void DNAFourCC::Enumerate<BigDNA::Read>(Read::StreamT& r) {
r.readUBytesToBuf(fcc, 4); r.readUBytesToBuf(fcc, std::size(fcc));
} }
template <> template <>
inline void DNAFourCC::Enumerate<BigDNA::Write>(typename Write::StreamT& w) { inline void DNAFourCC::Enumerate<BigDNA::Write>(Write::StreamT& w) {
w.writeUBytes((atUint8*)fcc, 4); w.writeBytes(fcc, std::size(fcc));
} }
template <> template <>
inline void DNAFourCC::Enumerate<BigDNA::ReadYaml>(typename ReadYaml::StreamT& r) { inline void DNAFourCC::Enumerate<BigDNA::ReadYaml>(ReadYaml::StreamT& r) {
std::string rs = r.readString(nullptr); const std::string rs = r.readString(nullptr);
strncpy(fcc, rs.c_str(), 4); rs.copy(fcc, std::size(fcc));
} }
template <> template <>
inline void DNAFourCC::Enumerate<BigDNA::WriteYaml>(typename WriteYaml::StreamT& w) { inline void DNAFourCC::Enumerate<BigDNA::WriteYaml>(WriteYaml::StreamT& w) {
w.writeString(nullptr, std::string(fcc, 4)); w.writeString(nullptr, std::string_view{fcc, std::size(fcc)});
} }
template <> template <>
inline void DNAFourCC::Enumerate<BigDNA::BinarySize>(typename BinarySize::StreamT& s) { inline void DNAFourCC::Enumerate<BigDNA::BinarySize>(BinarySize::StreamT& s) {
s += 4; s += std::size(fcc);
} }
} // namespace hecl } // namespace hecl