Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- *******************
- .h
- class DamageClass {
- public:
- enum Type { Unknown, Physical, Chemical, Electrical, Fire, Count };
- static unordered_map<string, Type> Names;
- private:
- Type mValue{Unknown};
- public:
- DamageClass() {
- }
- DamageClass(const string &str) {
- auto iter = Names.find(str);
- if (iter == Names.end()) {
- throw runtime_error("Invalid damage class: " + str);
- }
- mValue = iter->second;
- }
- DamageClass(const Type &type) : mValue(type) {
- }
- bool operator==(const Type &other) const {
- return mValue == other;
- }
- bool operator==(const DamageClass &other) const {
- return mValue == other.mValue;
- }
- operator Type() const {
- return mValue;
- }
- void Serialize(Serializer &sav) {
- sav &mValue;
- }
- };
- *****************
- .cpp
- #define ENTRY(x) {#x, x}
- unordered_map<string, DamageClass::Type> DamageClass::Names = {
- ENTRY(Unknown),
- ENTRY(Physical),
- ENTRY(Chemical),
- ENTRY(Electrical),
- ENTRY(Fire),
- ENTRY(Count)
- };
Advertisement
Add Comment
Please, Sign In to add comment