aboutsummaryrefslogtreecommitdiff
path: root/core/src/Utils/Enum.hpp
diff options
context:
space:
mode:
authorrtk0c <[email protected]>2021-03-31 20:19:18 -0700
committerrtk0c <[email protected]>2021-03-31 20:19:18 -0700
commit44f5fa5c8f258e8fc1f7d7e2e45e0485bd6cc490 (patch)
tree3f09a1cce46d38f5a8c6266150e67af3802d4b95 /core/src/Utils/Enum.hpp
parent31950890c939862f79c817053c106bf711c63a64 (diff)
Complete items tab (UI and serialization)
Diffstat (limited to 'core/src/Utils/Enum.hpp')
-rw-r--r--core/src/Utils/Enum.hpp164
1 files changed, 82 insertions, 82 deletions
diff --git a/core/src/Utils/Enum.hpp b/core/src/Utils/Enum.hpp
index 5075155..e774b01 100644
--- a/core/src/Utils/Enum.hpp
+++ b/core/src/Utils/Enum.hpp
@@ -1,82 +1,82 @@
-#pragma once
-
-#include <compare>
-
-template <class TSelf>
-struct BasicEnum {
- using Self = TSelf;
- using ValueType = int;
-
- int value;
-
- BasicEnum()
- : value{ 0 } {}
- BasicEnum(int value)
- : value{ value } {}
-
- /// Comparsion between 2 values of enum. Useful for situations like `a == b` where both a and b are TSelf.
- friend auto operator<=>(const TSelf& a, const TSelf& b) { return a.value <=> b.value; }
- /// Comparsion between a enum and a raw value. Useful for situations like `a == TSelf::Option` where a is a enum and TSelf::Option is a raw value.
- friend auto operator<=>(const TSelf& self, int value) { return self.value <=> value; }
-
- operator int() const { return value; }
- operator bool() const { return value; }
-};
-
-#define ENUM(Name) struct Name : public BasicEnum<Name>
-#define ENUM_MEMBERS() \
- enum Enum : int; \
- operator Enum() const { return (Enum)value; } \
- using BasicEnum<Self>::BasicEnum; \
- enum Enum : int
-
-template <class TSelf>
-struct BasicFlag {
- using Self = TSelf;
- using ValueType = int;
-
- int value;
-
- BasicFlag()
- : value{ 0 } {}
- BasicFlag(int value)
- : value{ value } {}
-
- bool IsSet(TSelf mask) const { return (value & mask.value) == mask.value; }
- bool IsSetExclusive(TSelf mask) const { return value == mask.value; }
- void Set(TSelf mask, bool state) {
- if (state) {
- value = (int)(value | mask.value);
- } else {
- value = (int)(value & ~mask.value);
- }
- }
-
- /// Comparsion between 2 values of flag. Useful for situations like `a == b` where both a and b are TSelf.
- friend bool operator==(const TSelf& a, const TSelf& b) { return a.value == b.value; }
- friend auto operator<=>(const TSelf& a, const TSelf& b) { return a.value <=> b.value; }
- /// Comparsion between a flag and a raw value. Useful for situations like `a == TSelf::Option` where a is a flag and TSelf::Option is a raw value.
- friend bool operator==(const TSelf& self, int value) { return self.value == value; }
- friend auto operator<=>(const TSelf& self, int value) { return self.value <=> value; }
-
- friend TSelf operator&(const TSelf& a, const TSelf& b) { return TSelf(a.value & b.value); }
- friend TSelf operator|(const TSelf& a, const TSelf& b) { return TSelf(a.value | b.value); }
- friend TSelf operator^(const TSelf& a, const TSelf& b) { return TSelf(a.value ^ b.value); }
-
- TSelf operator~() const { return TSelf(~value); }
-
- TSelf& operator&=(int that) {
- value = value & that;
- return *this;
- }
-
- TSelf& operator|=(int that) {
- value = value | that;
- return *this;
- }
-
- TSelf& operator^=(int that) {
- value = value ^ that;
- return *this;
- }
-};
+#pragma once
+
+#include <compare>
+
+template <class TSelf>
+struct BasicEnum {
+ using Self = TSelf;
+ using ValueType = int;
+
+ int value;
+
+ BasicEnum()
+ : value{ 0 } {}
+ BasicEnum(int value)
+ : value{ value } {}
+
+ /// Comparsion between 2 values of enum. Useful for situations like `a == b` where both a and b are TSelf.
+ friend auto operator<=>(const TSelf& a, const TSelf& b) { return a.value <=> b.value; }
+ /// Comparsion between a enum and a raw value. Useful for situations like `a == TSelf::Option` where a is a enum and TSelf::Option is a raw value.
+ friend auto operator<=>(const TSelf& self, int value) { return self.value <=> value; }
+
+ operator int() const { return value; }
+ operator bool() const { return value; }
+};
+
+#define ENUM(Name) struct Name : public BasicEnum<Name>
+#define ENUM_MEMBERS() \
+ enum Enum : int; \
+ operator Enum() const { return (Enum)value; } \
+ using BasicEnum<Self>::BasicEnum; \
+ enum Enum : int
+
+template <class TSelf>
+struct BasicFlag {
+ using Self = TSelf;
+ using ValueType = int;
+
+ int value;
+
+ BasicFlag()
+ : value{ 0 } {}
+ BasicFlag(int value)
+ : value{ value } {}
+
+ bool IsSet(TSelf mask) const { return (value & mask.value) == mask.value; }
+ bool IsSetExclusive(TSelf mask) const { return value == mask.value; }
+ void Set(TSelf mask, bool state) {
+ if (state) {
+ value = (int)(value | mask.value);
+ } else {
+ value = (int)(value & ~mask.value);
+ }
+ }
+
+ /// Comparsion between 2 values of flag. Useful for situations like `a == b` where both a and b are TSelf.
+ friend bool operator==(const TSelf& a, const TSelf& b) { return a.value == b.value; }
+ friend auto operator<=>(const TSelf& a, const TSelf& b) { return a.value <=> b.value; }
+ /// Comparsion between a flag and a raw value. Useful for situations like `a == TSelf::Option` where a is a flag and TSelf::Option is a raw value.
+ friend bool operator==(const TSelf& self, int value) { return self.value == value; }
+ friend auto operator<=>(const TSelf& self, int value) { return self.value <=> value; }
+
+ friend TSelf operator&(const TSelf& a, const TSelf& b) { return TSelf(a.value & b.value); }
+ friend TSelf operator|(const TSelf& a, const TSelf& b) { return TSelf(a.value | b.value); }
+ friend TSelf operator^(const TSelf& a, const TSelf& b) { return TSelf(a.value ^ b.value); }
+
+ TSelf operator~() const { return TSelf(~value); }
+
+ TSelf& operator&=(int that) {
+ value = value & that;
+ return *this;
+ }
+
+ TSelf& operator|=(int that) {
+ value = value | that;
+ return *this;
+ }
+
+ TSelf& operator^=(int that) {
+ value = value ^ that;
+ return *this;
+ }
+};