diff options
-rw-r--r-- | Jamroot.jam | 26 | ||||
-rw-r--r-- | slicer/db/Jamfile.jam | 1 | ||||
-rw-r--r-- | slicer/db/sqlInsertSerializer.h | 2 | ||||
-rw-r--r-- | slicer/db/sqlSelectDeserializer.h | 2 | ||||
-rw-r--r-- | slicer/db/sqlTablePatchSerializer.h | 2 | ||||
-rw-r--r-- | slicer/db/sqlUpdateSerializer.h | 2 | ||||
-rw-r--r-- | slicer/ice/Jamfile.jam | 1 | ||||
-rw-r--r-- | slicer/ice/serializer.h | 8 | ||||
-rw-r--r-- | slicer/json/Jamfile.jam | 1 | ||||
-rw-r--r-- | slicer/json/serializer.cpp | 52 | ||||
-rw-r--r-- | slicer/json/serializer.h | 12 | ||||
-rw-r--r-- | slicer/slicer/modelParts.h | 9 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.cpp | 7 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.h | 166 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 76 | ||||
-rw-r--r-- | slicer/slicer/serializer.h | 13 | ||||
-rw-r--r-- | slicer/test/Jamfile.jam | 1 | ||||
-rw-r--r-- | slicer/test/compilation.cpp | 6 | ||||
-rw-r--r-- | slicer/test/conversions.h | 4 | ||||
-rw-r--r-- | slicer/test/serializers.cpp | 8 | ||||
-rw-r--r-- | slicer/tool/parser.cpp | 26 | ||||
-rw-r--r-- | slicer/tool/parser.h | 41 | ||||
-rw-r--r-- | slicer/xml/Jamfile.jam | 1 | ||||
-rw-r--r-- | slicer/xml/serializer.cpp | 30 | ||||
-rw-r--r-- | slicer/xml/serializer.h | 12 |
25 files changed, 307 insertions, 202 deletions
diff --git a/Jamroot.jam b/Jamroot.jam index c332369..98e8e4c 100644 --- a/Jamroot.jam +++ b/Jamroot.jam @@ -1,5 +1,6 @@ import os ; import slice ; +import testing ; using gcc : : [ os.environ CXX ] ; using pkg-config ; @@ -12,22 +13,37 @@ project <define>ICE_CPP11_MAPPING <cxxstd>17 <visibility>hidden - <linkflags>"-Wl,-z,defs,--warn-once,--gc-sections" + <linkflags>"-Wl,-z,defs,--warn-once,--gc-sections" <variant>release:<cxxflags>"-flto" <toolset>gcc:<variant>release:<cxxflags>"-flto=2" <variant>release:<linkflags>"-flto" <toolset>gcc:<variant>release:<linkflags>"-flto=2" - <variant>debug:<warnings>extra - <variant>debug:<warnings-as-errors>on - <variant>coverage:<coverage>on + <variant>debug:<warnings>extra + <variant>debug:<warnings-as-errors>on + <variant>coverage:<coverage>on <toolset>tidy:<checkxx>boost-* <toolset>tidy:<checkxx>bugprone-* <toolset>tidy:<checkxx>clang-* <toolset>tidy:<checkxx>misc-* <toolset>tidy:<checkxx>modernize-* + <toolset>tidy:<xcheckxx>modernize-use-trailing-return-type <toolset>tidy:<checkxx>hicpp-* <toolset>tidy:<checkxx>performance-* - ; + <toolset>tidy:<exclude>test/bin/tidy/debug/classes.h + <toolset>tidy:<exclude>test/bin/tidy/debug/classtype.h + <toolset>tidy:<exclude>test/bin/tidy/debug/collections.h + <toolset>tidy:<exclude>test/bin/tidy/debug/enums.h + <toolset>tidy:<exclude>test/bin/tidy/debug/inheritance.h + <toolset>tidy:<exclude>test/bin/tidy/debug/interfaces.h + <toolset>tidy:<exclude>test/bin/tidy/debug/json.h + <toolset>tidy:<exclude>test/bin/tidy/debug/locals.h + <toolset>tidy:<exclude>test/bin/tidy/debug/optionals.h + <toolset>tidy:<exclude>test/bin/tidy/debug/structs.h + <toolset>tidy:<exclude>test/bin/tidy/debug/types.h + <toolset>tidy:<exclude>test/bin/tidy/debug/xml.h + <toolset>tidy:<exclude>slicer/bin/common.h + <toolset>tidy:<exclude>xml/bin/tidy/debug/cxxstd-17-iso/xmlExceptions.h + ; build-project slicer ; diff --git a/slicer/db/Jamfile.jam b/slicer/db/Jamfile.jam index 2ea3f05..fcfa4d3 100644 --- a/slicer/db/Jamfile.jam +++ b/slicer/db/Jamfile.jam @@ -1,4 +1,3 @@ -import testing ; import package ; import ../test/slicer.jam ; diff --git a/slicer/db/sqlInsertSerializer.h b/slicer/db/sqlInsertSerializer.h index 3534b87..175706f 100644 --- a/slicer/db/sqlInsertSerializer.h +++ b/slicer/db/sqlInsertSerializer.h @@ -11,7 +11,7 @@ namespace Slicer { public: SqlInsertSerializer(DB::Connection * const, std::string tableName); - virtual void Serialize(Slicer::ModelPartForRootPtr) override; + void Serialize(Slicer::ModelPartForRootPtr) override; protected: void SerializeObject(const Slicer::ModelPartPtr &) const; diff --git a/slicer/db/sqlSelectDeserializer.h b/slicer/db/sqlSelectDeserializer.h index 736bb11..e9afd1d 100644 --- a/slicer/db/sqlSelectDeserializer.h +++ b/slicer/db/sqlSelectDeserializer.h @@ -10,7 +10,7 @@ namespace Slicer { public: SqlSelectDeserializer(DB::SelectCommand *, Ice::optional<std::string> typeIdCol = Ice::optional<std::string>()); - virtual void Deserialize(Slicer::ModelPartForRootPtr) override; + void Deserialize(Slicer::ModelPartForRootPtr) override; protected: void DLL_PRIVATE DeserializeSimple(const Slicer::ModelPartPtr &); diff --git a/slicer/db/sqlTablePatchSerializer.h b/slicer/db/sqlTablePatchSerializer.h index 425ce95..00ea328 100644 --- a/slicer/db/sqlTablePatchSerializer.h +++ b/slicer/db/sqlTablePatchSerializer.h @@ -9,7 +9,7 @@ namespace Slicer { public: SqlTablePatchSerializer(DB::Connection * const, DB::TablePatch &); - virtual void Serialize(Slicer::ModelPartForRootPtr) override; + void Serialize(Slicer::ModelPartForRootPtr) override; private: void createTemporaryTable(); diff --git a/slicer/db/sqlUpdateSerializer.h b/slicer/db/sqlUpdateSerializer.h index 7c451b2..a3462f8 100644 --- a/slicer/db/sqlUpdateSerializer.h +++ b/slicer/db/sqlUpdateSerializer.h @@ -10,7 +10,7 @@ namespace Slicer { public: SqlUpdateSerializer(DB::Connection * const, std::string tableName); - virtual void Serialize(Slicer::ModelPartForRootPtr) override; + void Serialize(Slicer::ModelPartForRootPtr) override; protected: void SerializeObject(const Slicer::ModelPartPtr &) const; diff --git a/slicer/ice/Jamfile.jam b/slicer/ice/Jamfile.jam index 3b9f2b2..fa8aefd 100644 --- a/slicer/ice/Jamfile.jam +++ b/slicer/ice/Jamfile.jam @@ -1,4 +1,3 @@ -import testing ; import package ; lib stdc++fs ; diff --git a/slicer/ice/serializer.h b/slicer/ice/serializer.h index d534b3e..c1768c0 100644 --- a/slicer/ice/serializer.h +++ b/slicer/ice/serializer.h @@ -21,7 +21,7 @@ namespace Slicer { public: IceBlobSerializer(Ice::ByteSeq &); - virtual void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootPtr) override; private: Ice::ByteSeq & blob; @@ -31,7 +31,7 @@ namespace Slicer { public: IceStreamSerializer(std::ostream &); - virtual void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootPtr) override; protected: std::ostream & strm; @@ -42,7 +42,7 @@ namespace Slicer { public: IceBlobDeserializer(const Ice::ByteSeq &); - virtual void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootPtr) override; protected: const Ice::ByteSeq & blob; @@ -52,7 +52,7 @@ namespace Slicer { public: IceStreamDeserializer(std::istream &); - virtual void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootPtr) override; protected: std::istream & strm; diff --git a/slicer/json/Jamfile.jam b/slicer/json/Jamfile.jam index 7d7a8ed..7b52b04 100644 --- a/slicer/json/Jamfile.jam +++ b/slicer/json/Jamfile.jam @@ -1,4 +1,3 @@ -import testing ; import package ; lib jsonpp : : : : diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp index d56a98e..b9b0c69 100644 --- a/slicer/json/serializer.cpp +++ b/slicer/json/serializer.cpp @@ -248,21 +248,37 @@ namespace Slicer { mp = mp->GetSubclassModelPart(*typeId); } } - mp->OnEachChild(std::bind(&JsonSerializer::ModelTreeIterate, &std::get<json::Object>(*n).insert({name, nn}).first->second, _1, _2)); + mp->OnEachChild( + [capture0 = &std::get<json::Object>(*n).insert({name, nn}).first->second] + (auto && PH1, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterate(capture0, PH1, PH2); + }); } break; case mpt_Sequence: if (mp->HasValue()) { - mp->OnEachChild(std::bind(&JsonSerializer::ModelTreeIterateSeq, &std::get<json::Object>(*n).insert({name, json::Array()}).first->second, _2)); + mp->OnEachChild( + [capture0 = &std::get<json::Object>(*n).insert({name, json::Array()}).first->second] + (auto &&, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterateSeq(capture0, PH2); + }); } break; case mpt_Dictionary: if (mp->HasValue()) { if (metaDataFlagSet(mp->GetMetadata(), md_object)) { - mp->OnEachChild(std::bind(&JsonSerializer::ModelTreeIterateDictObj, &std::get<json::Object>(*n).insert({name, json::Object()}).first->second, _2)); + mp->OnEachChild( + [capture0 = &std::get<json::Object>(*n).insert({name, json::Object()}).first->second] + (auto &&, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterateDictObj(capture0, PH2); + }); } else { - mp->OnEachChild(std::bind(&JsonSerializer::ModelTreeIterateSeq, &std::get<json::Object>(*n).insert({name, json::Array()}).first->second, _2)); + mp->OnEachChild( + [capture0 = &std::get<json::Object>(*n).insert({name, json::Array()}).first->second] + (auto &&, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterateSeq(capture0, PH2); + }); } } break; @@ -288,20 +304,28 @@ namespace Slicer { mp = mp->GetSubclassModelPart(*typeId); } } - mp->OnEachChild(std::bind(&JsonSerializer::ModelTreeIterate, n, _1, _2)); + mp->OnEachChild([n](auto && PH1, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterate(n, PH1, PH2); + }); break; case mpt_Sequence: *n = json::Array(); - mp->OnEachChild(std::bind(&JsonSerializer::ModelTreeIterateSeq, n, _2)); + mp->OnEachChild([n](auto &&, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterateSeq(n, PH2); + }); break; case mpt_Dictionary: if (metaDataFlagSet(mp->GetMetadata(), md_object)) { *n = json::Object(); - mp->OnEachChild(std::bind(&JsonSerializer::ModelTreeIterateDictObj, n, _2)); + mp->OnEachChild([n](auto &&, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterateDictObj(n, PH2); + }); } else { *n = json::Array(); - mp->OnEachChild(std::bind(&JsonSerializer::ModelTreeIterate, n, _1, _2)); + mp->OnEachChild([n](auto && PH1, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterate(n, PH1, PH2); + }); } break; } @@ -330,7 +354,9 @@ namespace Slicer { JsonStreamSerializer::Serialize(ModelPartForRootPtr modelRoot) { json::Value doc; - modelRoot->OnEachChild(std::bind(&JsonSerializer::ModelTreeIterateRoot, &doc, _2)); + modelRoot->OnEachChild([&doc](auto &&, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterateRoot(&doc, PH2); + }); json::serializeValue(doc, strm, "utf-8"); } @@ -357,7 +383,9 @@ namespace Slicer { JsonFileSerializer::Serialize(ModelPartForRootPtr modelRoot) { json::Value doc; - modelRoot->OnEachChild(std::bind(&JsonSerializer::ModelTreeIterateRoot, &doc, _2)); + modelRoot->OnEachChild([&doc](auto &&, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterateRoot(&doc, PH2); + }); std::ofstream outFile(path); json::serializeValue(doc, outFile, "utf-8"); } @@ -382,7 +410,9 @@ namespace Slicer { void JsonValueSerializer::Serialize(ModelPartForRootPtr modelRoot) { - modelRoot->OnEachChild(std::bind(&JsonSerializer::ModelTreeIterateRoot, &value, _2)); + modelRoot->OnEachChild([this](auto &&, auto && PH2, auto &&) { + return JsonSerializer::ModelTreeIterateRoot(&value, PH2); + }); } } diff --git a/slicer/json/serializer.h b/slicer/json/serializer.h index 64679ed..ed666aa 100644 --- a/slicer/json/serializer.h +++ b/slicer/json/serializer.h @@ -18,7 +18,7 @@ namespace Slicer { public: JsonStreamSerializer(std::ostream &); - virtual void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootPtr) override; protected: std::ostream & strm; @@ -28,7 +28,7 @@ namespace Slicer { public: JsonFileSerializer(std::filesystem::path); - virtual void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootPtr) override; protected: const std::filesystem::path path; @@ -38,7 +38,7 @@ namespace Slicer { public: JsonValueSerializer(json::Value &); - virtual void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootPtr) override; protected: json::Value & value; @@ -48,7 +48,7 @@ namespace Slicer { public: JsonStreamDeserializer(std::istream &); - virtual void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootPtr) override; protected: std::istream & strm; @@ -58,7 +58,7 @@ namespace Slicer { public: JsonFileDeserializer(std::filesystem::path); - virtual void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootPtr) override; protected: const std::filesystem::path path; @@ -68,7 +68,7 @@ namespace Slicer { public: JsonValueDeserializer(const json::Value &); - virtual void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootPtr) override; protected: const json::Value & value; diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index 3ec4201..f31a8c0 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -95,8 +95,8 @@ namespace Slicer { explicit ChildRef(ModelPartPtr); explicit ChildRef(ModelPartPtr, const Metadata &); - ModelPartPtr Child() const; - const Metadata & ChildMetaData() const; + [[nodiscard]] ModelPartPtr Child() const; + [[nodiscard]] const Metadata & ChildMetaData() const; explicit operator bool() const; private: @@ -111,8 +111,9 @@ namespace Slicer { bool filter(const HookFilter & flt); void apply(const ChildHandler & ch, const ModelPartPtr & modelPart); - virtual const Metadata & GetMetadata() const = 0; + [[nodiscard]] virtual const Metadata & GetMetadata() const = 0; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) const std::string name; }; @@ -167,6 +168,7 @@ namespace Slicer { protected: explicit ModelPartModel() : Model(nullptr) { } explicit ModelPartModel(T * m) : Model(m) { } + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) T * Model; }; @@ -184,6 +186,7 @@ namespace Slicer { virtual void Read(::Ice::InputStream &) = 0; ModelPartPtr GetContainedModelPart() override; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) ModelPartPtr mp; }; } diff --git a/slicer/slicer/modelPartsTypes.cpp b/slicer/slicer/modelPartsTypes.cpp index faad404..7d9ea54 100644 --- a/slicer/slicer/modelPartsTypes.cpp +++ b/slicer/slicer/modelPartsTypes.cpp @@ -5,11 +5,12 @@ namespace Slicer { using ClassRefMap = std::map<std::string, ClassRef, std::less<>>; + using ClassNamePair = std::pair<std::string, std::string>; using ClassNameMap = boost::multi_index_container< - std::pair<std::string, std::string>, + ClassNamePair, boost::multi_index::indexed_by< - boost::multi_index::ordered_unique<boost::multi_index::member<std::pair<std::string, std::string>, const std::string, &std::pair<std::string, std::string>::first>, std::less<>>, - boost::multi_index::ordered_unique<boost::multi_index::member<std::pair<std::string, std::string>, const std::string, &std::pair<std::string, std::string>::second>, std::less<>> + boost::multi_index::ordered_unique<boost::multi_index::member<ClassNamePair, const std::string, &ClassNamePair::first>, std::less<>>, + boost::multi_index::ordered_unique<boost::multi_index::member<ClassNamePair, const std::string, &ClassNamePair::second>, std::less<>> >>; static void createClassMaps() __attribute__((constructor(208))); diff --git a/slicer/slicer/modelPartsTypes.h b/slicer/slicer/modelPartsTypes.h index 3c69f76..99ccb81 100644 --- a/slicer/slicer/modelPartsTypes.h +++ b/slicer/slicer/modelPartsTypes.h @@ -17,7 +17,7 @@ namespace Slicer { ModelPartForRoot(T * o); const std::string & GetRootName() const override; - virtual bool HasValue() const override; + bool HasValue() const override; void Write(::Ice::OutputStream &) const override; void Read(::Ice::InputStream &) override; @@ -29,32 +29,32 @@ namespace Slicer { class DLL_PUBLIC ModelPartForSimpleBase : public ModelPart { public: - virtual void OnEachChild(const ChildHandler &) override; - virtual ChildRef GetAnonChildRef(const HookFilter &) override; - virtual ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; - virtual bool HasValue() const override; - virtual ModelPartType GetType() const override; + void OnEachChild(const ChildHandler &) override; + ChildRef GetAnonChildRef(const HookFilter &) override; + ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; + bool HasValue() const override; + ModelPartType GetType() const override; static const ModelPartType type; }; template<typename T> class DLL_PUBLIC ModelPartForSimple : public ModelPartForSimpleBase, protected ModelPartModel<T> { public: - typedef T element_type; + using element_type = T; ModelPartForSimple(T * h); - virtual void SetValue(ValueSource && s) override; - virtual bool GetValue(ValueTarget && s) override; + void SetValue(ValueSource && s) override; + bool GetValue(ValueTarget && s) override; }; class DLL_PUBLIC ModelPartForConvertedBase : public ModelPart { public: - virtual void OnEachChild(const ChildHandler &) override; - virtual ChildRef GetAnonChildRef(const HookFilter &) override; - virtual ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; - virtual bool HasValue() const override; - virtual ModelPartType GetType() const override; + void OnEachChild(const ChildHandler &) override; + ChildRef GetAnonChildRef(const HookFilter &) override; + ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; + bool HasValue() const override; + ModelPartType GetType() const override; static const ModelPartType type; protected: @@ -71,39 +71,40 @@ namespace Slicer { template<typename T, typename M, T M::* MV> class DLL_PUBLIC ModelPartForConverted : public ModelPartForConvertedBase, protected ModelPartModel<T> { public: - typedef T element_type; + using element_type = T; ModelPartForConverted(T * h); - virtual void SetValue(ValueSource && s) override; - virtual bool GetValue(ValueTarget && s) override; + void SetValue(ValueSource && s) override; + bool GetValue(ValueTarget && s) override; }; template<typename T, typename M, Ice::optional<T> M::* MV> class DLL_PUBLIC ModelPartForConverted<Ice::optional<T>, M, MV> : public ModelPartForConvertedBase, protected ModelPartModel<Ice::optional<T>> { public: - typedef Ice::optional<T> element_type; + using element_type = Ice::optional<T>; ModelPartForConverted(Ice::optional<T> * h); - virtual void SetValue(ValueSource && s) override; - virtual bool GetValue(ValueTarget && s) override; - virtual bool HasValue() const override; + void SetValue(ValueSource && s) override; + bool GetValue(ValueTarget && s) override; + bool HasValue() const override; }; class DLL_PUBLIC ModelPartForOptionalBase : public ModelPart { public: - virtual void OnEachChild(const ChildHandler & ch) override; - virtual void Complete() override; - virtual ChildRef GetAnonChildRef(const HookFilter & flt) override; - virtual ChildRef GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase = true) override; - virtual void SetValue(ValueSource && s) override; - virtual bool HasValue() const override; - virtual bool IsOptional() const override; - virtual const Metadata & GetMetadata() const override; + 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; + void SetValue(ValueSource && s) override; + bool HasValue() const override; + bool IsOptional() const override; + const Metadata & GetMetadata() const override; protected: virtual bool hasModel() const = 0; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) ModelPartPtr modelPart; }; @@ -111,17 +112,17 @@ namespace Slicer { class DLL_PUBLIC ModelPartForOptional : public ModelPartForOptionalBase, protected ModelPartModel<Ice::optional<typename T::element_type> > { public: ModelPartForOptional(Ice::optional< typename T::element_type > * h); - virtual void Create() override; - virtual bool GetValue(ValueTarget && s) override; - virtual ModelPartType GetType() const override; + void Create() override; + bool GetValue(ValueTarget && s) override; + ModelPartType GetType() const override; protected: - virtual bool hasModel() const override; + bool hasModel() const override; }; class DLL_PUBLIC ModelPartForComplexBase : public ModelPart { public: - virtual ModelPartType GetType() const override; + ModelPartType GetType() const override; static const ModelPartType type; protected: @@ -140,7 +141,7 @@ namespace Slicer { class DLL_PUBLIC ModelPartForComplex : public ModelPartForComplexBase { public: class DLL_PRIVATE HookBase; - typedef std::unique_ptr<HookBase> HookPtr; + using HookPtr = std::unique_ptr<HookBase>; template <typename MT, typename MP> class DLL_PRIVATE Hook; @@ -148,12 +149,12 @@ namespace Slicer { template <typename MT, typename MP> class DLL_PRIVATE HookMetadata; - virtual void OnEachChild(const ChildHandler & ch) override; + void OnEachChild(const ChildHandler & ch) override; - virtual ChildRef GetAnonChildRef(const HookFilter & flt) override; + ChildRef GetAnonChildRef(const HookFilter & flt) override; ChildRef GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase = true) override; - virtual const Metadata & GetMetadata() const override; + const Metadata & GetMetadata() const override; virtual T * GetModel() = 0; @@ -173,25 +174,25 @@ namespace Slicer { template<typename T> class DLL_PUBLIC ModelPartForClass : public ModelPartForComplex<T>, protected ModelPartModel<std::shared_ptr<T> > { public: - typedef std::shared_ptr<T> element_type; + using element_type = std::shared_ptr<T>; ModelPartForClass(element_type * h); - virtual void Create() override; + void Create() override; T * GetModel() override; - virtual ModelPartPtr GetSubclassModelPart(const std::string & name) override; + ModelPartPtr GetSubclassModelPart(const std::string & name) override; - virtual bool HasValue() const override; + [[nodiscard]] bool HasValue() const override; - virtual TypeId GetTypeId() const override; + [[nodiscard]] TypeId GetTypeId() const override; template<typename dummy = T> const std::string & getTypeId(typename std::enable_if<std::is_base_of<Ice::Object, dummy>::value>::type * = nullptr) const; template<typename dummy = T> std::string getTypeId(typename std::enable_if<!std::is_base_of<Ice::Object, dummy>::value>::type * = nullptr) const; - virtual Ice::optional<std::string> GetTypeIdProperty() const override; + [[nodiscard]] Ice::optional<std::string> GetTypeIdProperty() const override; static const std::string typeIdProperty; static const std::string * className; @@ -209,38 +210,38 @@ namespace Slicer { template<typename T> class DLL_PUBLIC ModelPartForStruct : public ModelPartForComplex<T>, protected ModelPartModel<T> { public: - typedef T element_type; + using element_type = T; ModelPartForStruct(T * o); T * GetModel() override; - virtual bool HasValue() const override; + [[nodiscard]] bool HasValue() const override; }; class DLL_PUBLIC ModelPartForEnumBase : public ModelPart { public: - virtual void OnEachChild(const ChildHandler &) override; + void OnEachChild(const ChildHandler &) override; ChildRef GetAnonChildRef(const HookFilter &) override; ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; - virtual bool HasValue() const override; - virtual ModelPartType GetType() const override; + bool HasValue() const override; + ModelPartType GetType() const override; static const ModelPartType type; }; template<typename T> class DLL_PUBLIC ModelPartForEnum : public ModelPartForEnumBase, protected ModelPartModel<T> { public: - typedef T element_type; + using element_type = T; class DLL_PRIVATE Enumerations; ModelPartForEnum(T * s); - virtual const Metadata & GetMetadata() const override; + const Metadata & GetMetadata() const override; - virtual void SetValue(ValueSource && s) override; + void SetValue(ValueSource && s) override; - virtual bool GetValue(ValueTarget && s) override; + bool GetValue(ValueTarget && s) override; static const Metadata metadata; static const Enumerations enumerations; @@ -250,27 +251,27 @@ namespace Slicer { class DLL_PUBLIC ModelPartForSequenceBase : public ModelPart { public: - virtual bool HasValue() const override; - virtual ModelPartType GetType() const override; + bool HasValue() const override; + ModelPartType GetType() const override; static const ModelPartType type; }; template<typename T> class DLL_PUBLIC ModelPartForSequence : public ModelPartForSequenceBase, protected ModelPartModel<T> { public: - typedef T element_type; + using element_type = T; ModelPartForSequence(T * s); - virtual void OnEachChild(const ChildHandler & ch) override; + void OnEachChild(const ChildHandler & ch) override; ChildRef GetAnonChildRef(const HookFilter &) override; ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; - virtual const Metadata & GetMetadata() const override; + const Metadata & GetMetadata() const override; - virtual ModelPartPtr GetContainedModelPart() override; + ModelPartPtr GetContainedModelPart() override; static const Metadata metadata; static const std::string elementName; @@ -284,8 +285,9 @@ namespace Slicer { public: ModelPartForDictionaryElementInserter(T * d); - virtual void Complete() override; + void Complete() override; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) typename T::value_type value; private: @@ -294,27 +296,27 @@ namespace Slicer { class DLL_PUBLIC ModelPartForDictionaryBase : public ModelPart { public: - virtual bool HasValue() const override; - virtual ModelPartType GetType() const override; + bool HasValue() const override; + ModelPartType GetType() const override; static const ModelPartType type; }; template<typename T> class DLL_PUBLIC ModelPartForDictionary : public ModelPartForDictionaryBase, protected ModelPartModel<T> { public: - typedef T element_type; + using element_type = T; ModelPartForDictionary(T * d); - virtual void OnEachChild(const ChildHandler & ch) override; + void OnEachChild(const ChildHandler & ch) override; ChildRef GetAnonChildRef(const HookFilter &) override; ChildRef GetChildRef(const std::string & name, const HookFilter &, bool matchCase = true) override; - virtual const Metadata & GetMetadata() const override; + const Metadata & GetMetadata() const override; - virtual ModelPartPtr GetContainedModelPart() override; + ModelPartPtr GetContainedModelPart() override; static const Metadata metadata; static const std::string pairName; @@ -323,21 +325,21 @@ namespace Slicer { template<typename T> class DLL_PUBLIC Stream { public: - typedef std::function<void(const T &)> Consumer; - typedef T element_type; + using Consumer = std::function<void(const T &)>; + using element_type = T; virtual void Produce(const Consumer & c) = 0; }; class DLL_PUBLIC ModelPartForStreamBase : public ModelPart { public: - virtual ModelPartType GetType() const override; - virtual bool HasValue() const override; - virtual ChildRef GetAnonChildRef(const HookFilter &) override; - virtual ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; + ModelPartType GetType() const override; + bool HasValue() const override; + ChildRef GetAnonChildRef(const HookFilter &) override; + ChildRef GetChildRef(const std::string &, const HookFilter &, bool matchCase = true) override; - virtual ModelPartPtr GetContainedModelPart() override = 0; - virtual void OnEachChild(const ChildHandler & ch) override = 0; + ModelPartPtr GetContainedModelPart() override = 0; + void OnEachChild(const ChildHandler & ch) override = 0; }; template<typename T> @@ -345,19 +347,19 @@ namespace Slicer { public: ModelPartForStream(Stream<T> * s); - virtual ModelPartPtr GetContainedModelPart() override; - virtual void OnEachChild(const ChildHandler & ch) override; + ModelPartPtr GetContainedModelPart() override; + void OnEachChild(const ChildHandler & ch) override; }; class DLL_PUBLIC ModelPartForStreamRootBase : public ModelPartForRootBase { public: ModelPartForStreamRootBase(const ModelPartPtr & mp); - virtual void Write(Ice::OutputStream&) const override; - virtual void Read(Ice::InputStream&) override; - virtual bool HasValue() const override; - virtual void OnEachChild(const ChildHandler & ch) override; - virtual const std::string & GetRootName() const override = 0; + void Write(Ice::OutputStream&) const override; + void Read(Ice::InputStream&) override; + bool HasValue() const override; + void OnEachChild(const ChildHandler & ch) override; + const std::string & GetRootName() const override = 0; }; template<typename T> @@ -365,7 +367,7 @@ namespace Slicer { public: ModelPartForStreamRoot(Stream<T> * s); - virtual const std::string & GetRootName() const override; + const std::string & GetRootName() const override; private: Stream<T> * stream; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index e75c849..872304b 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -12,6 +12,12 @@ #include <boost/multi_index/member.hpp> #include <boost/algorithm/string/case_conv.hpp> +#ifdef __clang__ +#define FINALVISMODELPARTS DLL_PUBLIC +#else +#define FINALVISMODELPARTS +#endif + #define CUSTOMMODELPARTFOR(Type, BaseModelPart, ModelPartType) \ template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor<Type>() { return std::make_shared<ModelPartType>(nullptr); } \ template<> DLL_PUBLIC ModelPartPtr ModelPart::CreateFor(Type & s) { return std::make_shared<ModelPartType>(&s); } \ @@ -22,7 +28,7 @@ template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(Ice::optional<Type> & s) { return std::make_shared<ModelPartForRoot<Ice::optional<Type>>>(&s); } \ template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(const Type & s) { return CreateRootFor(const_cast<Type &>(s)); } \ template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(const Ice::optional<Type> & s) { return CreateRootFor(const_cast<Ice::optional<Type> &>(s)); } \ - template class BaseModelPart; \ + template class FINALVISMODELPARTS BaseModelPart; \ template class ModelPartForRoot<Type>; \ template class ModelPartForRoot< Ice::optional<Type> >; \ @@ -65,8 +71,8 @@ namespace Slicer { typeWrite(::Ice::OutputStream & s, const ::Ice::optional<T> & m) { if constexpr (!isLocal<T>::value) { - typedef Ice::StreamableTraits<T> traits; - typedef Ice::StreamOptionalHelper<T, traits::helper, traits::fixedLength> SOH; + using traits = Ice::StreamableTraits<T>; + using SOH = Ice::StreamOptionalHelper<T, traits::helper, traits::fixedLength>; s.startEncapsulation(); if (m && s.writeOptional(0, SOH::optionalFormat)) { SOH::write(&s, *m); @@ -95,8 +101,8 @@ namespace Slicer { typeRead(::Ice::InputStream & s, ::Ice::optional<T> & m) { if constexpr (!isLocal<T>::value) { - typedef Ice::StreamableTraits<T> traits; - typedef Ice::StreamOptionalHelper<T, traits::helper, traits::fixedLength> SOH; + using traits = Ice::StreamableTraits<T>; + using SOH = Ice::StreamOptionalHelper<T, traits::helper, traits::fixedLength>; s.startEncapsulation(); if (s.readOptional(0, SOH::optionalFormat)) { m = T(); @@ -185,7 +191,7 @@ namespace Slicer { template <typename R, typename ... Args> struct function_traits; template <typename R, typename ... Args> struct function_traits<std::function<R(Args...)>> { template<int A> struct arg { - typedef typename std::tuple_element<A, std::tuple<Args...>>::type type; + using type = typename std::tuple_element<A, std::tuple<Args...>>::type; }; }; template <typename F> struct callable_traits : public function_traits<std::function<typename std::remove_pointer<F>::type>> { }; @@ -193,7 +199,7 @@ namespace Slicer { // Converters that remove "optionalness". template <typename X> struct Coerce { - typedef typename std::remove_const<typename std::remove_reference<X>::type>::type T; + using T = typename std::remove_const<typename std::remove_reference<X>::type>::type; T & operator()(T & x) const { return x; } const T & operator()(const T & x) const { return x; } @@ -206,7 +212,7 @@ namespace Slicer { }; template <typename X> struct Coerce<Ice::optional<X>> { - typedef typename std::remove_const<typename std::remove_reference<X>::type>::type T; + using T = typename std::remove_const<typename std::remove_reference<X>::type>::type; Ice::optional<T> & operator()(Ice::optional<T> & x) const { return x; } const Ice::optional<T> & operator()(const Ice::optional<T> & x) const { return x; } @@ -221,7 +227,7 @@ namespace Slicer { bool ModelPartForConvertedBase::tryConvertFrom(ValueSource & vsp, MT * model, const Conv & conv) { if (auto vspt = dynamic_cast<TValueSource<ET> *>(&vsp)) { - typedef typename callable_traits<Conv>::template arg<0>::type CA; + using CA = typename callable_traits<Conv>::template arg<0>::type; ET tmp; vspt->set(tmp); auto converted = conv(Coerce<CA>()(tmp)); @@ -251,8 +257,8 @@ namespace Slicer { TryConvertResult ModelPartForConvertedBase::tryConvertTo(ValueTarget & vsp, const MT * model, const Conv & conv) { if (auto vspt = dynamic_cast<TValueTarget<ET> *>(&vsp)) { - typedef typename callable_traits<Conv>::template arg<0>::type CA; - typedef typename std::remove_const<typename std::remove_reference<CA>::type>::type CAR; + using CA = typename callable_traits<Conv>::template arg<0>::type; + using CAR = typename std::remove_const<typename std::remove_reference<CA>::type>::type; if (Coerce<CAR>::valueExists(*model)) { auto converted = conv(Coerce<CA>()(*model)); if (Coerce<ET>::valueExists(converted)) { @@ -399,7 +405,7 @@ namespace Slicer { virtual ~HookBase() = default; virtual ModelPartPtr Get(T * t) const = 0; - virtual const Metadata & GetMetadata() const override + const Metadata & GetMetadata() const override { return emptyMetadata; } @@ -434,7 +440,7 @@ namespace Slicer { { } - virtual const Metadata & GetMetadata() const override + const Metadata & GetMetadata() const override { return metadata; } @@ -508,6 +514,8 @@ namespace Slicer { template<typename T> void ModelPartForClass<T>::unregisterClass() { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) + BOOST_ASSERT(className); ModelPartForComplexBase::unregisterClass(*className, typeName); deleteClassName(); } @@ -518,6 +526,8 @@ namespace Slicer { { // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) BOOST_ASSERT(this->Model); + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) + BOOST_ASSERT(className); return ModelPartForComplexBase::GetTypeId(getTypeId(), *className); } @@ -525,6 +535,8 @@ namespace Slicer { template<typename dummy> const std::string & ModelPartForClass<T>::getTypeId(typename std::enable_if<std::is_base_of<Ice::Object, dummy>::value>::type *) const { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) + BOOST_ASSERT(this->Model); return (*this->Model)->ice_id(); } @@ -532,6 +544,8 @@ namespace Slicer { template<typename dummy> std::string ModelPartForClass<T>::getTypeId(typename std::enable_if<!std::is_base_of<Ice::Object, dummy>::value>::type *) const { + // NOLINTNEXTLINE(hicpp-no-array-decay,-warnings-as-errors) + BOOST_ASSERT(this->Model); return ModelPartForComplexBase::demangle(typeid(*this->Model->get()).name()); } @@ -556,11 +570,14 @@ namespace Slicer { // ModelPartForEnum template<typename T> + using EnumPair = std::pair<T, std::string>; + + template<typename T> class ModelPartForEnum<T>::Enumerations : public boost::multi_index_container< - std::pair<T, std::string>, + EnumPair<T>, boost::multi_index::indexed_by< - boost::multi_index::ordered_unique<boost::multi_index::member<std::pair<T, std::string>, const T, &std::pair<T, std::string>::first>>, - boost::multi_index::ordered_unique<boost::multi_index::member<std::pair<T, std::string>, const std::string, &std::pair<T, std::string>::second>, std::less<>> + boost::multi_index::ordered_unique<boost::multi_index::member<EnumPair<T>, const T, &EnumPair<T>::first>>, + boost::multi_index::ordered_unique<boost::multi_index::member<EnumPair<T>, const std::string, &EnumPair<T>::second>, std::less<>> >> { }; @@ -576,26 +593,29 @@ namespace Slicer { return metadata; } + template<int Side, typename Ex, typename ExP, typename T, typename V, typename R> + inline const auto & ModelPartForEnumLookup(const typename ModelPartForEnum<T>::Enumerations & enumerations, + const V & val, R EnumPair<T>::* rv) + { + const auto & side = enumerations.template get<Side>(); + if (auto i = side.find(val); i != side.end()) { + return (*i).*rv; + } + throw Ex(ExP(val), typeid(T).name()); + } + template<typename T> T ModelPartForEnum<T>::lookup(const std::string_view & val) { - auto & right = enumerations.template get<1>(); - auto i = right.find(val); - if (i == right.end()) { - throw InvalidEnumerationSymbol(std::string(val), typeid(T).name()); - } - return i->first; + return ModelPartForEnumLookup<1, InvalidEnumerationSymbol, std::string, T>(enumerations, val, + &EnumPair<T>::first); } template<typename T> const std::string & ModelPartForEnum<T>::lookup(T val) { - auto & left = enumerations.template get<0>(); - auto i = left.find(val); - if (i == left.end()) { - throw InvalidEnumerationValue((::Ice::Int)val, typeid(T).name()); - } - return i->second; + return ModelPartForEnumLookup<0, InvalidEnumerationValue, ::Ice::Int, T>(enumerations, val, + &EnumPair<T>::second); } template<typename T> diff --git a/slicer/slicer/serializer.h b/slicer/slicer/serializer.h index 73d4617..90acc18 100644 --- a/slicer/slicer/serializer.h +++ b/slicer/slicer/serializer.h @@ -5,19 +5,16 @@ #include <slicer/modelParts.h> #include <visibility.h> #include <factory.h> +#include <c++11Helpers.h> namespace Slicer { class DLL_PUBLIC Serializer { public: Serializer() = default; - Serializer(const Serializer &) = delete; - Serializer(Serializer &&) = delete; + SPECIAL_MEMBERS_DEFAULT(Serializer); virtual ~Serializer() = default; - Serializer & operator=(const Serializer &) = delete; - Serializer & operator=(Serializer &&) = delete; - virtual void Serialize(ModelPartForRootPtr) = 0; }; using SerializerPtr = std::shared_ptr<Serializer>; @@ -25,14 +22,10 @@ namespace Slicer { class DLL_PUBLIC Deserializer { public: Deserializer() = default; - Deserializer(const Deserializer &) = delete; - Deserializer(Deserializer &&) = delete; + SPECIAL_MEMBERS_DEFAULT(Deserializer); virtual ~Deserializer() = default; - Deserializer & operator=(const Deserializer &) = delete; - Deserializer & operator=(Deserializer &&) = delete; - virtual void Deserialize(ModelPartForRootPtr) = 0; }; using DeserializerPtr = std::shared_ptr<Deserializer>; diff --git a/slicer/test/Jamfile.jam b/slicer/test/Jamfile.jam index 4c0acbd..d0eecdb 100644 --- a/slicer/test/Jamfile.jam +++ b/slicer/test/Jamfile.jam @@ -1,4 +1,3 @@ -import testing ; import ./slicer.jam ; lib dl ; diff --git a/slicer/test/compilation.cpp b/slicer/test/compilation.cpp index 445e867..0475bbe 100644 --- a/slicer/test/compilation.cpp +++ b/slicer/test/compilation.cpp @@ -10,8 +10,6 @@ BOOST_TEST_DONT_PRINT_LOG_VALUE(std::type_info); // LCOV_EXCL_STOP -namespace pl = std::placeholders; - #define TypeTest(Var, Expr, Explicit, Expected) \ Var obj = Expr; \ Slicer::ModelPartPtr mpp = Slicer::ModelPart::CreateFor(obj); \ @@ -54,7 +52,7 @@ BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_sequenceclasses ) BOOST_REQUIRE(cmpp); BOOST_REQUIRE_EQUAL(Slicer::mpt_Complex, cmpp->GetType()); std::vector<std::string> names; - cmpp->OnEachChild(std::bind(&hookHandler, &names, pl::_1, pl::_2, pl::_3)); + cmpp->OnEachChild(std::bind(&hookHandler, &names, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); BOOST_REQUIRE_EQUAL(2, names.size()); BOOST_REQUIRE_EQUAL("a", names.front()); BOOST_REQUIRE_EQUAL("b", names.back()); @@ -67,7 +65,7 @@ BOOST_AUTO_TEST_CASE( compile_auto_modelpart_type_sequencestructs ) BOOST_REQUIRE(cmpp); BOOST_REQUIRE_EQUAL(Slicer::mpt_Complex, cmpp->GetType()); std::vector<std::string> names; - cmpp->OnEachChild(std::bind(&hookHandler, &names, pl::_1, pl::_2, pl::_3)); + cmpp->OnEachChild(std::bind(&hookHandler, &names, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3)); BOOST_REQUIRE_EQUAL(2, names.size()); BOOST_REQUIRE_EQUAL("a", names.front()); BOOST_REQUIRE_EQUAL("b", names.back()); diff --git a/slicer/test/conversions.h b/slicer/test/conversions.h index 55f42f3..bf70407 100644 --- a/slicer/test/conversions.h +++ b/slicer/test/conversions.h @@ -11,14 +11,14 @@ namespace TestModule { class DLL_PUBLIC AbValidator : public Slicer::ModelPartForClass<ClassType> { public: - AbValidator(ClassTypePtr *); + explicit AbValidator(ClassTypePtr *); void Complete() override; }; class DLL_PUBLIC MonthValidator : public Slicer::ModelPartForSimple<::Ice::Short> { public: - MonthValidator(::Ice::Short *); + explicit MonthValidator(::Ice::Short *); void Complete() override; }; diff --git a/slicer/test/serializers.cpp b/slicer/test/serializers.cpp index bf50b22..0b483b0 100644 --- a/slicer/test/serializers.cpp +++ b/slicer/test/serializers.cpp @@ -20,7 +20,7 @@ #include "conversions.h" #ifdef SLICER_MODELPARTSTYPES_IMPL_H -#error Test code should have pull in implementation header +#error Client code should NOT need to pull in implementation header #endif namespace fs = std::filesystem; @@ -681,3 +681,9 @@ BOOST_AUTO_TEST_CASE(case_less_test) BOOST_AUTO_TEST_SUITE_END(); +BOOST_AUTO_TEST_CASE(enum_lookups) +{ + BOOST_CHECK_EQUAL("One", Slicer::ModelPartForEnum<TestModule::SomeNumbers>::lookup(TestModule::SomeNumbers::One)); + BOOST_CHECK_EQUAL(TestModule::SomeNumbers::One, Slicer::ModelPartForEnum<TestModule::SomeNumbers>::lookup("One")); +} + diff --git a/slicer/tool/parser.cpp b/slicer/tool/parser.cpp index 0edcc2f..294dd7a 100644 --- a/slicer/tool/parser.cpp +++ b/slicer/tool/parser.cpp @@ -98,9 +98,8 @@ namespace Slicer { if (!cpp) { return true; } fprintbf(cpp, "// Begin Slicer code\n\n"); - fprintbf(cpp, "#include <%s>\n\n", fs::path(topLevelFile.filename()).replace_extension(".h").string()); - fprintbf(cpp, "#include <%s>\n", (headerPrefix / "modelPartsTypes.impl.h").string()); - fprintbf(cpp, "#include <%s>\n", (headerPrefix / "common.h").string()); + fprintbf(cpp, "#include <%s>\n\n", (headerPrefix / "modelPartsTypes.impl.h").string()); + fprintbf(cpp, "#include <%s>\n", fs::path(topLevelFile.filename()).replace_extension(".h").string()); for (const auto & m : u->modules()) { for (const auto & i : metaDataValues("slicer:include:", m->getMetaData())) { fprintbf(cpp, "#include <%s>\n", i); @@ -155,6 +154,15 @@ namespace Slicer { type, name); } + void + Slicer::externType(const Slice::TypePtr & type) const + { + if (definedTypes.count(type->typeId())) return; + + fprintbf(cpp, "extern template class %s< %s >;\n", + getBasicModelPart(type), Slice::ClassDeclPtr::dynamicCast(type) ? type->typeId() : Slice::typeToString(type)); + } + bool Slicer::visitClassDefStart(const Slice::ClassDefPtr & c) { @@ -210,6 +218,7 @@ namespace Slicer { fprintbf(cpp, "CUSTOMMODELPARTFOR(%s, ModelPartForClass<%s>, ModelPartForClass<%s>);\n\n", Slice::typeToString(decl), c->scoped(), c->scoped()); } + definedTypes.insert(decl->typeId()); classNo += 1; @@ -246,6 +255,9 @@ namespace Slicer { { if (!cpp) { return; } + for (const auto & dm : dataMembers) { + externType(dm->type()); + } fprintbf(cpp, "using C%d = ModelPartForComplex< %s >;\n", components, it->scoped()); fprintbf(cpp, "template<> DLL_PUBLIC\n"); @@ -329,6 +341,7 @@ namespace Slicer { if (!cpp) { return; } fprintbf(cpp, "// Sequence %s\n", s->name()); + externType(s->type()); fprintbf(cpp, "template<> DLL_PUBLIC\n"); fprintbf(cpp, "ChildRef ModelPartForSequence< %s >::GetChildRef(const std::string & name, const HookFilter & flt, bool matchCase)\n{\n", s->scoped()); @@ -370,6 +383,8 @@ namespace Slicer { if (!cpp) { return; } fprintbf(cpp, "// Dictionary %s\n", d->name()); + externType(d->keyType()); + externType(d->valueType()); auto iname = metaDataValue("slicer:item:", d->getMetaData()); fprintbf(cpp, "template<> DLL_PUBLIC\n"); fprintbf(cpp, "const std::string ModelPartForDictionary< %s >::pairName(\"%s\");\n\n", @@ -545,13 +560,13 @@ namespace Slicer { for (auto & pi : {0, 1, 2}) { boost::algorithm::replace_all(split[pi], ".", "::"); } - rtn.push_back(split); + rtn.push_back(ConversionSpec(split)); } return rtn; } void - Slicer::defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata) const + Slicer::defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata) { fprintbf(cpp, "// NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)\n"); if (auto cmp = metaDataValue("slicer:custommodelpart:", metadata)) { @@ -562,6 +577,7 @@ namespace Slicer { fprintbf(cpp, "MODELPARTFOR(%s, %s);\n\n", type, getBasicModelPart(stype)); } + definedTypes.insert(stype->typeId()); } unsigned int diff --git a/slicer/tool/parser.h b/slicer/tool/parser.h index b9474d3..67aa243 100644 --- a/slicer/tool/parser.h +++ b/slicer/tool/parser.h @@ -11,60 +11,71 @@ namespace Slicer { typedef std::vector<std::string> Args; class ConversionSpec { public: - ConversionSpec(const Args &); + explicit ConversionSpec(const Args &); + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) std::string ExchangeType; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) std::string ConvertToModelFunc; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) std::string ConvertToExchangeFunc; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) Args Options; }; - typedef std::vector<ConversionSpec> Conversions; + using Conversions = std::vector<ConversionSpec>; Slicer(); + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) FILE * cpp; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) std::filesystem::path slicePath; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) std::filesystem::path cppPath; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) std::filesystem::path headerPrefix; + // NOLINTNEXTLINE(misc-non-private-member-variables-in-classes) std::vector<std::filesystem::path> includes; unsigned int Execute(); - unsigned int Components() const; + [[nodiscard]] unsigned int Components() const; #pragma GCC visibility push(hidden) - virtual bool visitUnitStart(const Slice::UnitPtr&) override; + bool visitUnitStart(const Slice::UnitPtr&) override; - virtual void visitUnitEnd(const Slice::UnitPtr&) override; + void visitUnitEnd(const Slice::UnitPtr&) override; - virtual bool visitModuleStart(const Slice::ModulePtr & m) override; + bool visitModuleStart(const Slice::ModulePtr & m) override; - virtual bool visitClassDefStart(const Slice::ClassDefPtr & c) override; + bool visitClassDefStart(const Slice::ClassDefPtr & c) override; - virtual bool visitStructStart(const Slice::StructPtr&) override; + bool visitStructStart(const Slice::StructPtr&) override; - virtual void visitEnum(const Slice::EnumPtr &) override; + void visitEnum(const Slice::EnumPtr &) override; - virtual void visitSequence(const Slice::SequencePtr & s) override; + void visitSequence(const Slice::SequencePtr & s) override; - virtual void visitDictionary(const Slice::DictionaryPtr & d) override; + void visitDictionary(const Slice::DictionaryPtr & d) override; - virtual void visitModuleEnd(const Slice::ModulePtr & m) override; + void visitModuleEnd(const Slice::ModulePtr & m) override; private: void createModelPartForConverted(const Slice::TypePtr & type, const std::string & container, const Slice::DataMemberPtr & dm) const; void createNewModelPartPtrFor(const Slice::TypePtr & type, const Slice::DataMemberPtr & dm = Slice::DataMemberPtr(), const Slice::StringList & md = Slice::StringList()) const; - std::string getBasicModelPart(const Slice::TypePtr & type) const; - void defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata) const; + [[nodiscard]] std::string getBasicModelPart(const Slice::TypePtr & type) const; + void defineMODELPART(const std::string & type, const Slice::TypePtr & stype, const Slice::StringList & metadata); void visitComplexDataMembers(const Slice::ConstructedPtr & t, const Slice::DataMemberList &) const; void defineConversions(const Slice::DataMemberPtr & dm) const; void defineRoot(const std::string & type, const std::string & name, const Slice::TypePtr & stype) const; + void externType(const Slice::TypePtr &) const; - bool hasMetadata(const std::list<std::string> & metadata) const; + [[nodiscard]] bool hasMetadata(const std::list<std::string> & metadata) const; void copyMetadata(const std::list<std::string> & metadata) const; static Slice::StringList getAllMetadata(const Slice::DataMemberPtr & dm); static Conversions getConversions(const Slice::StringList & metadata); + std::set<std::string> definedTypes; #pragma GCC visibility pop unsigned int components; diff --git a/slicer/xml/Jamfile.jam b/slicer/xml/Jamfile.jam index 363d68c..c237f93 100644 --- a/slicer/xml/Jamfile.jam +++ b/slicer/xml/Jamfile.jam @@ -1,4 +1,3 @@ -import testing ; import package ; lib stdc++fs ; diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp index 36605e6..f31acb0 100644 --- a/slicer/xml/serializer.cpp +++ b/slicer/xml/serializer.cpp @@ -163,7 +163,9 @@ namespace Slicer { class XmlAttributeValueTarget : public XmlValueTarget { public: explicit XmlAttributeValueTarget(xmlpp::Element * p, const std::string & n) : - XmlValueTarget(std::bind(&xmlpp::Element::set_attribute, p, Glib::ustring(n), _1, Glib::ustring())) + XmlValueTarget([p, n](auto && PH1) { + p->set_attribute(n, PH1); + }) { } }; @@ -171,7 +173,9 @@ namespace Slicer { class XmlContentValueTarget : public XmlValueTarget { public: explicit XmlContentValueTarget(xmlpp::Element * p) : - XmlValueTarget(std::bind(&xmlpp::Element::set_first_child_text, p, _1)) + XmlValueTarget([p](auto && PH1) { + p->set_first_child_text(PH1); + }) { } @@ -322,10 +326,12 @@ namespace Slicer { } else { if (hp && metaDataFlagSet(hp->GetMetadata(), md_bare)) { - ModelTreeProcessElement(n, mp, std::bind((ElementCreatorF)&xmlpp::Element::add_child_element, _1, name, Glib::ustring())); + ModelTreeProcessElement(n, mp, [name](auto && PH1, auto &&) { + return PH1->add_child_element(name); + }); } else { - CurrentElementCreator cec(std::bind(ec, n, name)); + CurrentElementCreator cec([ec, n, name] { return ec(n, name); }); ModelTreeProcessElement(cec, mp, defaultElementCreator); } } @@ -370,7 +376,9 @@ namespace Slicer { element->set_attribute(*typeIdPropName, *typeId); mp = mp->GetSubclassModelPart(*typeId); } - mp->OnEachChild(std::bind(&XmlSerializer::ModelTreeIterate, element, _1, _2, _3, ec)); + mp->OnEachChild([element, ec](auto && PH1, auto && PH2, auto && PH3) { + return XmlSerializer::ModelTreeIterate(element, PH1, PH2, PH3, ec); + }); } } @@ -403,7 +411,9 @@ namespace Slicer { XmlStreamSerializer::Serialize(ModelPartForRootPtr modelRoot) { xmlpp::Document doc; - modelRoot->OnEachChild(std::bind(&XmlSerializer::ModelTreeIterateRoot, &doc, _1, _2)); + modelRoot->OnEachChild([&doc](auto && PH1, auto && PH2, auto &&) { + return XmlSerializer::ModelTreeIterateRoot(&doc, PH1, PH2); + }); doc.write_to_stream(strm); } @@ -429,7 +439,9 @@ namespace Slicer { XmlFileSerializer::Serialize(ModelPartForRootPtr modelRoot) { xmlpp::Document doc; - modelRoot->OnEachChild(std::bind(&XmlSerializer::ModelTreeIterateRoot, &doc, _1, _2)); + modelRoot->OnEachChild([&doc](auto && PH1, auto && PH2, auto &&) { + return XmlSerializer::ModelTreeIterateRoot(&doc, PH1, PH2); + }); doc.write_to_file_formatted(path); } @@ -453,7 +465,9 @@ namespace Slicer { XmlDocumentSerializer::Serialize(ModelPartForRootPtr modelRoot) { doc = new xmlpp::Document(); - modelRoot->OnEachChild(std::bind(&XmlSerializer::ModelTreeIterateRoot, doc, _1, _2)); + modelRoot->OnEachChild([this](auto && PH1, auto && PH2, auto &&) { + return XmlSerializer::ModelTreeIterateRoot(doc, PH1, PH2); + }); } AdHocFormatter(BadBooleanValueMsg, "Bad boolean value [%?]"); diff --git a/slicer/xml/serializer.h b/slicer/xml/serializer.h index d2220ef..f41e5a7 100644 --- a/slicer/xml/serializer.h +++ b/slicer/xml/serializer.h @@ -26,7 +26,7 @@ namespace Slicer { public: XmlStreamSerializer(std::ostream &); - virtual void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootPtr) override; protected: std::ostream & strm; @@ -36,7 +36,7 @@ namespace Slicer { public: XmlFileSerializer(std::filesystem::path); - virtual void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootPtr) override; protected: const std::filesystem::path path; @@ -46,7 +46,7 @@ namespace Slicer { public: XmlDocumentSerializer(xmlpp::Document * &); - virtual void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootPtr) override; protected: xmlpp::Document * & doc; @@ -65,7 +65,7 @@ namespace Slicer { public: XmlStreamDeserializer(std::istream &); - virtual void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootPtr) override; protected: std::istream & strm; @@ -75,7 +75,7 @@ namespace Slicer { public: XmlFileDeserializer(std::filesystem::path); - virtual void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootPtr) override; protected: const std::filesystem::path path; @@ -85,7 +85,7 @@ namespace Slicer { public: XmlDocumentDeserializer(const xmlpp::Document *); - virtual void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootPtr) override; protected: const xmlpp::Document * doc; |