From bf1c5f2fa5b1d1e78531279e08c1e6eb00a2fef5 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Mon, 3 Dec 2018 10:48:50 -0800 Subject: [PATCH] Make Serializer::Factory stored by HFMFormatRegistry unique_ptr --- libraries/hfm/src/hfm/HFMFormatRegistry.cpp | 14 +++++++------- libraries/hfm/src/hfm/HFMFormatRegistry.h | 12 ++++++------ libraries/hfm/src/hfm/HFMSimpleFormat.cpp | 2 +- .../src/model-networking/ModelLoader.cpp | 6 +++--- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/libraries/hfm/src/hfm/HFMFormatRegistry.cpp b/libraries/hfm/src/hfm/HFMFormatRegistry.cpp index 08f13c414a..1be05e99d9 100644 --- a/libraries/hfm/src/hfm/HFMFormatRegistry.cpp +++ b/libraries/hfm/src/hfm/HFMFormatRegistry.cpp @@ -13,7 +13,7 @@ namespace hfm { -FormatRegistry::MIMETypeID FormatRegistry::registerMIMEType(const MIMEType& mimeType, const std::shared_ptr& supportedFactory) { +FormatRegistry::MIMETypeID FormatRegistry::registerMIMEType(const MIMEType& mimeType, std::unique_ptr& supportedFactory) { MIMETypeID id = _mimeTypeLibrary.registerMIMEType(mimeType); withWriteLock([&](){ _supportedFormats.emplace_back(id, supportedFactory); @@ -33,20 +33,20 @@ void FormatRegistry::unregisterMIMEType(const MIMETypeID& mimeTypeID) { _mimeTypeLibrary.unregisterMIMEType(mimeTypeID); } -std::shared_ptr FormatRegistry::getFactoryForMIMETypeID(FormatRegistry::MIMETypeID mimeTypeID) const { - return resultWithReadLock>([&](){ +std::shared_ptr FormatRegistry::getSerializerForMIMETypeID(FormatRegistry::MIMETypeID mimeTypeID) const { + return resultWithReadLock>([&](){ for (auto it = _supportedFormats.begin(); it != _supportedFormats.end(); it++) { if ((*it).mimeTypeID == mimeTypeID) { - return (*it).factory; + return (*it).factory->get(); } } - return std::shared_ptr(); + return std::shared_ptr(); }); } -std::shared_ptr FormatRegistry::getFactoryForMIMEType(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url, const std::string& webMediaType) const { +std::shared_ptr FormatRegistry::getSerializerForMIMEType(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url, const std::string& webMediaType) const { MIMETypeID id = _mimeTypeLibrary.findMatchingMIMEType(data, mapping, url, webMediaType); - return getFactoryForMIMETypeID(id); + return getSerializerForMIMETypeID(id); } }; diff --git a/libraries/hfm/src/hfm/HFMFormatRegistry.h b/libraries/hfm/src/hfm/HFMFormatRegistry.h index e807d98c46..6e0bd5c66c 100644 --- a/libraries/hfm/src/hfm/HFMFormatRegistry.h +++ b/libraries/hfm/src/hfm/HFMFormatRegistry.h @@ -23,22 +23,22 @@ public: using MIMETypeID = MIMETypeLibrary::ID; static const MIMETypeID INVALID_MIME_TYPE_ID { MIMETypeLibrary::INVALID_ID }; - MIMETypeID registerMIMEType(const MIMEType& mimeType, const std::shared_ptr& supportedFactory); + MIMETypeID registerMIMEType(const MIMEType& mimeType, std::unique_ptr& supportedFactory); void unregisterMIMEType(const MIMETypeID& id); - std::shared_ptr getFactoryForMIMEType(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url, const std::string& webMediaType) const; - std::shared_ptr getFactoryForMIMETypeID(MIMETypeID id) const; + std::shared_ptr getSerializerForMIMEType(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url, const std::string& webMediaType) const; + std::shared_ptr getSerializerForMIMETypeID(MIMETypeID id) const; protected: MIMETypeLibrary _mimeTypeLibrary; class SupportedFormat { public: - SupportedFormat(const MIMETypeID& mimeTypeID, const std::shared_ptr& factory) : + SupportedFormat(const MIMETypeID& mimeTypeID, std::unique_ptr& factory) : mimeTypeID(mimeTypeID), - factory(factory) { + factory(std::move(factory)) { } MIMETypeID mimeTypeID; - std::shared_ptr factory; + std::unique_ptr factory; }; std::vector _supportedFormats; }; diff --git a/libraries/hfm/src/hfm/HFMSimpleFormat.cpp b/libraries/hfm/src/hfm/HFMSimpleFormat.cpp index 2881945400..0388268de8 100644 --- a/libraries/hfm/src/hfm/HFMSimpleFormat.cpp +++ b/libraries/hfm/src/hfm/HFMSimpleFormat.cpp @@ -24,7 +24,7 @@ namespace hfm { template void SimpleFormat::registerFormat(FormatRegistry& registry) { - _mimeTypeID = registry.registerMIMEType(_mimeType, std::make_shared>()); + _mimeTypeID = registry.registerMIMEType(_mimeType, std::make_unique>()); } template diff --git a/libraries/model-networking/src/model-networking/ModelLoader.cpp b/libraries/model-networking/src/model-networking/ModelLoader.cpp index ff32c3a999..51d2c96ee3 100644 --- a/libraries/model-networking/src/model-networking/ModelLoader.cpp +++ b/libraries/model-networking/src/model-networking/ModelLoader.cpp @@ -16,9 +16,9 @@ hfm::Model::Pointer ModelLoader::load(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url, const std::string& webMediaType) const { - auto factory = DependencyManager::get()->getFactoryForMIMEType(data, mapping, url, webMediaType); - if (!factory) { + auto serializer = DependencyManager::get()->getSerializerForMIMEType(data, mapping, url, webMediaType); + if (!serializer) { return hfm::Model::Pointer(); } - return factory->get()->read(data, mapping, url); + return serializer->read(data, mapping, url); }