New Repository

Had my private email in a old commit of the first repository
This commit is contained in:
n0ffie 2024-10-28 00:33:32 +01:00
commit f25d3cc8da
20 changed files with 6534 additions and 0 deletions

34
include/flagman.hpp Normal file
View file

@ -0,0 +1,34 @@
#pragma once
#include "types.hpp"
template <typename EnumType>
class FlagManager
{
EnumType flags;
public:
static constexpr size_t size = sizeof(EnumType) * 8;
FlagManager(EnumType flags) : flags(flags) {}
[[nodiscard]]
bool get(EnumType flag) const { return (flags & flag) == flag; }
void set(EnumType flag) { flags |= flag; }
void clear(EnumType flag) { flags &= ~flag; }
void toggle(EnumType flag) { flags ^= flag; }
[[nodiscard]]
bool any() const { return flags; }
void set_all() { flags = EnumType(-1); }
void clear_all() { flags = 0; }
bool operator==(const FlagManager& other) const { return flags == other.flags; }
bool operator!=(const FlagManager& other) const { return flags != other.flags; }
// return true if every bit in *this is set in other
bool of(FlagManager& other) const { return (flags & other.flags) == flags; }
// return true if every bit in *this is set in other
bool of(EnumType other) const { return (flags & other) == flags; }
};
template <typename EnumType>
using Flagman = FlagManager<EnumType>;