From f8ebd0e2e590806bbdcc022343429699217c8787 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 25 Oct 2020 18:07:08 +0000 Subject: string_view child ref uplooks --- slicer/json/serializer.cpp | 6 +++--- slicer/slicer/hookMap.h | 10 ++++++---- slicer/slicer/modelParts.cpp | 2 +- slicer/slicer/modelParts.h | 6 +++--- slicer/slicer/modelPartsTypes.cpp | 16 ++++++++-------- slicer/slicer/modelPartsTypes.h | 18 +++++++++--------- slicer/slicer/modelPartsTypes.impl.h | 6 +++--- slicer/tool/parser.cpp | 2 +- slicer/xml/serializer.cpp | 8 ++++---- 9 files changed, 38 insertions(+), 36 deletions(-) diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp index aaf1999..cf165b2 100644 --- a/slicer/json/serializer.cpp +++ b/slicer/json/serializer.cpp @@ -17,9 +17,9 @@ NAMEDFACTORY("application/json", Slicer::JsonStreamSerializer, Slicer::StreamSer NAMEDFACTORY("application/json", Slicer::JsonStreamDeserializer, Slicer::StreamDeserializerFactory); namespace Slicer { - const std::string md_object = "json:object"; - const std::string keyName = "key"; - const std::string valueName = "value"; + constexpr std::string_view md_object {"json:object"}; + constexpr std::string_view keyName {"key"}; + constexpr std::string_view valueName {"value"}; using namespace std::placeholders; diff --git a/slicer/slicer/hookMap.h b/slicer/slicer/hookMap.h index 153f9c0..8eba5f5 100644 --- a/slicer/slicer/hookMap.h +++ b/slicer/slicer/hookMap.h @@ -98,21 +98,23 @@ namespace Slicer { constexpr inline eq equal_range(K && k) const { - return {std::move(k), &HookCommon::name, _begin, _end}; + return {std::forward(k), &HookCommon::name, _begin, _end}; } template constexpr inline eq equal_range_lower(K && k) const { - return {std::move(k), &HookCommon::nameLower, _begin, _end}; + return {std::forward(k), &HookCommon::nameLower, _begin, _end}; } template - inline eq + inline auto equal_range_nocase(const K & k) const { - return equal_range_lower(boost::algorithm::to_lower_copy(k)); + std::string i {k}; + boost::algorithm::to_lower(i); + return equal_range_lower(std::move(i)); } constexpr inline auto diff --git a/slicer/slicer/modelParts.cpp b/slicer/slicer/modelParts.cpp index bbb142a..83c65c5 100644 --- a/slicer/slicer/modelParts.cpp +++ b/slicer/slicer/modelParts.cpp @@ -54,7 +54,7 @@ namespace Slicer { } ModelPartPtr - ModelPart::GetChild(const std::string & memberName, const HookFilter & flt) + ModelPart::GetChild(std::string_view memberName, const HookFilter & flt) { auto ref = GetChildRef(memberName, flt); return ref ? ref.Child() : ModelPartPtr(nullptr); diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 1596ad8..6af9344 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -139,10 +139,10 @@ namespace Slicer { virtual void OnEachChild(const ChildHandler &) = 0; ModelPartPtr GetAnonChild(const HookFilter & = HookFilter()); - ModelPartPtr GetChild(const std::string & memberName, const HookFilter & = HookFilter()); + ModelPartPtr GetChild(std::string_view memberName, const HookFilter & = HookFilter()); virtual ChildRef GetAnonChildRef(const HookFilter & = HookFilter()) = 0; virtual ChildRef GetChildRef( - const std::string & memberName, const HookFilter & = HookFilter(), bool matchCase = true) + std::string_view memberName, const HookFilter & = HookFilter(), bool matchCase = true) = 0; virtual ModelPartPtr GetSubclassModelPart(const std::string &); virtual TypeId GetTypeId() const; @@ -171,7 +171,7 @@ namespace Slicer { virtual const std::string & GetRootName() const = 0; ChildRef GetAnonChildRef(const HookFilter &) override; - ChildRef GetChildRef(const std::string & name, const HookFilter &, bool matchCase = true) override; + ChildRef GetChildRef(std::string_view name, const HookFilter &, bool matchCase = true) override; void OnEachChild(const ChildHandler & ch) override; ModelPartType GetType() const override; bool IsOptional() const override; diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp index 4ba7557..8cc8656 100644 --- a/slicer/slicer/modelPartsTypes.cpp +++ b/slicer/slicer/modelPartsTypes.cpp @@ -101,7 +101,7 @@ namespace Slicer { MODELPARTFOR(Ice::Long, ModelPartForSimple); bool - optionalCaseEq(const std::string & a, const std::string & b, bool matchCase) + optionalCaseEq(std::string_view a, std::string_view b, bool matchCase) { return (matchCase ? boost::equals(a, b) : boost::iequals(a, b)); } @@ -117,10 +117,10 @@ namespace Slicer { } ChildRef - ModelPartForRootBase::GetChildRef(const std::string & name, const HookFilter & hf, bool matchCase) + ModelPartForRootBase::GetChildRef(std::string_view name, const HookFilter & hf, bool matchCase) { if (!optionalCaseEq(name, GetRootName(), matchCase)) { - throw IncorrectElementName(name); + throw IncorrectElementName(std::string {name}); } return GetAnonChildRef(hf); } @@ -159,7 +159,7 @@ namespace Slicer { return ChildRef(); } ChildRef - ModelPartForSimpleBase::GetChildRef(const std::string &, const HookFilter &, bool) + ModelPartForSimpleBase::GetChildRef(std::string_view, const HookFilter &, bool) { return ChildRef(); } @@ -185,7 +185,7 @@ namespace Slicer { return ChildRef(); } ChildRef - ModelPartForConvertedBase::GetChildRef(const std::string &, const HookFilter &, bool) + ModelPartForConvertedBase::GetChildRef(std::string_view, const HookFilter &, bool) { return ChildRef(); } @@ -273,7 +273,7 @@ namespace Slicer { } ChildRef - ModelPartForOptionalBase::GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase) + ModelPartForOptionalBase::GetChildRef(std::string_view name, const HookFilter & flt, bool matchCase) { if (this->hasModel()) { return modelPart->GetChildRef(name, flt, matchCase); @@ -317,7 +317,7 @@ namespace Slicer { return ChildRef(); } ChildRef - ModelPartForEnumBase::GetChildRef(const std::string &, const HookFilter &, bool) + ModelPartForEnumBase::GetChildRef(std::string_view, const HookFilter &, bool) { return ChildRef(); } @@ -366,7 +366,7 @@ namespace Slicer { } // NOLINTNEXTLINE(hicpp-no-array-decay) ChildRef - ModelPartForStreamBase::GetChildRef(const std::string &, const Slicer::HookFilter &, bool) + ModelPartForStreamBase::GetChildRef(std::string_view, const Slicer::HookFilter &, bool) { throw InvalidStreamOperation(__FUNCTION__); } diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 087c318..f9c76d4 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -10,7 +10,7 @@ namespace Slicer { static constexpr bool value = false; }; - DLL_PUBLIC bool optionalCaseEq(const std::string & a, const std::string & b, bool matchCase); + DLL_PUBLIC bool optionalCaseEq(std::string_view a, std::string_view b, bool matchCase); template class DLL_PUBLIC ModelPartForRoot : public ModelPartForRootBase { public: @@ -31,7 +31,7 @@ namespace Slicer { public: void OnEachChild(const ChildHandler &) override; ChildRef GetAnonChildRef(const HookFilter &) override; - ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; + ChildRef GetChildRef(std::string_view, const HookFilter &, bool matchCase = true) override; bool HasValue() const override; ModelPartType GetType() const override; static const ModelPartType type; @@ -52,7 +52,7 @@ namespace Slicer { public: void OnEachChild(const ChildHandler &) override; ChildRef GetAnonChildRef(const HookFilter &) override; - ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; + ChildRef GetChildRef(std::string_view, const HookFilter &, bool matchCase = true) override; bool HasValue() const override; ModelPartType GetType() const override; static const ModelPartType type; @@ -97,7 +97,7 @@ namespace Slicer { void OnEachChild(const ChildHandler & ch) override; void Complete() override; ChildRef GetAnonChildRef(const HookFilter & flt) override; - ChildRef GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase = true) override; + ChildRef GetChildRef(std::string_view name, const HookFilter & flt, bool matchCase = true) override; void SetValue(ValueSource && s) override; bool HasValue() const override; bool IsOptional() const override; @@ -149,7 +149,7 @@ namespace Slicer { void OnEachChild(const ChildHandler & ch) override; ChildRef GetAnonChildRef(const HookFilter & flt) override; - ChildRef GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase = true) override; + ChildRef GetChildRef(std::string_view name, const HookFilter & flt, bool matchCase = true) override; const Metadata & GetMetadata() const override; @@ -215,7 +215,7 @@ namespace Slicer { public: void OnEachChild(const ChildHandler &) override; ChildRef GetAnonChildRef(const HookFilter &) override; - ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; + ChildRef GetChildRef(std::string_view, const HookFilter &, bool matchCase = true) override; bool HasValue() const override; ModelPartType GetType() const override; static const ModelPartType type; @@ -258,7 +258,7 @@ namespace Slicer { ChildRef GetAnonChildRef(const HookFilter &) override; - ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; + ChildRef GetChildRef(std::string_view, const HookFilter &, bool matchCase = true) override; const Metadata & GetMetadata() const override; @@ -302,7 +302,7 @@ namespace Slicer { ChildRef GetAnonChildRef(const HookFilter &) override; - ChildRef GetChildRef(const std::string & name, const HookFilter &, bool matchCase = true) override; + ChildRef GetChildRef(std::string_view name, const HookFilter &, bool matchCase = true) override; const Metadata & GetMetadata() const override; @@ -325,7 +325,7 @@ namespace Slicer { ModelPartType GetType() const override; bool HasValue() const override; ChildRef GetAnonChildRef(const HookFilter &) override; - ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; + ChildRef GetChildRef(std::string_view, const HookFilter &, bool matchCase = true) override; ModelPartPtr GetContainedModelPart() override = 0; void OnEachChild(const ChildHandler & ch) override = 0; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 87094e5..cb24fe4 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -434,7 +434,7 @@ namespace Slicer { template ChildRef - ModelPartForComplex::GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase) + ModelPartForComplex::GetChildRef(std::string_view name, const HookFilter & flt, bool matchCase) { if (matchCase) { return GetChildRefFromRange(hooks().equal_range(name), flt); @@ -737,11 +737,11 @@ namespace Slicer { template ChildRef - ModelPartForDictionary::GetChildRef(const std::string & name, const HookFilter &, bool matchCase) + ModelPartForDictionary::GetChildRef(std::string_view name, const HookFilter &, bool matchCase) { BOOST_ASSERT(this->Model); if (!optionalCaseEq(name, pairName, matchCase)) { - throw IncorrectElementName(name); + throw IncorrectElementName(std::string {name}); } return ChildRef(std::make_shared>(this->Model)); } diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 0a72dd5..98a41e7 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -491,7 +491,7 @@ namespace Slicer { externType(s->type()); fprintbf(cpp, "template<> DLL_PUBLIC\n"); fprintbf(cpp, - "ChildRef ModelPartForSequence< %s >::GetChildRef(const std::string & name, const HookFilter & flt, " + "ChildRef ModelPartForSequence< %s >::GetChildRef(std::string_view name, const HookFilter & flt, " "bool matchCase)\n{\n", s->scoped()); const IceMetaData md {s->getMetaData()}; diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp index afdb636..bc87e4c 100644 --- a/slicer/xml/serializer.cpp +++ b/slicer/xml/serializer.cpp @@ -22,8 +22,8 @@ namespace Slicer { constexpr std::string_view md_bare {"xml:bare"}; constexpr std::string_view md_attributes {"xml:attributes"}; constexpr std::string_view md_elements {"xml:elements"}; - const std::string keyName = "key"; - const std::string valueName = "value"; + constexpr std::string_view keyName {"key"}; + constexpr std::string_view valueName {"value"}; using ElementCreatorF = xmlpp::Element * (xmlpp::Element::*)(const Glib::ustring &, const Glib::ustring &); const auto defaultElementCreator = [](auto && element, auto && name) { return element->add_child_element(name); @@ -270,7 +270,7 @@ namespace Slicer { { while (node) { if (auto element = dynamic_cast(node)) { - auto smpr = mp->GetChildRef(element->get_name(), [](const auto & h) { + auto smpr = mp->GetChildRef(element->get_name().raw(), [](const auto & h) { return h->GetMetadata().flagNotSet(md_attribute); }); if (smpr) { @@ -284,7 +284,7 @@ namespace Slicer { } } else if (auto attribute = dynamic_cast(node)) { - auto smp = mp->GetChild(attribute->get_name(), [](const auto & h) { + auto smp = mp->GetChild(attribute->get_name().raw(), [](const auto & h) { return h->GetMetadata().flagSet(md_attribute); }); if (smp) { -- cgit v1.2.3