diff --git a/src/snoretoastactions.h b/src/snoretoastactions.h index 22640f8..75e9563 100644 --- a/src/snoretoastactions.h +++ b/src/snoretoastactions.h @@ -1,56 +1,86 @@ /* SnoreToast is capable to invoke Windows 8 toast notifications. Copyright (C) 2013-2019 Hannah von Reth SnoreToast is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. SnoreToast is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with SnoreToast. If not, see . */ #pragma once -#include +#include +#include #include +#if __cplusplus > 201402L || _HAS_CXX17 +#define SNORE_HAS_CXX17 +#endif + +#ifdef SNORE_HAS_CXX17 +#include +#endif + class SnoreToastActions { public: enum class Actions { Clicked, Hidden, Dismissed, Timedout, ButtonClicked, TextEntered, Error = -1 }; - static constexpr std::wstring_view getActionString(const Actions &a) + static const inline std::wstring& getActionString(const Actions &a) { - return ActionStrings[static_cast(a)]; + return actionMap().at(a); } + static inline SnoreToastActions::Actions getAction(const std::wstring &s) + { + for (const auto &a : actionMap()) { + if (a.second.compare(s) == 0) { + return a.first; + } + } + return SnoreToastActions::Actions::Error; + } + + +#ifdef SNORE_HAS_CXX17 static inline SnoreToastActions::Actions getAction(const std::wstring_view &s) { - for (unsigned int i = 0; i <= sizeof(ActionStrings); ++i) { - if (ActionStrings[i].compare(s) == 0) { - return static_cast(i); + for (const auto &a : actionMap()) { + if (a.second.compare(s) == 0) { + return a.first; } } return SnoreToastActions::Actions::Error; } +#endif private: - static constexpr std::wstring_view ActionStrings[] = { - L"clicked", L"hidden", L"dismissed", L"timedout", L"buttonClicked", L"textEntered", - }; + static const std::map &actionMap(){ + static const std::map _ActionStrings = { + {Actions::Clicked, L"clicked"}, + {Actions::Hidden, L"hidden"}, + {Actions::Dismissed, L"dismissed"}, + {Actions::Timedout, L"timedout"}, + {Actions::ButtonClicked, L"buttonClicked"}, + {Actions::TextEntered, L"textEntered"} + }; + return _ActionStrings; + } };