From 1cc058e2bf7bd8b4822609d3322ab4d55fd66ffe Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 30 Sep 2023 12:07:59 +0100 Subject: Include typename in LocalTypeException and simplify ICE read/write functions --- slicer/slicer/common.ice | 4 ++- slicer/slicer/modelParts.h | 3 ++ slicer/slicer/modelPartsTypes.cpp | 6 ++++ slicer/slicer/modelPartsTypes.impl.h | 68 +++++++++++------------------------- 4 files changed, 32 insertions(+), 49 deletions(-) diff --git a/slicer/slicer/common.ice b/slicer/slicer/common.ice index ad3ff1f..c082102 100644 --- a/slicer/slicer/common.ice +++ b/slicer/slicer/common.ice @@ -19,7 +19,9 @@ module Slicer { ["cpp:ice_print"] exception UnsupportedModelType extends RuntimeError { }; ["cpp:ice_print"] - exception LocalTypeException extends RuntimeError { }; + exception LocalTypeException extends RuntimeError { + string type; + }; ["cpp:ice_print"] exception NoConversionFound extends RuntimeError { string type; diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 65be827..c9be22e 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -185,5 +185,8 @@ namespace Slicer { void OnContained(const ModelPartHandler &) override; ModelPartParam mp; + + protected: + [[noreturn]] static void throwLocalTypeException(const std::type_info &); }; } diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp index 0e3f78a..c2c8e79 100644 --- a/slicer/slicer/modelPartsTypes.cpp +++ b/slicer/slicer/modelPartsTypes.cpp @@ -157,6 +157,12 @@ namespace Slicer { return mp->OnContained(h); } + void + ModelPartForRootBase::throwLocalTypeException(const std::type_info & type) + { + throw LocalTypeException(ModelPartForComplexBase::demangle(type.name())); + } + bool ModelPartForSimpleBase::HasValue() const { diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index b1f0df8..9c141f7 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -133,70 +133,42 @@ namespace Slicer { template void - typeWrite(::Ice::OutputStream & s, const ::Ice::optional & m) - { - if constexpr (!isLocal::value) { - s.startEncapsulation(); - s.write(0, m); - s.endEncapsulation(); - } - else { - throw LocalTypeException(); - } - } - - template - void - typeWrite(::Ice::OutputStream & s, const T & m) - { - if constexpr (!isLocal::value) { - s.write(m); - } - else { - throw LocalTypeException(); - } - } - - template - void - typeRead(::Ice::InputStream & s, ::Ice::optional & m) + ModelPartForRoot::Write(::Ice::OutputStream & s) const { if constexpr (!isLocal::value) { - s.startEncapsulation(); - s.read(0, m); - s.endEncapsulation(); + if constexpr (isOptional::value) { + s.startEncapsulation(); + s.write(0, *ModelObject); + s.endEncapsulation(); + } + else { + s.write(*ModelObject); + } } else { - throw LocalTypeException(); + ModelPartForRootBase::throwLocalTypeException(typeid(T)); } } template void - typeRead(::Ice::InputStream & s, T & m) + ModelPartForRoot::Read(::Ice::InputStream & s) { if constexpr (!isLocal::value) { - s.read(m); + if constexpr (isOptional::value) { + s.startEncapsulation(); + s.read(0, *ModelObject); + s.endEncapsulation(); + } + else { + s.read(*ModelObject); + } } else { - throw LocalTypeException(); + ModelPartForRootBase::throwLocalTypeException(typeid(T)); } } - template - void - ModelPartForRoot::Write(::Ice::OutputStream & s) const - { - typeWrite(s, *ModelObject); - } - - template - void - ModelPartForRoot::Read(::Ice::InputStream & s) - { - typeRead(s, *ModelObject); - } - // ModelPartForSimple template void -- cgit v1.2.3