summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-08-14 23:31:46 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-08-14 23:31:46 +0100
commitecebc3ac7c34adc1f40dc3532e6d5998bc05bf88 (patch)
treea151c49a0bee8041b076f2038e0c9fbc9ec109cb
parentHook range iter constructor which doesn't call moveMatch for end (diff)
downloadslicer-ecebc3ac7c34adc1f40dc3532e6d5998bc05bf88.tar.bz2
slicer-ecebc3ac7c34adc1f40dc3532e6d5998bc05bf88.tar.xz
slicer-ecebc3ac7c34adc1f40dc3532e6d5998bc05bf88.zip
Don't support operations that don't make sense
GetSubclassModelPart and GetContainedModelPart throw if called on ModelParts which don't support them. This should remove the need for shared_from_this.
-rw-r--r--slicer/slicer/modelParts.cpp4
-rw-r--r--slicer/test/compilation.cpp24
2 files changed, 14 insertions, 14 deletions
diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp
index 1b40773..abe94d8 100644
--- a/slicer/slicer/modelParts.cpp
+++ b/slicer/slicer/modelParts.cpp
@@ -14,7 +14,7 @@ namespace Slicer {
ModelPartPtr
ModelPart::GetSubclassModelPart(const std::string &)
{
- return shared_from_this();
+ throw std::logic_error {"GetSubclassModelPart not supported on this ModelPart"};
}
TypeId
@@ -69,7 +69,7 @@ namespace Slicer {
ModelPartPtr
ModelPart::GetContainedModelPart()
{
- return shared_from_this();
+ throw std::logic_error {"GetContainedModelPart not supported on this ModelPart"};
}
bool
diff --git a/slicer/test/compilation.cpp b/slicer/test/compilation.cpp
index 6bc6993..fbbbb5f 100644
--- a/slicer/test/compilation.cpp
+++ b/slicer/test/compilation.cpp
@@ -44,7 +44,7 @@ BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_class)
{
TypeTest(TestModule::BuiltInsPtr, std::make_shared<TestModule::BuiltIns>(), ModelPartForClass,
ModelPartType::Complex);
- BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
+ BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error);
}
static void
@@ -53,7 +53,7 @@ hookHandler(std::vector<std::string> * names, const std::string & name, Slicer::
{
names->push_back(name);
BOOST_REQUIRE(mpp);
- BOOST_REQUIRE(mpp->GetContainedModelPart());
+ BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error);
BOOST_REQUIRE(h);
BOOST_REQUIRE_EQUAL(h->name, name);
}
@@ -104,61 +104,61 @@ BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_mapstructs)
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_string)
{
StackTypeTest(std::string, ModelPartForSimple, ModelPartType::Simple);
- BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
+ BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error);
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_bool)
{
StackTypeTest(bool, ModelPartForSimple, ModelPartType::Simple);
- BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
+ BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error);
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_float)
{
StackTypeTest(Ice::Float, ModelPartForSimple, ModelPartType::Simple);
- BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
+ BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error);
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_double)
{
StackTypeTest(Ice::Double, ModelPartForSimple, ModelPartType::Simple);
- BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
+ BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error);
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_byte)
{
StackTypeTest(Ice::Byte, ModelPartForSimple, ModelPartType::Simple);
- BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
+ BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error);
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_short)
{
StackTypeTest(Ice::Short, ModelPartForSimple, ModelPartType::Simple);
- BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
+ BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error);
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_int)
{
StackTypeTest(Ice::Int, ModelPartForSimple, ModelPartType::Simple);
- BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
+ BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error);
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_long)
{
StackTypeTest(Ice::Long, ModelPartForSimple, ModelPartType::Simple);
- BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
+ BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error);
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_struct)
{
StackTypeTest(TestModule::StructType, ModelPartForStruct, ModelPartType::Complex);
- BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
+ BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error);
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_enum)
{
StackTypeTest(TestModule::SomeNumbers, ModelPartForEnum, ModelPartType::Simple);
- BOOST_REQUIRE_EQUAL(mpp.get(), mpp->GetContainedModelPart().get());
+ BOOST_CHECK_THROW(mpp->GetContainedModelPart(), std::logic_error);
}
BOOST_AUTO_TEST_CASE(normalClassTypeId)