diff options
Diffstat (limited to 'libs/input/PropertyMap.cpp')
-rw-r--r-- | libs/input/PropertyMap.cpp | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/libs/input/PropertyMap.cpp b/libs/input/PropertyMap.cpp index ed9ac9fc72..9a4f10b21d 100644 --- a/libs/input/PropertyMap.cpp +++ b/libs/input/PropertyMap.cpp @@ -16,6 +16,8 @@ #define LOG_TAG "PropertyMap" +#include <cstdlib> + #include <input/PropertyMap.h> #include <log/log.h> @@ -44,6 +46,16 @@ void PropertyMap::addProperty(const std::string& key, const std::string& value) mProperties.emplace(key, value); } +std::unordered_set<std::string> PropertyMap::getKeysWithPrefix(const std::string& prefix) const { + std::unordered_set<std::string> keys; + for (const auto& [key, _] : mProperties) { + if (key.starts_with(prefix)) { + keys.insert(key); + } + } + return keys; +} + bool PropertyMap::hasProperty(const std::string& key) const { return mProperties.find(key) != mProperties.end(); } @@ -102,6 +114,23 @@ bool PropertyMap::tryGetProperty(const std::string& key, float& outValue) const return true; } +bool PropertyMap::tryGetProperty(const std::string& key, double& outValue) const { + std::string stringValue; + if (!tryGetProperty(key, stringValue) || stringValue.length() == 0) { + return false; + } + + char* end; + double value = strtod(stringValue.c_str(), &end); + if (*end != '\0') { + ALOGW("Property key '%s' has invalid value '%s'. Expected a double.", key.c_str(), + stringValue.c_str()); + return false; + } + outValue = value; + return true; +} + void PropertyMap::addAll(const PropertyMap* map) { for (const auto& [key, value] : map->mProperties) { mProperties.emplace(key, value); |