Porytiles
Loading...
Searching...
No Matches
palette_index.hpp
Go to the documentation of this file.
1#pragma once
2
3// ReSharper disable once CppUnusedIncludeDirective
4#include <compare>
5#include <cstddef>
6#include <string>
7
9
10namespace porytiles {
11
12inline constexpr std::size_t colors_per_pal = 16;
13
24 public:
25 // NOLINTNEXTLINE(google-explicit-constructor)
26 PaletteIndex(std::size_t value) : value_{value}
27 {
28 if (value >= colors_per_pal) {
29 panic("invalid PaletteIndex value " + std::to_string(value));
30 }
31 }
32
33 auto operator<=>(const PaletteIndex &) const = default;
34
35 // NOLINTNEXTLINE
36 operator const std::size_t &() const &
37 {
38 return value_;
39 }
40
41 // NOLINTNEXTLINE
42 operator std::size_t &&() &&
43 {
44 return std::move(value_);
45 }
46
47 [[nodiscard]] const std::size_t &value() const &
48 {
49 return value_;
50 }
51
52 [[nodiscard]] std::size_t &&value() &&
53 {
54 return std::move(value_);
55 }
56
57 [[nodiscard]] std::size_t index() const
58 {
59 return value_;
60 }
61
62 private:
63 std::size_t value_{};
64};
65
66} // namespace porytiles
Represents a palette index value within a particular palette.
std::size_t && value() &&
const std::size_t & value() const &
std::size_t index() const
auto operator<=>(const PaletteIndex &) const =default
PaletteIndex(std::size_t value)
void panic(const StringViewSourceLoc &s)
Unconditionally terminates the program with a panic message.
Definition panic.cpp:43
constexpr std::size_t colors_per_pal