wowlib
0.0.0
Read & write World of Warcraft client files — a C++26 core
Toggle main menu visibility
Loading...
Searching...
No Matches
fourcc.hpp
Go to the documentation of this file.
1
#pragma once
2
7
8
#include <array>
9
#include <cstdint>
10
#include <string>
11
12
namespace
wowlib::formats
{
14
enum class
FourCCEndian
: std::uint8_t {
18
Reversed
,
19
22
Forward
23
};
24
33
constexpr
std::uint32_t
fourcc
(
const
char
(&cc)[5],
FourCCEndian
endian =
FourCCEndian::Reversed
) {
34
const
auto
b = [&](std::size_t i) {
35
return
static_cast<
std::uint32_t
>
(cc[i]);
36
};
37
return
endian ==
FourCCEndian::Reversed
38
? b(3) | b(2) << 8 | b(1) << 16 | b(0) << 24
39
: b(0) | b(1) << 8 | b(2) << 16 | b(3) << 24;
40
}
41
46
constexpr
std::string
fourccToString
(std::uint32_t
fourcc
,
FourCCEndian
endian =
FourCCEndian::Reversed
) {
47
const
auto
b = [&](
unsigned
shift) {
48
return
static_cast<
char
>
((
fourcc
>> shift) & 0xFF);
49
};
50
return
endian ==
FourCCEndian::Reversed
51
? std::string{b(24), b(16), b(8), b(0)}
52
: std::string{b(0), b(8), b(16), b(24)};
53
}
54
}
wowlib::formats
Definition
adt.hpp:68
wowlib::formats::fourcc
constexpr std::uint32_t fourcc(const char(&cc)[5], FourCCEndian endian=FourCCEndian::Reversed)
The host integer a scanned chunk id compares equal to for code cc.
Definition
fourcc.hpp:33
wowlib::formats::fourccToString
constexpr std::string fourccToString(std::uint32_t fourcc, FourCCEndian endian=FourCCEndian::Reversed)
The readable four-character spelling of a scanned chunk id.
Definition
fourcc.hpp:46
wowlib::formats::FourCCEndian
FourCCEndian
How a chunk's FourCC characters are laid out on disk.
Definition
fourcc.hpp:14
wowlib::formats::FourCCEndian::Reversed
@ Reversed
The characters are stored reversed: 'MVER' appears in the file as the bytes "REVM".
Definition
fourcc.hpp:18
wowlib::formats::FourCCEndian::Forward
@ Forward
The characters are stored as written: 'AFID' appears in the file as the bytes "AFID".
Definition
fourcc.hpp:22
src
wowlib
formats
common
fourcc.hpp
Generated by
1.17.0