diff options
author | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-08-06 11:22:34 +0100 |
---|---|---|
committer | Dan Goodliffe <dan@randomdan.homeip.net> | 2023-08-06 11:22:34 +0100 |
commit | 10049bab0f9765a726dd268aacd431d52d35b144 (patch) | |
tree | a6a68fb2011d955d6870106d86fc26112f777a84 | |
parent | Introduce any_ptr and replace shared_ptr model part params (diff) | |
download | slicer-10049bab0f9765a726dd268aacd431d52d35b144.tar.bz2 slicer-10049bab0f9765a726dd268aacd431d52d35b144.tar.xz slicer-10049bab0f9765a726dd268aacd431d52d35b144.zip |
Replace lots of shared_ptr with unique_ptr or any_ptr
-rw-r--r-- | slicer/db/sqlInsertSerializer.cpp | 2 | ||||
-rw-r--r-- | slicer/db/sqlInsertSerializer.h | 2 | ||||
-rw-r--r-- | slicer/db/sqlSelectDeserializer.cpp | 2 | ||||
-rw-r--r-- | slicer/db/sqlSelectDeserializer.h | 2 | ||||
-rw-r--r-- | slicer/db/sqlTablePatchSerializer.cpp | 2 | ||||
-rw-r--r-- | slicer/db/sqlTablePatchSerializer.h | 2 | ||||
-rw-r--r-- | slicer/db/sqlUpdateSerializer.cpp | 2 | ||||
-rw-r--r-- | slicer/db/sqlUpdateSerializer.h | 2 | ||||
-rw-r--r-- | slicer/ice/serializer.cpp | 8 | ||||
-rw-r--r-- | slicer/ice/serializer.h | 8 | ||||
-rw-r--r-- | slicer/json/serializer.cpp | 10 | ||||
-rw-r--r-- | slicer/json/serializer.h | 10 | ||||
-rw-r--r-- | slicer/slicer/modelParts.h | 3 | ||||
-rw-r--r-- | slicer/slicer/modelPartsTypes.impl.h | 6 | ||||
-rw-r--r-- | slicer/slicer/serializer.h | 4 | ||||
-rw-r--r-- | slicer/xml/serializer.cpp | 10 | ||||
-rw-r--r-- | slicer/xml/serializer.h | 10 |
17 files changed, 43 insertions, 42 deletions
diff --git a/slicer/db/sqlInsertSerializer.cpp b/slicer/db/sqlInsertSerializer.cpp index c120f10..ff30c7c 100644 --- a/slicer/db/sqlInsertSerializer.cpp +++ b/slicer/db/sqlInsertSerializer.cpp @@ -23,7 +23,7 @@ namespace Slicer { } void - SqlInsertSerializer::Serialize(Slicer::ModelPartForRootPtr mp) + SqlInsertSerializer::Serialize(ModelPartForRootParam mp) { switch (mp->GetType()) { case Slicer::ModelPartType::Sequence: diff --git a/slicer/db/sqlInsertSerializer.h b/slicer/db/sqlInsertSerializer.h index 3451455..f9f4fdf 100644 --- a/slicer/db/sqlInsertSerializer.h +++ b/slicer/db/sqlInsertSerializer.h @@ -18,7 +18,7 @@ namespace Slicer { public: SqlInsertSerializer(DB::Connection * const, std::string tableName); - void Serialize(Slicer::ModelPartForRootPtr) override; + void Serialize(ModelPartForRootParam) override; protected: void SerializeObject(ModelPartParam) const; diff --git a/slicer/db/sqlSelectDeserializer.cpp b/slicer/db/sqlSelectDeserializer.cpp index 554703f..526f4b7 100644 --- a/slicer/db/sqlSelectDeserializer.cpp +++ b/slicer/db/sqlSelectDeserializer.cpp @@ -15,7 +15,7 @@ namespace Slicer { } void - SqlSelectDeserializer::Deserialize(Slicer::ModelPartForRootPtr mp) + SqlSelectDeserializer::Deserialize(ModelPartForRootParam mp) { cmd->execute(); columnCount = cmd->columnCount(); diff --git a/slicer/db/sqlSelectDeserializer.h b/slicer/db/sqlSelectDeserializer.h index 32106d7..f8fce08 100644 --- a/slicer/db/sqlSelectDeserializer.h +++ b/slicer/db/sqlSelectDeserializer.h @@ -17,7 +17,7 @@ namespace Slicer { explicit SqlSelectDeserializer( DB::SelectCommand *, std::optional<std::string> typeIdCol = std::optional<std::string>()); - void Deserialize(Slicer::ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootParam) override; protected: void DLL_PRIVATE DeserializeSimple(ModelPartParam); diff --git a/slicer/db/sqlTablePatchSerializer.cpp b/slicer/db/sqlTablePatchSerializer.cpp index a22f15a..69acb16 100644 --- a/slicer/db/sqlTablePatchSerializer.cpp +++ b/slicer/db/sqlTablePatchSerializer.cpp @@ -19,7 +19,7 @@ namespace Slicer { } void - SqlTablePatchSerializer::Serialize(Slicer::ModelPartForRootPtr mpr) + SqlTablePatchSerializer::Serialize(ModelPartForRootParam mpr) { tablePatch.pk.clear(); tablePatch.cols.clear(); diff --git a/slicer/db/sqlTablePatchSerializer.h b/slicer/db/sqlTablePatchSerializer.h index 73e084d..1da29a6 100644 --- a/slicer/db/sqlTablePatchSerializer.h +++ b/slicer/db/sqlTablePatchSerializer.h @@ -15,7 +15,7 @@ namespace Slicer { public: SqlTablePatchSerializer(DB::Connection * const, DB::TablePatch &); - void Serialize(Slicer::ModelPartForRootPtr) override; + void Serialize(ModelPartForRootParam) override; private: void createTemporaryTable(); diff --git a/slicer/db/sqlUpdateSerializer.cpp b/slicer/db/sqlUpdateSerializer.cpp index 8a3c3a4..c054764 100644 --- a/slicer/db/sqlUpdateSerializer.cpp +++ b/slicer/db/sqlUpdateSerializer.cpp @@ -21,7 +21,7 @@ namespace Slicer { } void - SqlUpdateSerializer::Serialize(Slicer::ModelPartForRootPtr mp) + SqlUpdateSerializer::Serialize(ModelPartForRootParam mp) { switch (mp->GetType()) { case Slicer::ModelPartType::Sequence: diff --git a/slicer/db/sqlUpdateSerializer.h b/slicer/db/sqlUpdateSerializer.h index 07ee5bb..c634ff5 100644 --- a/slicer/db/sqlUpdateSerializer.h +++ b/slicer/db/sqlUpdateSerializer.h @@ -17,7 +17,7 @@ namespace Slicer { public: SqlUpdateSerializer(DB::Connection * const, std::string tableName); - void Serialize(Slicer::ModelPartForRootPtr) override; + void Serialize(ModelPartForRootParam) override; protected: void SerializeObject(ModelPartParam) const; diff --git a/slicer/ice/serializer.cpp b/slicer/ice/serializer.cpp index eacecf8..eb27729 100644 --- a/slicer/ice/serializer.cpp +++ b/slicer/ice/serializer.cpp @@ -22,7 +22,7 @@ namespace Slicer { } void - IceBlobSerializer::Serialize(ModelPartForRootPtr mp) + IceBlobSerializer::Serialize(ModelPartForRootParam mp) { Ice::OutputStream s(ic); mp->Write(s); @@ -32,7 +32,7 @@ namespace Slicer { IceStreamSerializer::IceStreamSerializer(std::ostream & os) : strm(os) { } void - IceStreamSerializer::Serialize(ModelPartForRootPtr mp) + IceStreamSerializer::Serialize(ModelPartForRootParam mp) { IceBlobSerializer::Serialize(mp); strm.write(reinterpret_cast<const char *>(blob.data()), static_cast<std::streamsize>(blob.size())); @@ -41,7 +41,7 @@ namespace Slicer { IceBlobDeserializer::IceBlobDeserializer(const Ice::ByteSeq & b) : refblob(b) { } void - IceBlobDeserializer::Deserialize(ModelPartForRootPtr mp) + IceBlobDeserializer::Deserialize(ModelPartForRootParam mp) { Ice::InputStream s(ic, refblob); mp->Read(s); @@ -50,7 +50,7 @@ namespace Slicer { IceStreamDeserializer::IceStreamDeserializer(std::istream & is) : IceBlobDeserializer(blob), strm(is) { } void - IceStreamDeserializer::Deserialize(ModelPartForRootPtr mp) + IceStreamDeserializer::Deserialize(ModelPartForRootParam mp) { blob.assign(std::istreambuf_iterator<char>(strm), std::istreambuf_iterator<char>()); IceBlobDeserializer::Deserialize(mp); diff --git a/slicer/ice/serializer.h b/slicer/ice/serializer.h index db467cd..0e9919d 100644 --- a/slicer/ice/serializer.h +++ b/slicer/ice/serializer.h @@ -21,7 +21,7 @@ namespace Slicer { class DLL_PUBLIC IceBlobSerializer : public Serializer, protected IceBase { public: - void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootParam) override; protected: Ice::ByteSeq blob; @@ -31,7 +31,7 @@ namespace Slicer { public: explicit IceStreamSerializer(std::ostream &); - void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootParam) override; protected: std::ostream & strm; @@ -41,7 +41,7 @@ namespace Slicer { public: explicit IceBlobDeserializer(const Ice::ByteSeq &); - void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootParam) override; protected: const Ice::ByteSeq & refblob; @@ -51,7 +51,7 @@ namespace Slicer { public: explicit IceStreamDeserializer(std::istream &); - void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootParam) override; protected: std::istream & strm; diff --git a/slicer/json/serializer.cpp b/slicer/json/serializer.cpp index 4c37d71..db77607 100644 --- a/slicer/json/serializer.cpp +++ b/slicer/json/serializer.cpp @@ -370,7 +370,7 @@ namespace Slicer { JsonStreamDeserializer::JsonStreamDeserializer(std::istream & s) : strm(s) { } void - JsonStreamDeserializer::Deserialize(ModelPartForRootPtr modelRoot) + JsonStreamDeserializer::Deserialize(ModelPartForRootParam modelRoot) { json::Value obj = json::parseValue(strm); auto mp = modelRoot->GetAnonChild(); @@ -378,7 +378,7 @@ namespace Slicer { } void - JsonStreamSerializer::Serialize(ModelPartForRootPtr modelRoot) + JsonStreamSerializer::Serialize(ModelPartForRootParam modelRoot) { JsonValueSerializer::Serialize(modelRoot); json::serializeValue(value, strm, "utf-8"); @@ -389,7 +389,7 @@ namespace Slicer { JsonFileDeserializer::JsonFileDeserializer(std::filesystem::path p) : path(std::move(p)) { } void - JsonFileDeserializer::Deserialize(ModelPartForRootPtr modelRoot) + JsonFileDeserializer::Deserialize(ModelPartForRootParam modelRoot) { std::ifstream inFile(path); json::Value obj = json::parseValue(inFile); @@ -400,14 +400,14 @@ namespace Slicer { JsonValueDeserializer::JsonValueDeserializer(const json::Value & v) : value(v) { } void - JsonValueDeserializer::Deserialize(ModelPartForRootPtr modelRoot) + JsonValueDeserializer::Deserialize(ModelPartForRootParam modelRoot) { auto mp = modelRoot->GetAnonChild(); std::visit(DocumentTreeIterate(mp), value); } void - JsonValueSerializer::Serialize(ModelPartForRootPtr modelRoot) + JsonValueSerializer::Serialize(ModelPartForRootParam modelRoot) { 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 230f1c9..1e373d1 100644 --- a/slicer/json/serializer.h +++ b/slicer/json/serializer.h @@ -21,7 +21,7 @@ namespace Slicer { class DLL_PUBLIC JsonValueSerializer : public JsonSerializer { public: - void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootParam) override; protected: json::Value value; @@ -31,7 +31,7 @@ namespace Slicer { public: explicit JsonStreamSerializer(std::ostream &); - void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootParam) override; protected: std::ostream & strm; @@ -49,7 +49,7 @@ namespace Slicer { public: explicit JsonStreamDeserializer(std::istream &); - void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootParam) override; protected: std::istream & strm; @@ -59,7 +59,7 @@ namespace Slicer { public: explicit JsonFileDeserializer(std::filesystem::path); - void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootParam) override; protected: const std::filesystem::path path; @@ -69,7 +69,7 @@ namespace Slicer { public: explicit JsonValueDeserializer(const json::Value &); - void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootParam) override; protected: const json::Value & value; diff --git a/slicer/slicer/modelParts.h b/slicer/slicer/modelParts.h index f2e26e1..6514c69 100644 --- a/slicer/slicer/modelParts.h +++ b/slicer/slicer/modelParts.h @@ -79,8 +79,9 @@ namespace Slicer { class HookCommon; using ModelPartPtr = std::shared_ptr<ModelPart>; - using ModelPartForRootPtr = std::shared_ptr<ModelPartForRootBase>; + using ModelPartForRootPtr = std::unique_ptr<ModelPartForRootBase>; using ModelPartParam = any_ptr<ModelPart>; + using ModelPartForRootParam = any_ptr<ModelPartForRootBase>; using TypeId = std::optional<std::string>; using ChildHandler = std::function<void(const std::string &, const ModelPartParam &, const HookCommon *)>; using ClassRef = std::function<ModelPartPtr(void *)>; diff --git a/slicer/slicer/modelPartsTypes.impl.h b/slicer/slicer/modelPartsTypes.impl.h index 95d0a37..2d2f7c8 100644 --- a/slicer/slicer/modelPartsTypes.impl.h +++ b/slicer/slicer/modelPartsTypes.impl.h @@ -69,11 +69,11 @@ namespace Ice { } \ template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(Type & s) \ { \ - return std::make_shared<ModelPartForRoot<Type>>(&s); \ + return std::make_unique<ModelPartForRoot<Type>>(&s); \ } \ template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(Ice::optional<Type> & s) \ { \ - return std::make_shared<ModelPartForRoot<Ice::optional<Type>>>(&s); \ + return std::make_unique<ModelPartForRoot<Ice::optional<Type>>>(&s); \ } \ template<> DLL_PUBLIC ModelPartForRootPtr ModelPart::CreateRootFor(const Type & s) \ { \ @@ -94,7 +94,7 @@ namespace Ice { DLL_PUBLIC ModelPartForRootPtr \ ModelPart::CreateRootFor(const StreamImpl & stream) \ { \ - return std::make_shared<ModelPartForStreamRoot<typename StreamImpl::element_type>>( \ + return std::make_unique<ModelPartForStreamRoot<typename StreamImpl::element_type>>( \ const_cast<StreamImpl *>(&stream)); \ } \ } diff --git a/slicer/slicer/serializer.h b/slicer/slicer/serializer.h index f26a914..653e61a 100644 --- a/slicer/slicer/serializer.h +++ b/slicer/slicer/serializer.h @@ -19,7 +19,7 @@ namespace Slicer { virtual ~Serializer() = default; - virtual void Serialize(ModelPartForRootPtr) = 0; + virtual void Serialize(ModelPartForRootParam) = 0; }; using SerializerPtr = std::shared_ptr<Serializer>; @@ -31,7 +31,7 @@ namespace Slicer { virtual ~Deserializer() = default; - virtual void Deserialize(ModelPartForRootPtr) = 0; + virtual void Deserialize(ModelPartForRootParam) = 0; }; using DeserializerPtr = std::shared_ptr<Deserializer>; diff --git a/slicer/xml/serializer.cpp b/slicer/xml/serializer.cpp index 7053756..f9cb045 100644 --- a/slicer/xml/serializer.cpp +++ b/slicer/xml/serializer.cpp @@ -449,7 +449,7 @@ namespace Slicer { XmlStreamDeserializer::XmlStreamDeserializer(std::istream & s) : strm(s) { } void - XmlStreamDeserializer::Deserialize(ModelPartForRootPtr modelRoot) + XmlStreamDeserializer::Deserialize(ModelPartForRootParam modelRoot) { xmlpp::DomParser dom; dom.parse_stream(strm); @@ -458,7 +458,7 @@ namespace Slicer { } void - XmlStreamSerializer::Serialize(ModelPartForRootPtr modelRoot) + XmlStreamSerializer::Serialize(ModelPartForRootParam modelRoot) { XmlDocumentSerializer::Serialize(modelRoot); doc.write_to_stream(strm); @@ -469,7 +469,7 @@ namespace Slicer { XmlFileDeserializer::XmlFileDeserializer(std::filesystem::path p) : path(std::move(p)) { } void - XmlFileDeserializer::Deserialize(ModelPartForRootPtr modelRoot) + XmlFileDeserializer::Deserialize(ModelPartForRootParam modelRoot) { xmlpp::DomParser dom(path); auto doc = dom.get_document(); @@ -479,13 +479,13 @@ namespace Slicer { XmlDocumentDeserializer::XmlDocumentDeserializer(const xmlpp::Document * d) : doc(d) { } void - XmlDocumentDeserializer::Deserialize(ModelPartForRootPtr modelRoot) + XmlDocumentDeserializer::Deserialize(ModelPartForRootParam modelRoot) { DocumentTreeIterate(doc, modelRoot); } void - XmlDocumentSerializer::Serialize(ModelPartForRootPtr modelRoot) + XmlDocumentSerializer::Serialize(ModelPartForRootParam modelRoot) { modelRoot->OnEachChild([this](auto && PH1, auto && PH2, auto &&) { return XmlSerializer::ModelTreeIterateRoot(&doc, PH1, PH2); diff --git a/slicer/xml/serializer.h b/slicer/xml/serializer.h index 4ee818a..d138ac0 100644 --- a/slicer/xml/serializer.h +++ b/slicer/xml/serializer.h @@ -42,7 +42,7 @@ namespace Slicer { class DLL_PUBLIC XmlDocumentSerializer : public XmlSerializer { public: - void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootParam) override; protected: xmlpp::Document doc; @@ -52,7 +52,7 @@ namespace Slicer { public: explicit XmlStreamSerializer(std::ostream &); - void Serialize(ModelPartForRootPtr) override; + void Serialize(ModelPartForRootParam) override; protected: std::ostream & strm; @@ -80,7 +80,7 @@ namespace Slicer { public: explicit XmlStreamDeserializer(std::istream &); - void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootParam) override; protected: std::istream & strm; @@ -90,7 +90,7 @@ namespace Slicer { public: explicit XmlFileDeserializer(std::filesystem::path); - void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootParam) override; protected: const std::filesystem::path path; @@ -100,7 +100,7 @@ namespace Slicer { public: explicit XmlDocumentDeserializer(const xmlpp::Document *); - void Deserialize(ModelPartForRootPtr) override; + void Deserialize(ModelPartForRootParam) override; protected: const xmlpp::Document * doc; |