From 7ff2ea1b986535230bbc19516974d56e29b78453 Mon Sep 17 00:00:00 2001 From: tmadlener Date: Fri, 1 Dec 2023 19:50:08 +0100 Subject: [PATCH] Improve method name to be more interface like --- python/templates/Interface.h.jinja2 | 4 ++-- tests/unittests/interface_types.cpp | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/python/templates/Interface.h.jinja2 b/python/templates/Interface.h.jinja2 index 63424a512..98527a5e7 100644 --- a/python/templates/Interface.h.jinja2 +++ b/python/templates/Interface.h.jinja2 @@ -103,7 +103,7 @@ public: /// Check if the object currently holds a value of the requested type template - bool holds() const { + bool isA() const { return typeid(T) == m_self->typeInfo(); } @@ -112,7 +112,7 @@ public: /// value. Use holds to check beforehand if necessary template template T getValue() const { - if (!holds()) { + if (!isA()) { throw std::runtime_error("Cannot get value as object currently holds anotyer type"); } // We can safely cast here since we check types before diff --git a/tests/unittests/interface_types.cpp b/tests/unittests/interface_types.cpp index 3ef591daf..98dd50210 100644 --- a/tests/unittests/interface_types.cpp +++ b/tests/unittests/interface_types.cpp @@ -14,7 +14,7 @@ TEST_CASE("InterfaceTypes basic functionality", "[interface-types][basics]") { auto emptyWrapper = WrapperT::makeEmpty(); REQUIRE_FALSE(emptyWrapper.isAvailable()); - REQUIRE(emptyWrapper.holds()); + REQUIRE(emptyWrapper.isA()); ExampleHit hit{}; WrapperT wrapper1 = hit; @@ -50,14 +50,14 @@ TEST_CASE("InterfaceType from immutable", "[interface-types][basics]") { ExampleHit hit{}; WrapperT wrapper{hit}; - REQUIRE(wrapper.holds()); - REQUIRE_FALSE(wrapper.holds()); + REQUIRE(wrapper.isA()); + REQUIRE_FALSE(wrapper.isA()); REQUIRE(wrapper.getValue() == hit); REQUIRE(wrapper == hit); ExampleCluster cluster{}; wrapper = cluster; - REQUIRE(wrapper.holds()); + REQUIRE(wrapper.isA()); REQUIRE(wrapper.getValue() == cluster); REQUIRE_THROWS_AS(wrapper.getValue(), std::runtime_error); REQUIRE(wrapper != hit); @@ -68,8 +68,8 @@ TEST_CASE("InterfaceType from mutable", "[interface-types][basics]") { ExampleHit hit{}; WrapperT wrapper{hit}; - REQUIRE(wrapper.holds()); - REQUIRE_FALSE(wrapper.holds()); + REQUIRE(wrapper.isA()); + REQUIRE_FALSE(wrapper.isA()); REQUIRE(wrapper.getValue() == hit); REQUIRE(wrapper == hit); // Comparison also work against the immutable classes @@ -78,7 +78,7 @@ TEST_CASE("InterfaceType from mutable", "[interface-types][basics]") { MutableExampleCluster cluster{}; wrapper = cluster; - REQUIRE(wrapper.holds()); + REQUIRE(wrapper.isA()); REQUIRE(wrapper.getValue() == cluster); REQUIRE_THROWS_AS(wrapper.getValue(), std::runtime_error); REQUIRE(wrapper != hit);