mirror of
https://github.com/rad4day/Waybar.git
synced 2025-07-13 22:52:30 +02:00
refactor: sort-by enum hyprland
This commit is contained in:
28
include/util/enum.hpp
Normal file
28
include/util/enum.hpp
Normal 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
|
Reference in New Issue
Block a user