diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-09-04 18:29:38 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-09-04 18:29:38 +0100 |
commit | f6044ae80b48eefebd788e08427bffd9a1e0cf42 (patch) | |
tree | d76d935e2bd2bc2d51ae5651b7a26153709988ae | |
parent | Simplify defining ModelPartForRoots for base types (diff) | |
download | slicer-f6044ae80b48eefebd788e08427bffd9a1e0cf42.tar.bz2 slicer-f6044ae80b48eefebd788e08427bffd9a1e0cf42.tar.xz slicer-f6044ae80b48eefebd788e08427bffd9a1e0cf42.zip |
Fix up warnings from clang-tidy, mostly nodiscard
-rw-r--r-- | slicer/slicer/modelParts.h | 18 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.h | 62 | ||||
-rw-r--r-- | slicer/slicer/slicer.h | 4 | ||||
-rw-r--r-- | slicer/test/serializers.cpp | 17 | ||||
-rw-r--r-- | slicer/tool/slicer.cpp | 38 | ||||
-rw-r--r-- | slicer/xml/testSpecifics.cpp | 6 |
6 files changed, 74 insertions, 71 deletions
diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 7e5a732..452538a 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -148,16 +148,16 @@ namespace Slicer { virtual bool OnChild(const SubPartHandler &, std::string_view memberName, const HookFilter & = HookFilter(), MatchCase matchCase = MatchCase::Yes); virtual void OnSubclass(const ModelPartHandler &, const std::string &); - virtual TypeId GetTypeId() const; - virtual std::optional<std::string> GetTypeIdProperty() const; - virtual ModelPartType GetType() const = 0; + [[nodiscard]] virtual TypeId GetTypeId() const; + [[nodiscard]] virtual std::optional<std::string> GetTypeIdProperty() const; + [[nodiscard]] virtual ModelPartType GetType() const = 0; virtual void Create(); virtual void Complete(); virtual void SetValue(ValueSource &&); virtual bool GetValue(ValueTarget &&); - virtual bool HasValue() const = 0; - virtual const Metadata & GetMetadata() const; - virtual bool IsOptional() const; + [[nodiscard]] virtual bool HasValue() const = 0; + [[nodiscard]] virtual const Metadata & GetMetadata() const; + [[nodiscard]] virtual bool IsOptional() const; virtual void OnContained(const ModelPartHandler &); }; @@ -172,13 +172,13 @@ namespace Slicer { public: explicit ModelPartForRootBase(ModelPartParam mp); - virtual const std::string & GetRootName() const = 0; + [[nodiscard]] virtual const std::string & GetRootName() const = 0; bool OnAnonChild(const SubPartHandler &, const HookFilter &) override; bool OnChild(const SubPartHandler &, std::string_view name, const HookFilter &, MatchCase matchCase = MatchCase::Yes) override; void OnEachChild(const ChildHandler & ch) override; - ModelPartType GetType() const override; - bool IsOptional() const override; + [[nodiscard]] ModelPartType GetType() const override; + [[nodiscard]] bool IsOptional() const override; virtual void Write(::Ice::OutputStream &) const = 0; virtual void Read(::Ice::InputStream &) = 0; void OnContained(const ModelPartHandler &) override; diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 0403650..430b72f 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -27,8 +27,8 @@ namespace Slicer { public: explicit ModelPartForRoot(T * o, ModelPartParam mp); - const std::string & GetRootName() const override; - bool HasValue() const override; + [[nodiscard]] const std::string & GetRootName() const override; + [[nodiscard]] bool HasValue() const override; void Write(::Ice::OutputStream &) const override; void Read(::Ice::InputStream &) override; @@ -40,8 +40,8 @@ namespace Slicer { class DLL_PUBLIC ModelPartForSimpleBase : public ModelPart { public: - bool HasValue() const override; - ModelPartType GetType() const override; + [[nodiscard]] bool HasValue() const override; + [[nodiscard]] ModelPartType GetType() const override; static const ModelPartType type; }; @@ -58,8 +58,8 @@ namespace Slicer { class DLL_PUBLIC ModelPartForConvertedBase : public ModelPart { public: - bool HasValue() const override; - ModelPartType GetType() const override; + [[nodiscard]] bool HasValue() const override; + [[nodiscard]] ModelPartType GetType() const override; static const ModelPartType type; protected: @@ -95,7 +95,7 @@ namespace Slicer { void SetValue(ValueSource && s) override; bool GetValue(ValueTarget && s) override; - bool HasValue() const override; + [[nodiscard]] bool HasValue() const override; }; class DLL_PUBLIC ModelPartForOptionalBase : public ModelPart { @@ -106,12 +106,12 @@ namespace Slicer { bool OnChild(const SubPartHandler &, std::string_view name, const HookFilter & flt, MatchCase matchCase = MatchCase::Yes) override; void SetValue(ValueSource && s) override; - bool HasValue() const override; - bool IsOptional() const override; - const Metadata & GetMetadata() const override; + [[nodiscard]] bool HasValue() const override; + [[nodiscard]] bool IsOptional() const override; + [[nodiscard]] const Metadata & GetMetadata() const override; protected: - virtual bool hasModel() const = 0; + [[nodiscard]] virtual bool hasModel() const = 0; ModelPart * modelPart; }; @@ -124,16 +124,16 @@ namespace Slicer { explicit ModelPartForOptional(element_type * h); void Create() override; bool GetValue(ValueTarget && s) override; - ModelPartType GetType() const override; + [[nodiscard]] ModelPartType GetType() const override; protected: - bool hasModel() const override; + [[nodiscard]] bool hasModel() const override; std::optional<T> modelPartOwner; }; class DLL_PUBLIC ModelPartForComplexBase : public ModelPart { public: - ModelPartType GetType() const override; + [[nodiscard]] ModelPartType GetType() const override; static const ModelPartType type; protected: @@ -163,7 +163,7 @@ namespace Slicer { bool OnChild(const SubPartHandler &, std::string_view name, const HookFilter & flt, MatchCase matchCase = MatchCase::Yes) override; - const Metadata & GetMetadata() const override; + [[nodiscard]] const Metadata & GetMetadata() const override; virtual T * GetModel() = 0; @@ -216,8 +216,8 @@ namespace Slicer { class DLL_PUBLIC ModelPartForEnumBase : public ModelPart { public: - bool HasValue() const override; - ModelPartType GetType() const override; + [[nodiscard]] bool HasValue() const override; + [[nodiscard]] ModelPartType GetType() const override; static const ModelPartType type; }; template<typename T> class EnumMap; @@ -228,7 +228,7 @@ namespace Slicer { using ModelPartModel<T>::ModelPartModel; - const Metadata & GetMetadata() const override; + [[nodiscard]] const Metadata & GetMetadata() const override; void SetValue(ValueSource && s) override; @@ -242,11 +242,11 @@ namespace Slicer { class DLL_PUBLIC ModelPartForSequenceBase : public ModelPart { public: - bool HasValue() const override; - ModelPartType GetType() const override; + [[nodiscard]] bool HasValue() const override; + [[nodiscard]] ModelPartType GetType() const override; bool OnChild(const SubPartHandler &, std::string_view, const HookFilter &, MatchCase matchCase = MatchCase::Yes) override; - virtual const std::string & GetElementName() const = 0; + [[nodiscard]] virtual const std::string & GetElementName() const = 0; static const ModelPartType type; }; @@ -261,9 +261,9 @@ namespace Slicer { bool OnAnonChild(const SubPartHandler &, const HookFilter &) override; - const std::string & GetElementName() const override; + [[nodiscard]] const std::string & GetElementName() const override; - const Metadata & GetMetadata() const override; + [[nodiscard]] const Metadata & GetMetadata() const override; void OnContained(const ModelPartHandler &) override; @@ -286,8 +286,8 @@ namespace Slicer { class DLL_PUBLIC ModelPartForDictionaryBase : public ModelPart { public: - bool HasValue() const override; - ModelPartType GetType() const override; + [[nodiscard]] bool HasValue() const override; + [[nodiscard]] ModelPartType GetType() const override; static const ModelPartType type; }; @@ -304,7 +304,7 @@ namespace Slicer { bool OnChild(const SubPartHandler &, std::string_view name, const HookFilter &, MatchCase matchCase = MatchCase::Yes) override; - const Metadata & GetMetadata() const override; + [[nodiscard]] const Metadata & GetMetadata() const override; void OnContained(const ModelPartHandler &) override; @@ -326,8 +326,8 @@ namespace Slicer { class DLL_PUBLIC ModelPartForStreamBase : public ModelPart { public: - ModelPartType GetType() const override; - bool HasValue() const override; + [[nodiscard]] ModelPartType GetType() const override; + [[nodiscard]] bool HasValue() const override; void OnContained(const ModelPartHandler &) override = 0; void OnEachChild(const ChildHandler & ch) override = 0; @@ -347,15 +347,15 @@ namespace Slicer { void Write(Ice::OutputStream &) const override; void Read(Ice::InputStream &) override; - bool HasValue() const override; + [[nodiscard]] bool HasValue() const override; void OnEachChild(const ChildHandler & ch) override; - const std::string & GetRootName() const override = 0; + [[nodiscard]] const std::string & GetRootName() const override = 0; }; template<typename T> class ModelPartForStreamRoot : public ModelPartForStreamRootBase { public: using ModelPartForStreamRootBase::ModelPartForStreamRootBase; - const std::string & GetRootName() const override; + [[nodiscard]] const std::string & GetRootName() const override; }; } diff --git a/slicer/slicer/slicer.h b/slicer/slicer/slicer.h index f669024..a4b43f3 100644 --- a/slicer/slicer/slicer.h +++ b/slicer/slicer/slicer.h @@ -6,7 +6,7 @@ namespace Slicer { template<typename Object> - Object + [[nodiscard]] Object DeserializeAnyWith(any_ptr<Deserializer> deserializer) { Object object {}; @@ -17,7 +17,7 @@ namespace Slicer { } template<typename Deserializer, typename Object, typename... SerializerParams> - Object + [[nodiscard]] Object DeserializeAny(SerializerParams &&... sp) { return DeserializeAnyWith<Object>(Deserializer(std::forward<SerializerParams>(sp)...)); diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp index f02dbaf..25feade 100644 --- a/slicer/test/serializers.cpp +++ b/slicer/test/serializers.cpp @@ -590,12 +590,12 @@ BOOST_AUTO_TEST_CASE(xml_streams) BOOST_AUTO_TEST_CASE(invalid_enum) { Slicer::JsonFileDeserializer jdeserializer {rootDir / "initial" / "invalidEnum.json"}; - BOOST_REQUIRE_THROW( - Slicer::DeserializeAnyWith<TestModule::SomeNumbers>(jdeserializer), Slicer::InvalidEnumerationSymbol); + BOOST_REQUIRE_THROW(std::ignore = Slicer::DeserializeAnyWith<TestModule::SomeNumbers>(jdeserializer), + Slicer::InvalidEnumerationSymbol); Slicer::XmlFileDeserializer xdeserializer {rootDir / "initial" / "invalidEnum.xml"}; - BOOST_REQUIRE_THROW( - Slicer::DeserializeAnyWith<TestModule::SomeNumbers>(xdeserializer), Slicer::InvalidEnumerationSymbol); + BOOST_REQUIRE_THROW(std::ignore = Slicer::DeserializeAnyWith<TestModule::SomeNumbers>(xdeserializer), + Slicer::InvalidEnumerationSymbol); } BOOST_AUTO_TEST_SUITE_END() @@ -603,7 +603,8 @@ BOOST_AUTO_TEST_SUITE_END() BOOST_AUTO_TEST_CASE(missingConversion) { auto in = json::parseValue(R"J({"conv": "2016-06-30 12:34:56"})J"); - BOOST_REQUIRE_THROW((Slicer::DeserializeAny<Slicer::JsonValueDeserializer, TestModule2::MissingConvPtr>(in)), + BOOST_REQUIRE_THROW( + (std::ignore = Slicer::DeserializeAny<Slicer::JsonValueDeserializer, TestModule2::MissingConvPtr>(in)), Slicer::NoConversionFound); auto obj = std::make_shared<TestModule2::MissingConv>("2016-06-30 12:34:56"); @@ -631,7 +632,7 @@ BOOST_AUTO_TEST_CASE(DeserializeJsonAbstractEmpty) BOOST_AUTO_TEST_CASE(DeserializeJsonAbstractDefault) { auto in = json::parseValue(R"J({ "obj": {} })J"); - BOOST_CHECK_THROW((Slicer::DeserializeAny<Slicer::JsonValueDeserializer, Functions::SFuncs>(in)), + BOOST_CHECK_THROW((std::ignore = Slicer::DeserializeAny<Slicer::JsonValueDeserializer, Functions::SFuncs>(in)), Slicer::AbstractClassException); } @@ -655,7 +656,7 @@ BOOST_AUTO_TEST_CASE(DeserializeXmlAbstractEmpty) BOOST_AUTO_TEST_CASE(DeserializeXmlAbstractDefault) { std::stringstream in("<SFuncs><obj/></SFuncs>"); - BOOST_CHECK_THROW((Slicer::DeserializeAny<Slicer::XmlStreamDeserializer, Functions::SFuncs>(in)), + BOOST_CHECK_THROW((std::ignore = Slicer::DeserializeAny<Slicer::XmlStreamDeserializer, Functions::SFuncs>(in)), Slicer::AbstractClassException); } @@ -692,7 +693,7 @@ BOOST_AUTO_TEST_CASE(DeserializeXmlIncorrectSeqElementName) <Classes> <obj/> </Classes>)X"); - BOOST_CHECK_THROW((Slicer::DeserializeAny<Slicer::XmlStreamDeserializer, TestModule::BuiltInSeq>(in)), + BOOST_CHECK_THROW((std::ignore = Slicer::DeserializeAny<Slicer::XmlStreamDeserializer, TestModule::BuiltInSeq>(in)), Slicer::IncorrectElementName); } diff --git a/slicer/tool/slicer.cpp b/slicer/tool/slicer.cpp index a4439cb..6cd3c19 100644 --- a/slicer/tool/slicer.cpp +++ b/slicer/tool/slicer.cpp @@ -23,27 +23,29 @@ namespace po = boost::program_options; using namespace AdHoc::literals; -static std::string -defaultPostProcessor() -{ - constexpr std::array<const std::pair<std::string_view, std::string_view>, 1> pps {{ - {"clang-format", "-i"}, - }}; - const auto path {[]() -> std::string_view { - if (auto p = getenv("PATH")) { - return p; - } - return ""; - }()}; - const auto pathBegin = make_split_iterator(path, first_finder(":", boost::is_equal())); - for (const auto & [cmd, opts] : pps) { - for (auto p = pathBegin; p != decltype(pathBegin) {}; ++p) { - if (std::filesystem::exists(std::filesystem::path(p->begin(), p->end()) / cmd)) { - return "%? %?"_fmt(cmd, opts); +namespace { + [[nodiscard]] std::string + defaultPostProcessor() + { + constexpr std::array<const std::pair<std::string_view, std::string_view>, 1> pps {{ + {"clang-format", "-i"}, + }}; + const auto path {[]() -> std::string_view { + if (auto p = getenv("PATH")) { + return p; + } + return ""; + }()}; + const auto pathBegin = make_split_iterator(path, first_finder(":", boost::is_equal())); + for (const auto & [cmd, opts] : pps) { + for (auto p = pathBegin; p != decltype(pathBegin) {}; ++p) { + if (std::filesystem::exists(std::filesystem::path(p->begin(), p->end()) / cmd)) { + return "%? %?"_fmt(cmd, opts); + } } } + return ""; } - return ""; } int diff --git a/slicer/xml/testSpecifics.cpp b/slicer/xml/testSpecifics.cpp index 26a8ee9..036c03d 100644 --- a/slicer/xml/testSpecifics.cpp +++ b/slicer/xml/testSpecifics.cpp @@ -44,8 +44,8 @@ BOOST_DATA_TEST_CASE(bad_boolean_values, in) { parse_memory(in); - BOOST_CHECK_THROW( - (Slicer::DeserializeAny<Slicer::XmlDocumentDeserializer, bool>(get_document())), Slicer::BadBooleanValue); + BOOST_CHECK_THROW((std::ignore = Slicer::DeserializeAny<Slicer::XmlDocumentDeserializer, bool>(get_document())), + Slicer::BadBooleanValue); } BOOST_DATA_TEST_CASE(good_integer_values, @@ -70,7 +70,7 @@ BOOST_DATA_TEST_CASE(bad_integer_values, in) { parse_memory(in); - BOOST_CHECK_THROW((Slicer::DeserializeAny<Slicer::XmlDocumentDeserializer, Ice::Int>(get_document())), + BOOST_CHECK_THROW((std::ignore = Slicer::DeserializeAny<Slicer::XmlDocumentDeserializer, Ice::Int>(get_document())), Slicer::BadNumericValue); } |