libpromeki 1.0.0-alpha
PROfessional MEdia toolKIt
 
Loading...
Searching...
No Matches
fourcc.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <promeki/config.h>
11#if PROMEKI_ENABLE_CORE
12#include <cstdint>
13#include <string>
14#include <promeki/namespace.h>
15#include <promeki/list.h>
16
17PROMEKI_NAMESPACE_BEGIN
18
33class FourCC {
34 public:
36 using List = ::promeki::List<FourCC>;
37
45 constexpr FourCC(char c0, char c1, char c2, char c3)
46 : d((static_cast<uint32_t>(c0) << 24) | (static_cast<uint32_t>(c1) << 16) |
47 (static_cast<uint32_t>(c2) << 8) | static_cast<uint32_t>(c3)) {}
48
54 template <size_t N> constexpr FourCC(const char (&str)[N]) : FourCC(str[0], str[1], str[2], str[3]) {
55 static_assert(N == 5, "FourCC string must have exactly 4 characters");
56 }
57
62 constexpr uint32_t value() const { return d; }
63
65 friend constexpr bool operator==(const FourCC &a, const FourCC &b) { return a.d == b.d; }
66
68 friend constexpr bool operator!=(const FourCC &a, const FourCC &b) { return a.d != b.d; }
69
71 friend constexpr bool operator<(const FourCC &a, const FourCC &b) { return a.d < b.d; }
72
74 friend constexpr bool operator>(const FourCC &a, const FourCC &b) { return a.d > b.d; }
75
77 friend constexpr bool operator<=(const FourCC &a, const FourCC &b) { return a.d <= b.d; }
78
80 friend constexpr bool operator>=(const FourCC &a, const FourCC &b) { return a.d >= b.d; }
81
82 private:
83 uint32_t d;
84};
85
86PROMEKI_NAMESPACE_END
87
88#endif // PROMEKI_ENABLE_CORE