diff options
author | rtk0c <[email protected]> | 2021-05-06 21:56:40 -0700 |
---|---|---|
committer | rtk0c <[email protected]> | 2021-05-06 21:56:40 -0700 |
commit | 1fd1e4b5f2418e3ac2909658993bfedb615537ec (patch) | |
tree | 6de080d2273890f8a74d7fcd3572bb44f44ac545 /core/src/Utils/Enum.hpp | |
parent | 538e804fc9beb83e711a210ffbb6badc15f285d5 (diff) |
Change brace style to on new line, add initial deliveries view when an order entry is selected
Diffstat (limited to 'core/src/Utils/Enum.hpp')
-rw-r--r-- | core/src/Utils/Enum.hpp | 110 |
1 files changed, 84 insertions, 26 deletions
diff --git a/core/src/Utils/Enum.hpp b/core/src/Utils/Enum.hpp index e774b01..1fb9661 100644 --- a/core/src/Utils/Enum.hpp +++ b/core/src/Utils/Enum.hpp @@ -3,7 +3,8 @@ #include <compare> template <class TSelf> -struct BasicEnum { +struct BasicEnum +{ using Self = TSelf; using ValueType = int; @@ -14,24 +15,42 @@ struct BasicEnum { 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; } + /// Comparison 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; + } + + /// Comparison 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; } + 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; \ +#define ENUM_MEMBERS() \ + enum Enum : int; \ + operator Enum() const \ + { \ + return (Enum)value; \ + } \ + using BasicEnum<Self>::BasicEnum; \ enum Enum : int template <class TSelf> -struct BasicFlag { +struct BasicFlag +{ using Self = TSelf; using ValueType = int; @@ -42,9 +61,16 @@ struct BasicFlag { 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) { + 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 { @@ -53,29 +79,61 @@ struct BasicFlag { } /// 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; } + 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 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); } - 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); } + 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) { + TSelf& operator&=(int that) + { value = value & that; return *this; } - TSelf& operator|=(int that) { + TSelf& operator|=(int that) + { value = value | that; return *this; } - TSelf& operator^=(int that) { + TSelf& operator^=(int that) + { value = value ^ that; return *this; } |