From 5e38fce1b46ba6cda98832a357e7f572533b14c0 Mon Sep 17 00:00:00 2001 From: Undeadamien Date: Fri, 3 Apr 2026 15:34:41 +0200 Subject: [PATCH] config: remove getAnyConfigValuePtr --- include/hyprlang.hpp | 16 +++++----------- src/config.cpp | 9 +++++++++ tests/parse/main.cpp | 16 ++++++++-------- 3 files changed, 22 insertions(+), 19 deletions(-) diff --git a/include/hyprlang.hpp b/include/hyprlang.hpp index 3b36465..f851485 100644 --- a/include/hyprlang.hpp +++ b/include/hyprlang.hpp @@ -389,11 +389,6 @@ namespace Hyprlang { */ CConfigValue* getSpecialConfigValuePtr(const char* category, const char* name, const char* key = nullptr); - /*! - Get a basic or special category's config value ptr by calling `getConfigValuePtr` or `getSpecialConfigValuePtr` - */ - CConfigValue* getAnyConfigValuePtr(const char* name); - /*! Get a config value's stored value. Empty on fail */ @@ -414,12 +409,10 @@ namespace Hyprlang { return val->getValue(); } - std::any getAnyConfigValue(const char* name) { - CConfigValue* val = getAnyConfigValuePtr(name); - if (!val) - return {}; - return val->getValue(); - } + /*! + Get a basic or special config value's stored value. Empty on fail. + */ + std::any getAnyConfigValue(const char* name); /*! Check whether a special category with the provided key value exists @@ -472,6 +465,7 @@ namespace Hyprlang { void applyDefaultsToCat(SSpecialCategory& cat); void retrieveKeysForCat(const char* category, const char*** out, size_t* len); CParseResult parseRawStream(const std::string& stream); + CConfigValue* getAnyConfigValuePtr(const char* name); }; /*! diff --git a/src/config.cpp b/src/config.cpp index 6c95093..3071f1c 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -1124,6 +1124,15 @@ CConfigValue* CConfig::getAnyConfigValuePtr(const char* name) { return getConfigValuePtr(name); } +std::any CConfig::getAnyConfigValue(const char* name) { + CConfigValue* val = getAnyConfigValuePtr(name); + + if (!val) + return {}; + + return val->getValue(); +} + void CConfig::registerHandler(PCONFIGHANDLERFUNC func, const char* name, SHandlerOptions options_) { SHandlerOptions options; std::memcpy(&options, &options_, seekABIStructSize(&options_, 0, sizeof(SHandlerOptions))); diff --git a/tests/parse/main.cpp b/tests/parse/main.cpp index 3ac57ee..6113097 100644 --- a/tests/parse/main.cpp +++ b/tests/parse/main.cpp @@ -396,14 +396,14 @@ int main(int argc, char** argv, char** envp) { EXPECT(std::any_cast(config.getAnyConfigValue("specialAnonymousNested[c]:nested:value1")), std::any_cast(config.getSpecialConfigValue("specialAnonymousNested", "nested:value1", "c"))); // check against malformed - EXPECT(config.getAnyConfigValuePtr("[a]:value"), nullptr); - EXPECT(config.getAnyConfigValuePtr("special[[a]:value"), nullptr); - EXPECT(config.getAnyConfigValuePtr("special[[a]]:value"), nullptr); - EXPECT(config.getAnyConfigValuePtr("special[a]]:value"), nullptr); - EXPECT(config.getAnyConfigValuePtr("special[a]value"), nullptr); - EXPECT(config.getAnyConfigValuePtr("special[avalue"), nullptr); - EXPECT(config.getAnyConfigValuePtr("special]:a[value"), nullptr); - EXPECT(config.getAnyConfigValuePtr("speciala]:value"), nullptr); + EXPECT(config.getAnyConfigValue("[a]:value").has_value(), false); + EXPECT(config.getAnyConfigValue("special[[a]:value").has_value(), false); + EXPECT(config.getAnyConfigValue("special[[a]]:value").has_value(), false); + EXPECT(config.getAnyConfigValue("special[a]]:value").has_value(), false); + EXPECT(config.getAnyConfigValue("special[a]value").has_value(), false); + EXPECT(config.getAnyConfigValue("special[avalue").has_value(), false); + EXPECT(config.getAnyConfigValue("special]:a[value").has_value(), false); + EXPECT(config.getAnyConfigValue("speciala]:value").has_value(), false); // test sourcing std::cout << " → Testing sourcing\n";