From 80764e501b43498ee229677c2691c2579d7bfb2c Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 7 Nov 2020 01:48:32 +0000 Subject: No need to generate sequence GetChildRef Can be implemented in sequence base with a virtual to get elementName --- slicer/slicer/modelPartsTypes.cpp | 8 ++++++++ slicer/slicer/modelPartsTypes.h | 5 ++++- slicer/slicer/modelPartsTypes.impl.h | 7 +++++++ slicer/tool/parser.cpp | 17 ----------------- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp index 8ebe127..f674bd0 100644 --- a/slicer/slicer/modelPartsTypes.cpp +++ b/slicer/slicer/modelPartsTypes.cpp @@ -348,6 +348,14 @@ namespace Slicer { { return type; } + ChildRef + ModelPartForSequenceBase::GetChildRef(std::string_view name, const HookFilter & flt, bool matchCase) + { + if (!name.empty() && !optionalCaseEq(name, GetElementName(), matchCase)) { + throw IncorrectElementName(std::string {name}); + } + return GetAnonChildRef(flt); + } const ModelPartType ModelPartForSequenceBase::type = ModelPartType::Sequence; bool diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 3dac906..28054a8 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -238,6 +238,9 @@ namespace Slicer { public: bool HasValue() const override; ModelPartType GetType() const override; + ChildRef GetChildRef(std::string_view, const HookFilter &, bool matchCase = true) override; + virtual const std::string & GetElementName() const = 0; + static const ModelPartType type; }; @@ -251,7 +254,7 @@ namespace Slicer { ChildRef GetAnonChildRef(const HookFilter &) override; - ChildRef GetChildRef(std::string_view, const HookFilter &, bool matchCase = true) override; + const std::string & GetElementName() const override; const Metadata & GetMetadata() const override; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index b75ad36..9048cf2 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -571,6 +571,13 @@ namespace Slicer { return metadata; } + template + const std::string & + ModelPartForSequence::GetElementName() const + { + return elementName; + } + template ModelPartPtr ModelPartForSequence::elementModelPart(typename T::value_type & e) const diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index ef468e8..79ea98a 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -488,25 +488,8 @@ namespace Slicer { fprintbf(cpp, "// Sequence %s\n", s->name()); externType(s->type()); - fprintbf(cpp, "template<>\n"); - fprintbf(cpp, - "ChildRef ModelPartForSequence< %s >::GetChildRef(std::string_view name, const HookFilter & flt, " - "bool matchCase)\n{\n", - s->scoped()); const IceMetaData md {s->getMetaData()}; auto ename = md.value("slicer:element:"); - if (ename) { - fprintbf(cpp, - "\tif (!name.empty() && !optionalCaseEq(name, \"%s\", matchCase)) { throw " - "IncorrectElementName(std::string{name}); }\n", - *ename); - } - else { - fprintbf(cpp, "\t(void)matchCase;\n"); - fprintbf(cpp, "\t(void)name;\n"); - } - fprintbf(cpp, "\treturn GetAnonChildRef(flt);\n}\n\n"); - fprintbf(cpp, "template<> DLL_PUBLIC\n"); fprintbf(cpp, "const std::string ModelPartForSequence< %s >::elementName(\"%s\");\n\n", s->scoped(), ename ? *ename : "element"); -- cgit v1.2.3