summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-09-08 00:19:27 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-09-08 00:19:27 +0100
commit3b5b34beaa5ccc4441eb8c4ae2ff113377348f5a (patch)
treefe55de2d796ac5ab97d05872649fb57faf202e88
parentMove helpers to anon namespace and delete the unused ones (diff)
downloadslicer-3b5b34beaa5ccc4441eb8c4ae2ff113377348f5a.tar.bz2
slicer-3b5b34beaa5ccc4441eb8c4ae2ff113377348f5a.tar.xz
slicer-3b5b34beaa5ccc4441eb8c4ae2ff113377348f5a.zip
Remove the need for Default<T>
-rw-r--r--slicer/slicer/modelParts.h5
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h40
-rw-r--r--slicer/test/compilation.cpp14
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<typename T> struct DLL_PUBLIC Default { };
-
class DLL_PUBLIC ModelPart {
public:
ModelPart() = default;
@@ -139,8 +137,7 @@ namespace Slicer {
ModelPart & operator=(ModelPart &&) = delete;
template<typename MP> static void Make(typename MP::element_type * t, const ModelPartHandler &);
- template<typename T> static void CreateFor(T & t, const ModelPartHandler &);
- template<typename T> static void CreateFor(Default<T> &&, const ModelPartHandler &);
+ template<typename T> static void CreateFor(T * t, const ModelPartHandler &);
template<typename T> 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<ModelPartType>(t)); \
} \
- template<> DLL_PUBLIC void ModelPart::CreateFor(Default<Type> &&, const ModelPartHandler & h) \
+ template<> DLL_PUBLIC void ModelPart::CreateFor(Type * s, const ModelPartHandler & h) \
{ \
- return Make<ModelPartType>(nullptr, h); \
+ return Make<ModelPartType>(s, h); \
} \
- template<> DLL_PUBLIC void ModelPart::CreateFor(Default<Ice::optional<Type>> &&, const ModelPartHandler & h) \
+ template<> DLL_PUBLIC void ModelPart::CreateFor(const Type * s, const ModelPartHandler & h) \
{ \
- return Make<ModelPartForOptional<ModelPartType>>(nullptr, h); \
+ return CreateFor(const_cast<Type *>(s), h); \
} \
- template<> DLL_PUBLIC void ModelPart::CreateFor(Type & s, const ModelPartHandler & h) \
+ template<> DLL_PUBLIC void ModelPart::CreateFor(Ice::optional<Type> * s, const ModelPartHandler & h) \
{ \
- return Make<ModelPartType>(&s, h); \
+ return Make<ModelPartForOptional<ModelPartType>>(s, h); \
} \
- template<> DLL_PUBLIC void ModelPart::CreateFor(const Type & s, const ModelPartHandler & h) \
+ template<> DLL_PUBLIC void ModelPart::CreateFor(const Ice::optional<Type> * s, const ModelPartHandler & h) \
{ \
- return CreateFor(const_cast<Type &>(s), h); \
- } \
- template<> DLL_PUBLIC void ModelPart::CreateFor(Ice::optional<Type> & s, const ModelPartHandler & h) \
- { \
- return Make<ModelPartForOptional<ModelPartType>>(&s, h); \
- } \
- template<> DLL_PUBLIC void ModelPart::CreateFor(const Ice::optional<Type> & s, const ModelPartHandler & h) \
- { \
- return CreateFor(const_cast<Ice::optional<Type> &>(s), h); \
+ return CreateFor(const_cast<Ice::optional<Type> *>(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<Type>(&s, mp)); \
}); \
} \
template<> DLL_PUBLIC void ModelPart::OnRootFor(Ice::optional<Type> & s, const ModelPartRootHandler & h) \
{ \
- return CreateFor(s, [&s, &h](auto && mp) { \
+ return CreateFor(&s, [&s, &h](auto && mp) { \
h(ModelPartForRoot<Ice::optional<Type>>(&s, mp)); \
}); \
} \
@@ -499,7 +491,7 @@ namespace Slicer {
void
ModelPartForClass<T>::CreateModelPart(void * p, const ModelPartHandler & h)
{
- return ::Slicer::ModelPart::CreateFor(*static_cast<element_type *>(p), h);
+ return ::Slicer::ModelPart::CreateFor(static_cast<element_type *>(p), h);
}
template<typename T>
@@ -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<T>::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<T>::OnContained(const ModelPartHandler & h)
{
- return ModelPart::CreateFor(Default<typename T::value_type> {}, h);
+ return ModelPart::CreateFor<typename T::value_type>(nullptr, h);
}
// ModelPartForDictionaryElementInserter
@@ -710,7 +702,7 @@ namespace Slicer {
void
ModelPartForStream<T>::OnContained(const ModelPartHandler & h)
{
- ModelPart::CreateFor(Default<T> {}, h);
+ ModelPart::CreateFor<T>(nullptr, h);
}
template<typename T>
@@ -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<std::vector<T>>::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<TestModule::Base>(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<TestModule::D1>(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<TestModule::D3>(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<Locals::LocalClass>(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<Locals::LocalSubClass>(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<Locals::LocalSub2Class>(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);