From 3b5b34beaa5ccc4441eb8c4ae2ff113377348f5a Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 8 Sep 2023 00:19:27 +0100 Subject: Remove the need for Default --- slicer/slicer/modelParts.h | 5 +---- slicer/slicer/modelPartsTypes.impl.h | 40 +++++++++++++++--------------------- slicer/test/compilation.cpp | 14 ++++++------- 3 files changed, 24 insertions(+), 35 deletions(-) diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 452538a..b4d1eb7 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -125,8 +125,6 @@ namespace Slicer { const std::string * nameStr; }; - template struct DLL_PUBLIC Default { }; - class DLL_PUBLIC ModelPart { public: ModelPart() = default; @@ -139,8 +137,7 @@ namespace Slicer { ModelPart & operator=(ModelPart &&) = delete; template static void Make(typename MP::element_type * t, const ModelPartHandler &); - template static void CreateFor(T & t, const ModelPartHandler &); - template static void CreateFor(Default &&, const ModelPartHandler &); + template static void CreateFor(T * t, const ModelPartHandler &); template static void OnRootFor(T & t, const ModelPartRootHandler &); virtual void OnEachChild(const ChildHandler &); diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index b04def8..3fcc598 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -46,39 +46,31 @@ namespace Ice { { \ h(ModelPartForOptional(t)); \ } \ - template<> DLL_PUBLIC void ModelPart::CreateFor(Default &&, const ModelPartHandler & h) \ + template<> DLL_PUBLIC void ModelPart::CreateFor(Type * s, const ModelPartHandler & h) \ { \ - return Make(nullptr, h); \ + return Make(s, h); \ } \ - template<> DLL_PUBLIC void ModelPart::CreateFor(Default> &&, const ModelPartHandler & h) \ + template<> DLL_PUBLIC void ModelPart::CreateFor(const Type * s, const ModelPartHandler & h) \ { \ - return Make>(nullptr, h); \ + return CreateFor(const_cast(s), h); \ } \ - template<> DLL_PUBLIC void ModelPart::CreateFor(Type & s, const ModelPartHandler & h) \ + template<> DLL_PUBLIC void ModelPart::CreateFor(Ice::optional * s, const ModelPartHandler & h) \ { \ - return Make(&s, h); \ + return Make>(s, h); \ } \ - template<> DLL_PUBLIC void ModelPart::CreateFor(const Type & s, const ModelPartHandler & h) \ + template<> DLL_PUBLIC void ModelPart::CreateFor(const Ice::optional * s, const ModelPartHandler & h) \ { \ - return CreateFor(const_cast(s), h); \ - } \ - template<> DLL_PUBLIC void ModelPart::CreateFor(Ice::optional & s, const ModelPartHandler & h) \ - { \ - return Make>(&s, h); \ - } \ - template<> DLL_PUBLIC void ModelPart::CreateFor(const Ice::optional & s, const ModelPartHandler & h) \ - { \ - return CreateFor(const_cast &>(s), h); \ + return CreateFor(const_cast *>(s), h); \ } \ template<> DLL_PUBLIC void ModelPart::OnRootFor(Type & s, const ModelPartRootHandler & h) \ { \ - return CreateFor(s, [&s, &h](auto && mp) { \ + return CreateFor(&s, [&s, &h](auto && mp) { \ h(ModelPartForRoot(&s, mp)); \ }); \ } \ template<> DLL_PUBLIC void ModelPart::OnRootFor(Ice::optional & s, const ModelPartRootHandler & h) \ { \ - return CreateFor(s, [&s, &h](auto && mp) { \ + return CreateFor(&s, [&s, &h](auto && mp) { \ h(ModelPartForRoot>(&s, mp)); \ }); \ } \ @@ -499,7 +491,7 @@ namespace Slicer { void ModelPartForClass::CreateModelPart(void * p, const ModelPartHandler & h) { - return ::Slicer::ModelPart::CreateFor(*static_cast(p), h); + return ::Slicer::ModelPart::CreateFor(static_cast(p), h); } template @@ -606,7 +598,7 @@ namespace Slicer { { BOOST_ASSERT(this->Model); for (auto & element : *this->Model) { - ModelPart::CreateFor(element, [&ch](auto && mp) { + ModelPart::CreateFor(&element, [&ch](auto && mp) { ch(elementName, mp, nullptr); }); } @@ -617,7 +609,7 @@ namespace Slicer { ModelPartForSequence::OnAnonChild(const SubPartHandler & ch, const HookFilter &) { BOOST_ASSERT(this->Model); - ModelPart::CreateFor(this->Model->emplace_back(), [&ch](auto && mp) { + ModelPart::CreateFor(&this->Model->emplace_back(), [&ch](auto && mp) { ch(mp, emptyMetadata); }); return true; @@ -641,7 +633,7 @@ namespace Slicer { void ModelPartForSequence::OnContained(const ModelPartHandler & h) { - return ModelPart::CreateFor(Default {}, h); + return ModelPart::CreateFor(nullptr, h); } // ModelPartForDictionaryElementInserter @@ -710,7 +702,7 @@ namespace Slicer { void ModelPartForStream::OnContained(const ModelPartHandler & h) { - ModelPart::CreateFor(Default {}, h); + ModelPart::CreateFor(nullptr, h); } template @@ -719,7 +711,7 @@ namespace Slicer { { BOOST_ASSERT(this->Model); this->Model->Produce([&ch](const T & element) { - ModelPart::CreateFor(element, [&ch](auto && mp) { + ModelPart::CreateFor(&element, [&ch](auto && mp) { ch(ModelPartForSequence>::elementName, mp, nullptr); }); }); diff --git a/slicer/test/compilation.cpp b/slicer/test/compilation.cpp index 14bf1d9..3cdfca3 100644 --- a/slicer/test/compilation.cpp +++ b/slicer/test/compilation.cpp @@ -25,7 +25,7 @@ BOOST_TEST_DONT_PRINT_LOG_VALUE(Slicer::ModelPartType) #define TypeTest(Var, Expr, Explicit, Expected, ...) \ Var obj = Expr; \ - Slicer::ModelPart::CreateFor(obj, [](auto && mpp) { \ + Slicer::ModelPart::CreateFor(&obj, [](auto && mpp) { \ BOOST_REQUIRE_EQUAL(Slicer::Expected, mpp->GetType()); \ \ BOOST_TEST_CONTEXT(#Var) { \ @@ -176,7 +176,7 @@ BOOST_AUTO_TEST_CASE(normalClassTypeId) { TestModule::BasePtr base = std::make_shared(1); BOOST_REQUIRE(base); - Slicer::ModelPart::CreateFor(base, [](auto && a) { + Slicer::ModelPart::CreateFor(&base, [](auto && a) { BOOST_REQUIRE(a); auto baseType = a->GetTypeId(); BOOST_REQUIRE(!baseType); @@ -187,7 +187,7 @@ BOOST_AUTO_TEST_CASE(normalSubClassTypeId) { TestModule::BasePtr base = std::make_shared(1, 2); BOOST_REQUIRE(base); - Slicer::ModelPart::CreateFor(base, [](auto && a) { + Slicer::ModelPart::CreateFor(&base, [](auto && a) { BOOST_REQUIRE(a); auto baseType = a->GetTypeId(); BOOST_REQUIRE(baseType); @@ -199,7 +199,7 @@ BOOST_AUTO_TEST_CASE(normalSubSubClassTypeId) { TestModule::BasePtr base = std::make_shared(1, 2, 3); BOOST_REQUIRE(base); - Slicer::ModelPart::CreateFor(base, [](auto && a) { + Slicer::ModelPart::CreateFor(&base, [](auto && a) { BOOST_REQUIRE(a); auto baseType = a->GetTypeId(); BOOST_REQUIRE(baseType); @@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(localClassTypeId) { Locals::LocalClassPtr base = std::make_shared(1, "One"); BOOST_REQUIRE(base); - Slicer::ModelPart::CreateFor(base, [](auto && a) { + Slicer::ModelPart::CreateFor(&base, [](auto && a) { BOOST_REQUIRE(a); auto baseType = a->GetTypeId(); BOOST_REQUIRE(!baseType); @@ -222,7 +222,7 @@ BOOST_AUTO_TEST_CASE(localSubClassTypeId) { Locals::LocalClassPtr base = std::make_shared(1, "One", 3.1); BOOST_REQUIRE(base); - Slicer::ModelPart::CreateFor(base, [](auto && a) { + Slicer::ModelPart::CreateFor(&base, [](auto && a) { BOOST_REQUIRE(a); auto baseType = a->GetTypeId(); BOOST_REQUIRE(baseType); @@ -234,7 +234,7 @@ BOOST_AUTO_TEST_CASE(localSubSubClassTypeId) { Locals::LocalClassPtr base = std::make_shared(1, "One", 3.1, 1); BOOST_REQUIRE(base); - Slicer::ModelPart::CreateFor(base, [](auto && a) { + Slicer::ModelPart::CreateFor(&base, [](auto && a) { BOOST_REQUIRE(a); auto baseType = a->GetTypeId(); BOOST_REQUIRE(baseType); -- cgit v1.2.3