From f42d9dc3ca8a09478a25ead5a46040b2fa2d9acb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 25 Oct 2020 16:47:52 +0000 Subject: Combine Hook and HookMetaData --- slicer/slicer/hook-test.cpp | 8 +++---- slicer/slicer/modelPartsTypes.h | 4 +--- slicer/slicer/modelPartsTypes.impl.h | 41 ++++++++++-------------------------- slicer/tool/parser.cpp | 8 +++---- 4 files changed, 19 insertions(+), 42 deletions(-) diff --git a/slicer/slicer/hook-test.cpp b/slicer/slicer/hook-test.cpp index 11641c2..d478beb 100644 --- a/slicer/slicer/hook-test.cpp +++ b/slicer/slicer/hook-test.cpp @@ -13,11 +13,11 @@ struct S { const std::string aa {"aa"}, aA {"aA"}, Aa {"Aa"}, AA {"AA"}, b {"b"}; using C = Slicer::ModelPartForComplex; -constexpr C::Hook> haa {&S::aa, "aa", "aa", &aa}; -constexpr C::Hook> haA {&S::aA, "aA", "aa", &aA}; -constexpr C::Hook> hAa {&S::Aa, "Aa", "aa", &Aa}; +constexpr C::Hook, 0> haa {&S::aa, "aa", "aa", &aa}; +constexpr C::Hook, 1> haA {&S::aA, "aA", "aa", &aA, "md1"}; +constexpr C::Hook, 3> hAa {&S::Aa, "Aa", "aa", &Aa, "md2", "md3", "md4"}; constexpr C::Hook> hAA {&S::AA, "AA", "aa", &AA}; -constexpr C::Hook> hb {&S::b, "b", "b", &b}; +constexpr C::Hook, 0> hb {&S::b, "b", "b", &b}; constexpr Slicer::HooksImpl h {{{&haa, &haA, &hAa, &hAA, &hb}}}; static_assert(h.arr.size() == 5); diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index eff56b7..087c318 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -144,9 +144,7 @@ namespace Slicer { public: class DLL_PRIVATE HookBase; - template class DLL_PRIVATE Hook; - - template class DLL_PRIVATE HookMetadata; + template class DLL_PRIVATE Hook; void OnEachChild(const ChildHandler & ch) override; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index f8e2a65..87094e5 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -449,42 +449,15 @@ namespace Slicer { using HookCommon::HookCommon; virtual ModelPartPtr Get(T * t) const = 0; - [[nodiscard]] const Metadata & - GetMetadata() const override - { - return emptyMetadata; - } - }; - - template - template - class DLL_PRIVATE ModelPartForComplex::Hook : public ModelPartForComplex::HookBase { - public: - constexpr Hook(MT T::*m, std::string_view n, std::string_view nl, const std::string * ns) : - HookBase(n, nl, ns), member(m) - { - } - - ModelPartPtr - Get(T * t) const override - { - return std::make_shared( - t ? const_cast::type *>(&(t->*member)) : nullptr); - } - - private: - const MT T::*member; }; template template - class DLL_PRIVATE ModelPartForComplex::HookMetadata : public ModelPartForComplex::template Hook { + class DLL_PRIVATE ModelPartForComplex::Hook : public ModelPartForComplex::HookBase { public: template - constexpr HookMetadata( - MT T::*member, std::string_view n, std::string_view nl, const std::string * ns, MD &&... md) : - Hook(member, n, nl, ns), - hookMetadata {{std::forward(md)...}} + constexpr Hook(MT T::*m, std::string_view n, std::string_view nl, const std::string * ns, MD &&... md) : + HookBase(n, nl, ns), member(m), hookMetadata {{std::forward(md)...}} { static_assert(sizeof...(MD) == N, "Wrong amount of metadata"); } @@ -495,7 +468,15 @@ namespace Slicer { return hookMetadata; } + ModelPartPtr + Get(T * t) const override + { + return std::make_shared( + t ? const_cast::type *>(&(t->*member)) : nullptr); + } + private: + const MT T::*member; const MetaDataImpl hookMetadata; }; diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index ef9139d..ba776b4 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -407,12 +407,10 @@ namespace Slicer { t = Slice::ClassDefPtr::dynamicCast(dm->container())->declaration(); } auto type = dm->type(); - fprintbf(cpp, "\tconstexpr C%d::%s<", components, md.countSlicerMetaData() ? "HookMetadata" : "Hook"); + fprintbf(cpp, "\tconstexpr C%d::Hook<", components); fprintbf(cpp, " %s, ", Slice::typeToString(type, dm->optional())); createNewModelPartPtrFor(type, dm, md); - if (auto n = md.countSlicerMetaData()) { - fprintbf(cpp, ", %d", n); - } + fprintbf(cpp, ", %d", md.countSlicerMetaData()); fprintbf(cpp, " > hook%d_%d {&%s, \"%s\", \"%s\", &hstr%d_%d", components, en, dm->scoped(), name, lname, components, en); if (md.hasSlicerMetaData()) { @@ -558,7 +556,7 @@ namespace Slicer { fprintbf(cpp, "\tconst std::string hstr%d_%d { \"%s\" };\n", components, element, name); fprintbf(cpp, "\tconstexpr C%d::Hook< const %s, ", components, Slice::typeToString(t)); createNewModelPartPtrFor(t); - fprintbf(cpp, " > hook%d_%s {&%s::value_type::%s, \"%s\", \"%s\", &hstr%d_%s};\n", components, element, + fprintbf(cpp, ", 0 > hook%d_%s {&%s::value_type::%s, \"%s\", \"%s\", &hstr%d_%s};\n", components, element, d->scoped(), element, name, lname, components, element); }; addHook(md.value("slicer:key:").value_or("key"), "first", d->keyType()); -- cgit v1.2.3