Porytiles
Loading...
Searching...
No Matches
color_set.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <bitset>
4#include <cstddef>
5#include <functional>
6#include <string>
7
9
10namespace porytiles2 {
11
19class ColorSet {
20 public:
21 ColorSet() = default;
22
32 [[nodiscard]] bool test(ColorIndex index) const;
33
43 void set(ColorIndex index, bool value = true);
44
53 void reset(ColorIndex index);
54
63 [[nodiscard]] const std::bitset<num_colors> &colors() const
64 {
65 return colors_;
66 }
67
77 [[nodiscard]] bool operator==(const ColorSet &other) const = default;
78
79 private:
80 // TODO: define this in terms of num_pals * colors_per_pal (i.e. 16 * 15)
81 std::bitset<num_colors> colors_;
82};
83
84} // namespace porytiles2
85
93template <>
94struct std::hash<porytiles2::ColorSet> {
104 [[nodiscard]] std::size_t operator()(const porytiles2::ColorSet &color_set) const noexcept
105 {
106 return std::hash<std::string>{}(color_set.colors().to_string());
107 }
108};
Represents a color index value for palette operations.
A set of colors represented as a bitset.
Definition color_set.hpp:19
const std::bitset< num_colors > & colors() const
Gets the underlying bitset.
Definition color_set.hpp:63
bool test(ColorIndex index) const
Tests whether a bit at the given index is set.
Definition color_set.cpp:5
void reset(ColorIndex index)
Resets a bit at the given index to false.
Definition color_set.cpp:15
void set(ColorIndex index, bool value=true)
Sets a bit at the given index.
Definition color_set.cpp:10
bool operator==(const ColorSet &other) const =default
Compares two ColorSet objects for equality.
std::size_t operator()(const porytiles2::ColorSet &color_set) const noexcept
Computes the hash value for a ColorSet.