/* OmniaFramework - A collection of useful functionality Copyright (C) 2025 OmniaX-Dev This file is part of OmniaFramework. OmniaFramework is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. OmniaFramework 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 General Public License for more details. You should have received a copy of the GNU General Public License along with OmniaFramework. If not, see . */ #pragma once #include #include #include #include namespace ostd { class Stylesheet { public: using QualifierList = std::vector>; public: using TypeVariant = std::variant; public: Stylesheet(void); Stylesheet& clear(void); Stylesheet& loadFromFile(const ostd::String& filePath, bool clearCurrentRules = true); Stylesheet& loadFromString(const ostd::String& content, const ostd::String& filePath = "memory://", bool clearCurrentRules = true); void set(const std::string& key, TypeVariant value, const ostd::String& themeID); void removeRule(const ostd::String& fullKey); void setFull(const ostd::String& fullKey, TypeVariant value); const TypeVariant* getVariant(const ostd::String& key, const std::vector& themeIDList, const QualifierList& qualifierList) const; const TypeVariant* getFull(const ostd::String& fullKey) const; template inline T get(const ostd::String& key, const T& fallback, const std::vector& themeIDList, const QualifierList& qualifierList) const { if (auto v = getVariant(key, themeIDList, qualifierList)) { if (auto p = std::get_if(v)) return *p; } return fallback; } void debugPrint(void); ostd::String typeVariantToString(const TypeVariant& v); private: bool parseThemeFileLine(const ostd::String& line); ostd::String parseGroupSelector(const ostd::String& rawSelector) const; std::vector parseGroup(const ostd::String& selector, const std::vector& group); private: std::unordered_map m_values; const ostd::String m_validNameRegex { "^[A-Za-z_][A-Za-z0-9_]*$" }; }; }