refactor: sort-by enum hyprland

This commit is contained in:
Austin Horstman
2023-09-09 09:32:55 -05:00
parent 65ba449460
commit 8ea2626de8
3 changed files with 85 additions and 39 deletions

28
include/util/enum.hpp Normal file
View File

@ -0,0 +1,28 @@
#pragma once
#include <iostream>
#include <map>
#include <string>
namespace waybar::util {
struct EnumParser {
EnumParser() {}
enum SORT_METHOD { ID, NAME, NUMBER, DEFAULT };
SORT_METHOD sortStringToEnum(const std::string& str) {
static const std::map<std::string, SORT_METHOD> enumMap = {
{"ID", ID}, {"NAME", NAME}, {"NUMBER", NUMBER}, {"DEFAULT", DEFAULT}};
auto it = enumMap.find(str);
if (it != enumMap.end()) {
return it->second;
} else {
throw std::invalid_argument("Invalid string representation for enum");
}
}
~EnumParser() = default;
};
} // namespace waybar::util