Skip to content

Commit

Permalink
Improve method name to be more interface like
Browse files Browse the repository at this point in the history
  • Loading branch information
tmadlener committed Dec 5, 2023
1 parent 170e60e commit 7ff2ea1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions python/templates/Interface.h.jinja2
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public:

/// Check if the object currently holds a value of the requested type
template<typename T>
bool holds() const {
bool isA() const {
return typeid(T) == m_self->typeInfo();
}

Expand All @@ -112,7 +112,7 @@ public:
/// value. Use holds to check beforehand if necessary template<typename T>
template<typename T>
T getValue() const {
if (!holds<T>()) {
if (!isA<T>()) {
throw std::runtime_error("Cannot get value as object currently holds anotyer type");
}
// We can safely cast here since we check types before
Expand Down
14 changes: 7 additions & 7 deletions tests/unittests/interface_types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ TEST_CASE("InterfaceTypes basic functionality", "[interface-types][basics]") {

auto emptyWrapper = WrapperT::makeEmpty();
REQUIRE_FALSE(emptyWrapper.isAvailable());
REQUIRE(emptyWrapper.holds<ExampleHit>());
REQUIRE(emptyWrapper.isA<ExampleHit>());

ExampleHit hit{};
WrapperT wrapper1 = hit;
Expand Down Expand Up @@ -50,14 +50,14 @@ TEST_CASE("InterfaceType from immutable", "[interface-types][basics]") {

ExampleHit hit{};
WrapperT wrapper{hit};
REQUIRE(wrapper.holds<ExampleHit>());
REQUIRE_FALSE(wrapper.holds<ExampleCluster>());
REQUIRE(wrapper.isA<ExampleHit>());
REQUIRE_FALSE(wrapper.isA<ExampleCluster>());
REQUIRE(wrapper.getValue<ExampleHit>() == hit);
REQUIRE(wrapper == hit);

ExampleCluster cluster{};
wrapper = cluster;
REQUIRE(wrapper.holds<ExampleCluster>());
REQUIRE(wrapper.isA<ExampleCluster>());
REQUIRE(wrapper.getValue<ExampleCluster>() == cluster);
REQUIRE_THROWS_AS(wrapper.getValue<ExampleHit>(), std::runtime_error);
REQUIRE(wrapper != hit);
Expand All @@ -68,8 +68,8 @@ TEST_CASE("InterfaceType from mutable", "[interface-types][basics]") {

ExampleHit hit{};
WrapperT wrapper{hit};
REQUIRE(wrapper.holds<ExampleHit>());
REQUIRE_FALSE(wrapper.holds<ExampleCluster>());
REQUIRE(wrapper.isA<ExampleHit>());
REQUIRE_FALSE(wrapper.isA<ExampleCluster>());
REQUIRE(wrapper.getValue<ExampleHit>() == hit);
REQUIRE(wrapper == hit);
// Comparison also work against the immutable classes
Expand All @@ -78,7 +78,7 @@ TEST_CASE("InterfaceType from mutable", "[interface-types][basics]") {

MutableExampleCluster cluster{};
wrapper = cluster;
REQUIRE(wrapper.holds<ExampleCluster>());
REQUIRE(wrapper.isA<ExampleCluster>());
REQUIRE(wrapper.getValue<ExampleCluster>() == cluster);
REQUIRE_THROWS_AS(wrapper.getValue<ExampleHit>(), std::runtime_error);
REQUIRE(wrapper != hit);
Expand Down

0 comments on commit 7ff2ea1

Please sign in to comment.