2022-09-05 04:24:50 -04:00
|
|
|
//
|
2022-09-05 20:59:46 -04:00
|
|
|
// EuropaTools
|
2022-09-05 04:24:50 -04:00
|
|
|
//
|
2025-01-07 14:17:50 -05:00
|
|
|
// (C) 2021-2025 modeco80 <lily.modeco80@protonmail.ch>
|
2022-09-05 04:24:50 -04:00
|
|
|
//
|
2025-01-07 18:02:27 -05:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-09-05 04:24:50 -04:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef EUROPA_FOURCC_H
|
|
|
|
#define EUROPA_FOURCC_H
|
|
|
|
|
2022-09-07 05:07:40 -04:00
|
|
|
#include <bit>
|
2022-09-21 03:59:16 -04:00
|
|
|
#include <europa/util/FixedString.hpp>
|
2022-09-07 05:07:40 -04:00
|
|
|
|
2022-09-05 04:24:50 -04:00
|
|
|
namespace europa::util {
|
|
|
|
|
2025-01-15 21:59:07 -05:00
|
|
|
/// Compile-time endian-safe FourCC.
|
2022-09-07 05:07:40 -04:00
|
|
|
template <FixedString fccString, std::endian Endian = std::endian::little>
|
2022-09-05 04:24:50 -04:00
|
|
|
consteval std::uint32_t FourCC() {
|
2025-01-15 21:59:07 -05:00
|
|
|
// FIXME: It may be useful to *optionally* add policy support
|
|
|
|
// some FourCC clients prefer '\0' padding, some prefer ' ' (0x20) padding
|
|
|
|
// Idk. Pretty useless here though so idk
|
2022-09-05 04:24:50 -04:00
|
|
|
static_assert(fccString.Length() == 4, "Provided string is not a FourCC");
|
|
|
|
|
|
|
|
switch(Endian) {
|
|
|
|
case std::endian::little:
|
|
|
|
return (fccString[0]) | (fccString[1] << 8) | (fccString[2] << 16) | (fccString[3] << 24);
|
|
|
|
|
|
|
|
case std::endian::big:
|
|
|
|
return (fccString[0] << 24) | (fccString[1] << 16) | (fccString[2] << 8) | fccString[3];
|
|
|
|
}
|
|
|
|
|
2025-01-15 21:59:07 -05:00
|
|
|
// If the user provided an invalid case, do something which is
|
|
|
|
// constexpr-unsafe to indicate user error.
|
|
|
|
throw 0xffffffff; // You passed an invalid Endian to FourCC()?
|
2022-09-05 04:24:50 -04:00
|
|
|
}
|
|
|
|
|
2022-09-07 05:07:40 -04:00
|
|
|
} // namespace europa::util
|
2022-09-05 04:24:50 -04:00
|
|
|
|
|
|
|
#endif // EUROPA_FOURCC_H
|