From 71fd88a5b5839b228c824e61028787be8e825dad Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 27 Apr 2015 10:40:20 +0200 Subject: Use std::shared_ptr instead of QSharedPointer for facade factory. Because it supports std::shared_ptr, which is a nice alternative to make everything a QObject subclass for nothing. --- common/clientapi.h | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) (limited to 'common/clientapi.h') diff --git a/common/clientapi.h b/common/clientapi.h index 6d66e40..f7f4c13 100644 --- a/common/clientapi.h +++ b/common/clientapi.h @@ -490,7 +490,7 @@ public: } template - QSharedPointer > getFacade(const QByteArray &resource) + std::shared_ptr > getFacade(const QByteArray &resource) { const QByteArray typeName = ApplicationDomain::getTypeName(); auto factoryFunction = mFacadeRegistry.value(key(resource, typeName)); @@ -499,27 +499,19 @@ public: auto ptr = static_cast* >(factoryFunction(externallyManaged)); if (externallyManaged) { //Allows tests to manage the lifetime of injected facades themselves - return QSharedPointer >(ptr, doNothingDeleter); + return std::shared_ptr >(ptr, doNothingDeleter); } else { - return QSharedPointer >(ptr); + return std::shared_ptr >(ptr); } } qWarning() << "Failed to find facade for resource: " << resource << " and type: " << typeName; - return QSharedPointer >(); + return std::shared_ptr >(); } private: QHash mFacadeRegistry; }; -template -struct LifeExtender { - LifeExtender(const QSharedPointer > &f) : facade(f) {} -private: - QSharedPointer > facade; -}; - - /** * Store interface used in the client API. */ @@ -551,8 +543,7 @@ public: auto facade = FacadeFactory::instance().getFacade(resource); facade->load(query, resultSet).template then([&future](){future.setFinished();}).exec(); //Keep the facade alive for the duration for the lifetime of the resultSet. - //TODO If the factory returned a std::shared_ptr we wouldn't require LifeExtender - resultSet->setFacade(std::make_shared >(facade)); + resultSet->setFacade(facade); }).template then([query, resultSet]() { resultSet->initialResultSetComplete(); if (!query.liveQuery) { -- cgit v1.2.3