From 22f50b1b004698c59c5622b19d8fe72655c84e68 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 13 Apr 2018 03:29:08 +0200 Subject: [PATCH] ElementAccess: streamline error cases My understanding is that in the standard use case, we precisely know what to expect and just go ahead and perform the conversion. Thus it is pointless to introduce fine grained distinctions. When the access fails, this always indicates some broken application logic, and just raises an error. --- src/gui/model/element-access.hpp | 16 +++++++--------- tests/gui/ctrl/element-access-test.cpp | 3 --- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/src/gui/model/element-access.hpp b/src/gui/model/element-access.hpp index fe7d00560..7f9dfd6eb 100644 --- a/src/gui/model/element-access.hpp +++ b/src/gui/model/element-access.hpp @@ -151,7 +151,7 @@ namespace model { struct ElementAccess::TypeConverter : RawResult::Visitor { - Result result; + Result result{"not convertible"}; template using canCast = std::is_convertible; @@ -163,6 +163,8 @@ namespace model { { if (pb) result = *dynamic_cast (pb); + else + result = "access returns empty answer"; } }; @@ -175,10 +177,9 @@ namespace model { * @tparam TAR type of result element expected at the designated location * @return suitably converted direct (language) reference to the desired element * wrapped as _result proxy_ - * @throw error::Invalid when the designated element exists, but is not - * type or conversion compatible to the expected result type - * @note when access was not possible because the element does not exist, - * the result proxy is empty and convertible to `bool(false)` + * @note when access was not possible because either the element does not exist, + * or is not convertible to the desired target type, the result proxy is empty + * and convertible to `bool(false)` */ template inline ElementAccess::Result @@ -201,10 +202,7 @@ namespace model { TypeConverter converter; RawResult targetElm = performAccessTo (destination, limitCreation); targetElm.accept (converter); - if (converter.result.isValid()) - return converter.result; - else - return "In current UI, there is no element at location "+string(destination); + return converter.result; } diff --git a/tests/gui/ctrl/element-access-test.cpp b/tests/gui/ctrl/element-access-test.cpp index acbba4cfb..d283af9be 100644 --- a/tests/gui/ctrl/element-access-test.cpp +++ b/tests/gui/ctrl/element-access-test.cpp @@ -124,9 +124,6 @@ namespace test { fakeDirectory->expectedQuery = location; fakeDirectory->expectedAnswer = &dummyTab; - DummyWidget* duf = &dummyTab; - model::Tangible* luf{duf}; - static_assert (std::is_convertible::value, "lalü"); AccessAPI accessAPI; auto answer = accessAPI().access (location);