summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2023-08-21 01:19:46 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2023-08-21 01:19:46 +0100
commit248b83144ab7facb9a124a1f5c2d1806412cc27e (patch)
tree00c0399a61336584a920421022054b51a272313a
parentMake ModelPartRoots on stack (diff)
downloadslicer-248b83144ab7facb9a124a1f5c2d1806412cc27e.tar.bz2
slicer-248b83144ab7facb9a124a1f5c2d1806412cc27e.tar.xz
slicer-248b83144ab7facb9a124a1f5c2d1806412cc27e.zip
Make remaining non-root ModelParts on the stack
-rw-r--r--slicer/slicer/modelParts.h11
-rw-r--r--slicer/slicer/modelPartsTypes.cpp2
-rw-r--r--slicer/slicer/modelPartsTypes.h7
-rw-r--r--slicer/slicer/modelPartsTypes.impl.h92
-rw-r--r--slicer/test/compilation.cpp182
-rw-r--r--slicer/test/conversions.cpp6
-rw-r--r--slicer/test/serializers.cpp6
-rw-r--r--slicer/tool/parser.cpp14
8 files changed, 169 insertions, 151 deletions
diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h
index da929ba..de6e89f 100644
--- a/slicer/slicer/modelParts.h
+++ b/slicer/slicer/modelParts.h
@@ -78,7 +78,6 @@ namespace Slicer {
class ModelPartForRootBase;
class HookCommon;
- using ModelPartPtr = std::shared_ptr<ModelPart>;
using ModelPartUPtr = std::unique_ptr<ModelPart>;
using ModelPartParam = any_ptr<ModelPart>;
using ModelPartForRootParam = any_ptr<ModelPartForRootBase>;
@@ -139,9 +138,9 @@ namespace Slicer {
ModelPart & operator=(const ModelPart &) = delete;
ModelPart & operator=(ModelPart &&) = delete;
- template<typename MP> static ModelPartPtr Make(typename MP::element_type * t);
- template<typename T> static ModelPartPtr CreateFor(T & t);
- template<typename T> static ModelPartPtr CreateFor(Default<T> &&);
+ 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 OnRootFor(T & t, const ModelPartRootHandler &);
virtual void OnEachChild(const ChildHandler &);
@@ -171,7 +170,7 @@ namespace Slicer {
class DLL_PUBLIC ModelPartForRootBase : public ModelPart {
public:
- explicit ModelPartForRootBase(ModelPartPtr mp);
+ explicit ModelPartForRootBase(ModelPartParam mp);
virtual const std::string & GetRootName() const = 0;
bool OnAnonChild(const SubPartHandler &, const HookFilter &) override;
@@ -183,7 +182,7 @@ namespace Slicer {
virtual void Read(::Ice::InputStream &) = 0;
void OnContained(const ModelPartHandler &) override;
- ModelPartPtr mp;
+ ModelPartParam mp;
};
}
diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp
index da38efe..673265e 100644
--- a/slicer/slicer/modelPartsTypes.cpp
+++ b/slicer/slicer/modelPartsTypes.cpp
@@ -108,7 +108,7 @@ namespace Slicer {
}
// ModelPartForRootBase
- ModelPartForRootBase::ModelPartForRootBase(ModelPartPtr m) : mp(std::move(m)) { }
+ ModelPartForRootBase::ModelPartForRootBase(ModelPartParam m) : mp(m) { }
bool
ModelPartForRootBase::OnAnonChild(const SubPartHandler & h, const HookFilter &)
diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h
index 838bbd0..f8a8814 100644
--- a/slicer/slicer/modelPartsTypes.h
+++ b/slicer/slicer/modelPartsTypes.h
@@ -26,7 +26,7 @@ namespace Slicer {
template<typename T> class ModelPartForRoot : public ModelPartForRootBase {
public:
- explicit ModelPartForRoot(T * o);
+ explicit ModelPartForRoot(T * o, ModelPartParam mp);
const std::string & GetRootName() const override;
bool HasValue() const override;
@@ -269,9 +269,6 @@ namespace Slicer {
static const Metadata metadata;
static const std::string elementName;
-
- private:
- // ModelPartPtr elementModelPart(typename T::value_type &) const;
};
template<typename T>
@@ -356,7 +353,7 @@ namespace Slicer {
template<typename T> class ModelPartForStreamRoot : public ModelPartForStreamRootBase {
public:
- explicit ModelPartForStreamRoot(Stream<T> * s);
+ using ModelPartForStreamRootBase::ModelPartForStreamRootBase;
const std::string & GetRootName() const override;
};
diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h
index 393809f..dc6ff07 100644
--- a/slicer/slicer/modelPartsTypes.impl.h
+++ b/slicer/slicer/modelPartsTypes.impl.h
@@ -33,47 +33,53 @@ namespace Ice {
}
#define CUSTOMMODELPARTFOR(Type, BaseModelPart, ModelPartType) \
- template<> DLL_PUBLIC ModelPartPtr ModelPart::Make<ModelPartType>(typename ModelPartType::element_type * t) \
+ template<> \
+ DLL_PUBLIC void ModelPart::Make<ModelPartType>( \
+ typename ModelPartType::element_type * t, const ModelPartHandler & h) \
{ \
- return std::make_shared<ModelPartType>(t); \
+ h(ModelPartType(t)); \
} \
template<> \
- DLL_PUBLIC ModelPartPtr ModelPart::Make<ModelPartForOptional<ModelPartType>>( \
- Ice::optional<typename ModelPartType::element_type> * t) \
+ DLL_PUBLIC void ModelPart::Make<ModelPartForOptional<ModelPartType>>( \
+ Ice::optional<typename ModelPartType::element_type> * t, const ModelPartHandler & h) \
{ \
- return std::make_shared<ModelPartForOptional<ModelPartType>>(t); \
+ h(ModelPartForOptional<ModelPartType>(t)); \
} \
- template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(Default<Type> &&) \
+ template<> DLL_PUBLIC void ModelPart::CreateFor(Default<Type> &&, const ModelPartHandler & h) \
{ \
- return Make<ModelPartType>(nullptr); \
+ return Make<ModelPartType>(nullptr, h); \
} \
- template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(Default<Ice::optional<Type>> &&) \
+ template<> DLL_PUBLIC void ModelPart::CreateFor(Default<Ice::optional<Type>> &&, const ModelPartHandler & h) \
{ \
- return Make<ModelPartForOptional<ModelPartType>>(nullptr); \
+ return Make<ModelPartForOptional<ModelPartType>>(nullptr, h); \
} \
- template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(Type & s) \
+ template<> DLL_PUBLIC void ModelPart::CreateFor(Type & s, const ModelPartHandler & h) \
{ \
- return Make<ModelPartType>(&s); \
+ return Make<ModelPartType>(&s, h); \
} \
- template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(const Type & s) \
+ template<> DLL_PUBLIC void ModelPart::CreateFor(const Type & s, const ModelPartHandler & h) \
{ \
- return CreateFor(const_cast<Type &>(s)); \
+ return CreateFor(const_cast<Type &>(s), h); \
} \
- template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(Ice::optional<Type> & s) \
+ template<> DLL_PUBLIC void ModelPart::CreateFor(Ice::optional<Type> & s, const ModelPartHandler & h) \
{ \
- return Make<ModelPartForOptional<ModelPartType>>(&s); \
+ return Make<ModelPartForOptional<ModelPartType>>(&s, h); \
} \
- template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(const Ice::optional<Type> & s) \
+ template<> DLL_PUBLIC void ModelPart::CreateFor(const Ice::optional<Type> & s, const ModelPartHandler & h) \
{ \
- return CreateFor(const_cast<Ice::optional<Type> &>(s)); \
+ return CreateFor(const_cast<Ice::optional<Type> &>(s), h); \
} \
template<> DLL_PUBLIC void ModelPart::OnRootFor(Type & s, const ModelPartRootHandler & h) \
{ \
- h(ModelPartForRoot<Type>(&s)); \
+ 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) \
{ \
- h(ModelPartForRoot<Ice::optional<Type>>(&s)); \
+ return CreateFor(s, [&s, &h](auto && mp) { \
+ h(ModelPartForRoot<Ice::optional<Type>>(&s, mp)); \
+ }); \
} \
template<> DLL_PUBLIC void ModelPart::OnRootFor(const Type & s, const ModelPartRootHandler & h) \
{ \
@@ -94,7 +100,8 @@ namespace Ice {
DLL_PUBLIC void \
ModelPart::OnRootFor(const StreamImpl & stream, const ModelPartRootHandler & h) \
{ \
- h(ModelPartForStreamRoot<typename StreamImpl::element_type>(const_cast<StreamImpl *>(&stream))); \
+ ModelPartForStream<typename StreamImpl::element_type> strm(const_cast<StreamImpl *>(&stream)); \
+ h(ModelPartForStreamRoot<typename StreamImpl::element_type>(strm)); \
} \
}
@@ -111,7 +118,7 @@ namespace Ice {
namespace Slicer {
// ModelPartForRoot
template<typename T>
- ModelPartForRoot<T>::ModelPartForRoot(T * o) : ModelPartForRootBase(ModelPart::CreateFor(*o)), ModelObject(o)
+ ModelPartForRoot<T>::ModelPartForRoot(T * o, ModelPartParam omp) : ModelPartForRootBase(omp), ModelObject(o)
{
}
@@ -347,7 +354,9 @@ namespace Slicer {
ModelPartForComplex<T>::OnEachChild(const ChildHandler & ch)
{
for (const auto & h : hooks()) {
- h->apply(ch, h->Get(GetModel()));
+ h->On(GetModel(), [h, &ch](auto && mp) {
+ h->apply(ch, mp);
+ });
}
}
@@ -361,8 +370,9 @@ namespace Slicer {
});
if (itr != range.end()) {
const auto & h = *itr;
- auto model = GetModel();
- ch(h->Get(model), h->GetMetadata());
+ h->On(GetModel(), [h, &ch](auto && mp) {
+ ch(mp, h->GetMetadata());
+ });
return true;
}
return false;
@@ -394,7 +404,7 @@ namespace Slicer {
public:
using HookCommon::HookCommon;
- virtual ModelPartPtr Get(T * t) const = 0;
+ virtual void On(T * t, const ModelPartHandler &) const = 0;
};
template<typename T>
@@ -417,13 +427,13 @@ namespace Slicer {
return hookMetadata;
}
- ModelPartPtr
- Get(T * t) const override
+ void
+ On(T * t, const ModelPartHandler & h) const override
{
if (t) {
- return Make<MP>(&(t->*member));
+ return Make<MP>(&(t->*member), h);
}
- return Make<MP>(nullptr);
+ return Make<MP>(nullptr, h);
}
private:
@@ -480,7 +490,7 @@ namespace Slicer {
void
ModelPartForClass<T>::CreateModelPart(void * p, const ModelPartHandler & h)
{
- return h(::Slicer::ModelPart::CreateFor(*static_cast<element_type *>(p)));
+ return ::Slicer::ModelPart::CreateFor(*static_cast<element_type *>(p), h);
}
template<typename T>
@@ -599,7 +609,9 @@ namespace Slicer {
{
BOOST_ASSERT(this->Model);
for (auto & element : *this->Model) {
- ch(elementName, ModelPart::CreateFor(element), NULL);
+ ModelPart::CreateFor(element, [&ch](auto && mp) {
+ ch(elementName, mp, nullptr);
+ });
}
}
@@ -608,7 +620,9 @@ namespace Slicer {
ModelPartForSequence<T>::OnAnonChild(const SubPartHandler & ch, const HookFilter &)
{
BOOST_ASSERT(this->Model);
- ch(ModelPart::CreateFor(this->Model->emplace_back()), emptyMetadata);
+ ModelPart::CreateFor(this->Model->emplace_back(), [&ch](auto && mp) {
+ ch(mp, emptyMetadata);
+ });
return true;
}
@@ -630,7 +644,7 @@ namespace Slicer {
void
ModelPartForSequence<T>::OnContained(const ModelPartHandler & h)
{
- return h(ModelPart::CreateFor(Default<typename T::value_type> {}));
+ return ModelPart::CreateFor(Default<typename T::value_type> {}, h);
}
// ModelPartForDictionaryElementInserter
@@ -699,7 +713,7 @@ namespace Slicer {
void
ModelPartForStream<T>::OnContained(const ModelPartHandler & h)
{
- return h(ModelPart::CreateFor(Default<T> {}));
+ ModelPart::CreateFor(Default<T> {}, h);
}
template<typename T>
@@ -708,17 +722,13 @@ namespace Slicer {
{
BOOST_ASSERT(this->Model);
this->Model->Produce([&ch](const T & element) {
- ch(ModelPartForSequence<std::vector<T>>::elementName, ModelPart::CreateFor(element), NULL);
+ ModelPart::CreateFor(element, [&ch](auto && mp) {
+ ch(ModelPartForSequence<std::vector<T>>::elementName, mp, nullptr);
+ });
});
}
template<typename T>
- ModelPartForStreamRoot<T>::ModelPartForStreamRoot(Stream<T> * s) :
- ModelPartForStreamRootBase(std::make_shared<ModelPartForStream<T>>(s))
- {
- }
-
- template<typename T>
const std::string &
ModelPartForStreamRoot<T>::GetRootName() const
{
diff --git a/slicer/test/compilation.cpp b/slicer/test/compilation.cpp
index ba7c568..14bf1d9 100644
--- a/slicer/test/compilation.cpp
+++ b/slicer/test/compilation.cpp
@@ -23,22 +23,24 @@ BOOST_TEST_DONT_PRINT_LOG_VALUE(std::type_info)
BOOST_TEST_DONT_PRINT_LOG_VALUE(Slicer::ModelPartType)
// LCOV_EXCL_STOP
-#define TypeTest(Var, Expr, Explicit, Expected) \
+#define TypeTest(Var, Expr, Explicit, Expected, ...) \
Var obj = Expr; \
- Slicer::ModelPartPtr mpp = Slicer::ModelPart::CreateFor(obj); \
- BOOST_REQUIRE_EQUAL(Slicer::Expected, mpp->GetType()); \
+ Slicer::ModelPart::CreateFor(obj, [](auto && mpp) { \
+ BOOST_REQUIRE_EQUAL(Slicer::Expected, mpp->GetType()); \
\
- BOOST_TEST_CONTEXT(#Var) { \
- auto mppvalue = mpp.get(); \
- auto amppvalue = mpp.get(); \
- auto apmppvalue = mpp.get(); \
- BOOST_TEST_CONTEXT(typeid(*mppvalue).name()) { \
- BOOST_REQUIRE_EQUAL(typeid(*mppvalue), typeid(*amppvalue)); \
- BOOST_REQUIRE_EQUAL(typeid(*mppvalue), typeid(*apmppvalue)); \
+ BOOST_TEST_CONTEXT(#Var) { \
+ auto mppvalue = mpp.get(); \
+ auto amppvalue = mpp.get(); \
+ auto apmppvalue = mpp.get(); \
+ BOOST_TEST_CONTEXT(typeid(*mppvalue).name()) { \
+ BOOST_REQUIRE_EQUAL(typeid(*mppvalue), typeid(*amppvalue)); \
+ BOOST_REQUIRE_EQUAL(typeid(*mppvalue), typeid(*apmppvalue)); \
+ } \
} \
- }
+ __VA_ARGS__ \
+ });
-#define StackTypeTest(Var, Explicit, Expected) TypeTest(Var, Var(), Explicit, Expected)
+#define StackTypeTest(Var, Explicit, Expected, ...) TypeTest(Var, Var(), Explicit, Expected, __VA_ARGS__)
constexpr auto DontCall = [](auto &&...) {
BOOST_ERROR("Shouldn't be called");
@@ -47,8 +49,7 @@ constexpr auto DontCall = [](auto &&...) {
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_class)
{
TypeTest(TestModule::BuiltInsPtr, std::make_shared<TestModule::BuiltIns>(), ModelPartForClass,
- ModelPartType::Complex);
- BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error);
+ ModelPartType::Complex, { BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error); });
}
static void
@@ -64,42 +65,45 @@ hookHandler(std::vector<std::string> * names, const std::string & name, Slicer::
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_sequenceclasses)
{
- StackTypeTest(TestModule::Classes, ModelPartForSequence, ModelPartType::Sequence);
- mpp->OnContained([](auto && cmpp) {
- BOOST_REQUIRE(cmpp);
- BOOST_REQUIRE_EQUAL(Slicer::ModelPartType::Complex, cmpp->GetType());
- std::vector<std::string> names;
- cmpp->OnEachChild([&](auto && PH1, auto && PH2, auto && PH3) {
- hookHandler(&names, PH1, PH2, PH3);
+ StackTypeTest(TestModule::Classes, ModelPartForSequence, ModelPartType::Sequence, {
+ mpp->OnContained([](auto && cmpp) {
+ BOOST_REQUIRE(cmpp);
+ BOOST_REQUIRE_EQUAL(Slicer::ModelPartType::Complex, cmpp->GetType());
+ std::vector<std::string> names;
+ cmpp->OnEachChild([&](auto && PH1, auto && PH2, auto && PH3) {
+ hookHandler(&names, PH1, PH2, PH3);
+ });
+ BOOST_REQUIRE_EQUAL(2, names.size());
+ BOOST_REQUIRE_EQUAL("a", names.front());
+ BOOST_REQUIRE_EQUAL("b", names.back());
});
- BOOST_REQUIRE_EQUAL(2, names.size());
- BOOST_REQUIRE_EQUAL("a", names.front());
- BOOST_REQUIRE_EQUAL("b", names.back());
});
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_sequencestructs)
{
- StackTypeTest(TestModule::Structs, ModelPartForSequence, ModelPartType::Sequence);
- mpp->OnContained([](auto && cmpp) {
- BOOST_REQUIRE(cmpp);
- BOOST_REQUIRE_EQUAL(Slicer::ModelPartType::Complex, cmpp->GetType());
- std::vector<std::string> names;
- cmpp->OnEachChild([&](auto && PH1, auto && PH2, auto && PH3) {
- hookHandler(&names, PH1, PH2, PH3);
+ StackTypeTest(TestModule::Structs, ModelPartForSequence, ModelPartType::Sequence, {
+ mpp->OnContained([](auto && cmpp) {
+ BOOST_REQUIRE(cmpp);
+ BOOST_REQUIRE_EQUAL(Slicer::ModelPartType::Complex, cmpp->GetType());
+ std::vector<std::string> names;
+ cmpp->OnEachChild([&](auto && PH1, auto && PH2, auto && PH3) {
+ hookHandler(&names, PH1, PH2, PH3);
+ });
+ BOOST_REQUIRE_EQUAL(2, names.size());
+ BOOST_REQUIRE_EQUAL("a", names.front());
+ BOOST_REQUIRE_EQUAL("b", names.back());
});
- BOOST_REQUIRE_EQUAL(2, names.size());
- BOOST_REQUIRE_EQUAL("a", names.front());
- BOOST_REQUIRE_EQUAL("b", names.back());
});
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_mapclasses)
{
- StackTypeTest(TestModule::ClassMap, ModelPartForDictionary, ModelPartType::Dictionary);
- mpp->OnContained([](auto && cmpp) {
- BOOST_REQUIRE(cmpp);
- BOOST_REQUIRE_EQUAL(Slicer::ModelPartType::Complex, cmpp->GetType());
+ StackTypeTest(TestModule::ClassMap, ModelPartForDictionary, ModelPartType::Dictionary, {
+ mpp->OnContained([](auto && cmpp) {
+ BOOST_REQUIRE(cmpp);
+ BOOST_REQUIRE_EQUAL(Slicer::ModelPartType::Complex, cmpp->GetType());
+ });
});
}
@@ -110,124 +114,130 @@ 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_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error);
+ StackTypeTest(std::string, ModelPartForSimple, ModelPartType::Simple,
+ { BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error); });
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_bool)
{
- StackTypeTest(bool, ModelPartForSimple, ModelPartType::Simple);
- BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error);
+ StackTypeTest(bool, ModelPartForSimple, ModelPartType::Simple,
+ { BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error); });
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_float)
{
- StackTypeTest(Ice::Float, ModelPartForSimple, ModelPartType::Simple);
- BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error);
+ StackTypeTest(Ice::Float, ModelPartForSimple, ModelPartType::Simple,
+ { BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error); });
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_double)
{
- StackTypeTest(Ice::Double, ModelPartForSimple, ModelPartType::Simple);
- BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error);
+ StackTypeTest(Ice::Double, ModelPartForSimple, ModelPartType::Simple,
+ { BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error); });
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_byte)
{
- StackTypeTest(Ice::Byte, ModelPartForSimple, ModelPartType::Simple);
- BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error);
+ StackTypeTest(Ice::Byte, ModelPartForSimple, ModelPartType::Simple,
+ { BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error); });
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_short)
{
- StackTypeTest(Ice::Short, ModelPartForSimple, ModelPartType::Simple);
- BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error);
+ StackTypeTest(Ice::Short, ModelPartForSimple, ModelPartType::Simple,
+ { BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error); });
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_int)
{
- StackTypeTest(Ice::Int, ModelPartForSimple, ModelPartType::Simple);
- BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error);
+ StackTypeTest(Ice::Int, ModelPartForSimple, ModelPartType::Simple,
+ { BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error); });
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_bi_long)
{
- StackTypeTest(Ice::Long, ModelPartForSimple, ModelPartType::Simple);
- BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error);
+ StackTypeTest(Ice::Long, ModelPartForSimple, ModelPartType::Simple,
+ { BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error); });
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_struct)
{
- StackTypeTest(TestModule::StructType, ModelPartForStruct, ModelPartType::Complex);
- BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error);
+ StackTypeTest(TestModule::StructType, ModelPartForStruct, ModelPartType::Complex,
+ { BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error); });
}
BOOST_AUTO_TEST_CASE(compile_auto_modelpart_type_enum)
{
- StackTypeTest(TestModule::SomeNumbers, ModelPartForEnum, ModelPartType::Simple);
- BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error);
+ StackTypeTest(TestModule::SomeNumbers, ModelPartForEnum, ModelPartType::Simple,
+ { BOOST_CHECK_THROW(mpp->OnContained(DontCall), std::logic_error); });
}
BOOST_AUTO_TEST_CASE(normalClassTypeId)
{
TestModule::BasePtr base = std::make_shared<TestModule::Base>(1);
BOOST_REQUIRE(base);
- auto a = Slicer::ModelPart::CreateFor(base);
- BOOST_REQUIRE(a);
- auto baseType = a->GetTypeId();
- BOOST_REQUIRE(!baseType);
+ Slicer::ModelPart::CreateFor(base, [](auto && a) {
+ BOOST_REQUIRE(a);
+ auto baseType = a->GetTypeId();
+ BOOST_REQUIRE(!baseType);
+ });
}
BOOST_AUTO_TEST_CASE(normalSubClassTypeId)
{
TestModule::BasePtr base = std::make_shared<TestModule::D1>(1, 2);
BOOST_REQUIRE(base);
- auto a = Slicer::ModelPart::CreateFor(base);
- BOOST_REQUIRE(a);
- auto baseType = a->GetTypeId();
- BOOST_REQUIRE(baseType);
- BOOST_REQUIRE_EQUAL(*baseType, "::TestModule::D1");
+ Slicer::ModelPart::CreateFor(base, [](auto && a) {
+ BOOST_REQUIRE(a);
+ auto baseType = a->GetTypeId();
+ BOOST_REQUIRE(baseType);
+ BOOST_REQUIRE_EQUAL(*baseType, "::TestModule::D1");
+ });
}
BOOST_AUTO_TEST_CASE(normalSubSubClassTypeId)
{
TestModule::BasePtr base = std::make_shared<TestModule::D3>(1, 2, 3);
BOOST_REQUIRE(base);
- auto a = Slicer::ModelPart::CreateFor(base);
- BOOST_REQUIRE(a);
- auto baseType = a->GetTypeId();
- BOOST_REQUIRE(baseType);
- BOOST_REQUIRE_EQUAL(*baseType, "::TestModule::D3");
+ Slicer::ModelPart::CreateFor(base, [](auto && a) {
+ BOOST_REQUIRE(a);
+ auto baseType = a->GetTypeId();
+ BOOST_REQUIRE(baseType);
+ BOOST_REQUIRE_EQUAL(*baseType, "::TestModule::D3");
+ });
}
BOOST_AUTO_TEST_CASE(localClassTypeId)
{
Locals::LocalClassPtr base = std::make_shared<Locals::LocalClass>(1, "One");
BOOST_REQUIRE(base);
- auto a = Slicer::ModelPart::CreateFor(base);
- BOOST_REQUIRE(a);
- auto baseType = a->GetTypeId();
- BOOST_REQUIRE(!baseType);
+ Slicer::ModelPart::CreateFor(base, [](auto && a) {
+ BOOST_REQUIRE(a);
+ auto baseType = a->GetTypeId();
+ BOOST_REQUIRE(!baseType);
+ });
}
BOOST_AUTO_TEST_CASE(localSubClassTypeId)
{
Locals::LocalClassPtr base = std::make_shared<Locals::LocalSubClass>(1, "One", 3.1);
BOOST_REQUIRE(base);
- auto a = Slicer::ModelPart::CreateFor(base);
- BOOST_REQUIRE(a);
- auto baseType = a->GetTypeId();
- BOOST_REQUIRE(baseType);
- BOOST_REQUIRE_EQUAL(*baseType, "::Locals::LocalSubClass");
+ Slicer::ModelPart::CreateFor(base, [](auto && a) {
+ BOOST_REQUIRE(a);
+ auto baseType = a->GetTypeId();
+ BOOST_REQUIRE(baseType);
+ BOOST_REQUIRE_EQUAL(*baseType, "::Locals::LocalSubClass");
+ });
}
BOOST_AUTO_TEST_CASE(localSubSubClassTypeId)
{
Locals::LocalClassPtr base = std::make_shared<Locals::LocalSub2Class>(1, "One", 3.1, 1);
BOOST_REQUIRE(base);
- auto a = Slicer::ModelPart::CreateFor(base);
- BOOST_REQUIRE(a);
- auto baseType = a->GetTypeId();
- BOOST_REQUIRE(baseType);
- BOOST_REQUIRE_EQUAL(*baseType, "::Locals::LocalSub2Class");
+ Slicer::ModelPart::CreateFor(base, [](auto && a) {
+ BOOST_REQUIRE(a);
+ auto baseType = a->GetTypeId();
+ BOOST_REQUIRE(baseType);
+ BOOST_REQUIRE_EQUAL(*baseType, "::Locals::LocalSub2Class");
+ });
}
diff --git a/slicer/test/conversions.cpp b/slicer/test/conversions.cpp
index a296197..193cd4f 100644
--- a/slicer/test/conversions.cpp
+++ b/slicer/test/conversions.cpp
@@ -175,9 +175,9 @@ namespace TestModule {
namespace Slicer {
template<>
- DLL_PUBLIC ModelPartPtr
- ModelPart::Make<TestModule::MonthValidator>(::Ice::Short * m)
+ DLL_PUBLIC void
+ ModelPart::Make<TestModule::MonthValidator>(::Ice::Short * m, const ModelPartHandler & h)
{
- return std::make_shared<TestModule::MonthValidator>(m);
+ return h(TestModule::MonthValidator(m));
}
}
diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp
index 6a41cdd..f02dbaf 100644
--- a/slicer/test/serializers.cpp
+++ b/slicer/test/serializers.cpp
@@ -710,6 +710,8 @@ BOOST_AUTO_TEST_CASE(enum_lookups)
BOOST_AUTO_TEST_CASE(sequence_element_in_same_slice_link_bug)
{
// Link error when sequence element type defined in same slice.
- BOOST_CHECK(Slicer::ModelPart::Make<Slicer::ModelPartForSequence<TestModule::Classes>>(nullptr));
- BOOST_CHECK(Slicer::ModelPart::Make<Slicer::ModelPartForSequence<TestModule::Dates>>(nullptr));
+ BOOST_CHECK_NO_THROW(
+ Slicer::ModelPart::Make<Slicer::ModelPartForSequence<TestModule::Classes>>(nullptr, [](auto &&) {}));
+ BOOST_CHECK_NO_THROW(
+ Slicer::ModelPart::Make<Slicer::ModelPartForSequence<TestModule::Dates>>(nullptr, [](auto &&) {}));
}
diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp
index 28252b5..55a06fe 100644
--- a/slicer/tool/parser.cpp
+++ b/slicer/tool/parser.cpp
@@ -238,13 +238,13 @@ namespace Slicer {
fprintbf(cpp, "\tconversion_fail(\"%s\");\n", Slice::typeToString(type));
fprintbf(cpp, "}\n\n");
- fprintbf(cpp, "\ttemplate<> DLL_PUBLIC ModelPartPtr ModelPart::Make<");
+ fprintbf(cpp, "\ttemplate<> DLL_PUBLIC void ModelPart::Make<");
createModelPartForConverted(type, c->scoped(), dm);
fprintbf(cpp, ">(typename ");
createModelPartForConverted(type, c->scoped(), dm);
- fprintbf(cpp, "::element_type * t) { return std::make_shared<");
+ fprintbf(cpp, "::element_type * t, const ModelPartHandler & h) { return h(");
createModelPartForConverted(type, c->scoped(), dm);
- fprintbf(cpp, ">(t); } \n");
+ fprintbf(cpp, "(t)); } \n");
}
}
@@ -444,9 +444,9 @@ namespace Slicer {
if (auto cmp = md.value("slicer:custommodelpart:")) {
fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, %s< %s >, %s)\n\n", Slice::typeToString(decl),
getBasicModelPart(decl), c->scoped(), CppName {*cmp});
- fprintbf(cpp, "\ttemplate<> DLL_PUBLIC ModelPartPtr ModelPart::Make<%s<%s> >(%s * t)",
+ fprintbf(cpp, "\ttemplate<> DLL_PUBLIC void ModelPart::Make<%s<%s> >(%s * t, const ModelPartHandler & h)",
getBasicModelPart(decl), c->scoped(), Slice::typeToString(decl));
- fprintbf(cpp, "{ return std::make_shared<%s>(t); } \n", CppName {*cmp});
+ fprintbf(cpp, "{ return h(%s(t)); } \n", CppName {*cmp});
}
else {
fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, ModelPartForClass<%s>, ModelPartForClass<%s>)\n\n",
@@ -764,9 +764,9 @@ namespace Slicer {
if (auto cmp = metadata.value("slicer:custommodelpart:")) {
fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, %s< %s >, %s)\n\n", type, getBasicModelPart(stype), type,
CppName {*cmp});
- fprintbf(cpp, "\ttemplate<> DLL_PUBLIC ModelPartPtr ModelPart::Make<%s<%s>>(%s * t)",
+ fprintbf(cpp, "\ttemplate<> DLL_PUBLIC void ModelPart::Make<%s<%s>>(%s * t, const ModelPartHandler & h)",
getBasicModelPart(stype), type, type);
- fprintbf(cpp, "{ return std::make_shared<%s>(t); } \n", CppName {*cmp});
+ fprintbf(cpp, "{ return h(%s(t)); } \n", CppName {*cmp});
}
else {
fprintbf(cpp, "MODELPARTFOR(%s, %s)\n\n", type, getBasicModelPart(stype));