From c4a52bb1e24205ff15f3806de9b08e7f33334b14 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Sat, 7 Nov 2020 14:37:36 +0200 Subject: [PATCH] Check property exists --- SDK/C++/private/operator_impl.cpp | 1 + components/common/cpp/include/ftl/configurable.hpp | 2 ++ components/common/cpp/src/configurable.cpp | 4 ++++ 3 files changed, 7 insertions(+) diff --git a/SDK/C++/private/operator_impl.cpp b/SDK/C++/private/operator_impl.cpp index a3e65a759..41f376c20 100644 --- a/SDK/C++/private/operator_impl.cpp +++ b/SDK/C++/private/operator_impl.cpp @@ -17,5 +17,6 @@ OperatorImpl::~OperatorImpl() voltu::PropertyPtr OperatorImpl::property(const std::string &name) { + if (!cfg_->has(name)) throw voltu::exceptions::BadPropertyName(); return std::make_shared<voltu::internal::CfgPropertyImpl>(cfg_, name); } diff --git a/components/common/cpp/include/ftl/configurable.hpp b/components/common/cpp/include/ftl/configurable.hpp index dadba17b4..3d2a115e6 100644 --- a/components/common/cpp/include/ftl/configurable.hpp +++ b/components/common/cpp/include/ftl/configurable.hpp @@ -70,6 +70,8 @@ class Configurable { template <typename T> inline bool is(const std::string &name) { return false; } + bool has(const std::string &name) const; + /** * Get a configuration property, but return a default if not found. */ diff --git a/components/common/cpp/src/configurable.cpp b/components/common/cpp/src/configurable.cpp index 4f6bff5ba..c5f6d9d86 100644 --- a/components/common/cpp/src/configurable.cpp +++ b/components/common/cpp/src/configurable.cpp @@ -151,6 +151,10 @@ bool ftl::Configurable::is<double>(const std::string &name) { return getConfig()[name].is_number_float(); } +bool ftl::Configurable::has(const std::string &name) const { + return (config_) ? config_->contains(name) : false; +} + void Configurable::required(const char *f, const std::vector<std::tuple<std::string, std::string, std::string>> &r) { bool diderror = false; for (auto i : r) { -- GitLab