diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-04-21 07:51:25 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-05-01 08:26:24 +0200 |
commit | ed8152b1ed9baf859966fd21d6641dfba9c4467c (patch) | |
tree | b4f7b372433c5da3b8df41d026ff95fecece9ce6 | |
parent | 6cb9b06432434fb3257118743780828b3b57326a (diff) |
improve loplugin:makeshared
to find places where we are converting stuff to unique_ptr
instead of using std::make_shared.
As a bonus, this tends to find places where we are using shared_ptr
where we can instead be using unique_ptr avoiding the locking overhead.
Change-Id: I1b57bbc4a6c766b48bba8e25a55161800e149f62
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/93207
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
26 files changed, 244 insertions, 126 deletions
diff --git a/avmedia/source/vlc/vlcframegrabber.cxx b/avmedia/source/vlc/vlcframegrabber.cxx index a2c17c0a70e7..034de45118d7 100644 --- a/avmedia/source/vlc/vlcframegrabber.cxx +++ b/avmedia/source/vlc/vlcframegrabber.cxx @@ -101,7 +101,7 @@ VLCFrameGrabber::VLCFrameGrabber( wrapper::EventHandler& eh, const OUString& url OUString url; osl::FileBase::getFileURLFromSystemPath( fileName, url ); - std::shared_ptr<SvStream> stream( utl::UcbStreamHelper::CreateStream( url, + std::unique_ptr<SvStream> stream( utl::UcbStreamHelper::CreateStream( url, StreamMode::STD_READ ) ); vcl::PNGReader reader( *stream ); diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index b44d712dbd50..200704e90a8d 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -351,7 +351,7 @@ xmlDocPtr Chart2ExportTest::parseExport(const OUString& rDir, const OUString& rF uno::Reference<packages::zip::XZipFileAccess2> xNameAccess = packages::zip::ZipFileAccess::createWithURL(comphelper::getComponentContext(m_xSFactory), pTempFile->GetURL()); uno::Reference<io::XInputStream> xInputStream(xNameAccess->getByName(findChartFile(rDir, xNameAccess)), uno::UNO_QUERY); CPPUNIT_ASSERT(xInputStream.is()); - std::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); return parseXmlStream(pStream.get()); } diff --git a/chart2/source/view/axes/VPolarAxis.cxx b/chart2/source/view/axes/VPolarAxis.cxx index 2b251ef9a081..9e41857c29d4 100644 --- a/chart2/source/view/axes/VPolarAxis.cxx +++ b/chart2/source/view/axes/VPolarAxis.cxx @@ -27,13 +27,13 @@ namespace chart using namespace ::com::sun::star; using namespace ::com::sun::star::chart2; -VPolarAxis* VPolarAxis::createAxis( const AxisProperties& rAxisProperties +std::shared_ptr<VPolarAxis> VPolarAxis::createAxis( const AxisProperties& rAxisProperties , const uno::Reference< util::XNumberFormatsSupplier >& xNumberFormatsSupplier , sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount ) { if( nDimensionIndex==0 ) - return new VPolarAngleAxis( rAxisProperties, xNumberFormatsSupplier, nDimensionCount ); - return new VPolarRadiusAxis( rAxisProperties, xNumberFormatsSupplier, nDimensionCount ); + return std::make_shared<VPolarAngleAxis>( rAxisProperties, xNumberFormatsSupplier, nDimensionCount ); + return std::make_shared<VPolarRadiusAxis>( rAxisProperties, xNumberFormatsSupplier, nDimensionCount ); } VPolarAxis::VPolarAxis( const AxisProperties& rAxisProperties diff --git a/chart2/source/view/axes/VPolarAxis.hxx b/chart2/source/view/axes/VPolarAxis.hxx index f1626f4b9474..0a7056be72aa 100644 --- a/chart2/source/view/axes/VPolarAxis.hxx +++ b/chart2/source/view/axes/VPolarAxis.hxx @@ -30,7 +30,7 @@ class PolarPlottingPositionHelper; class VPolarAxis : public VAxisBase { public: - static VPolarAxis* createAxis( const AxisProperties& rAxisProperties + static std::shared_ptr<VPolarAxis> createAxis( const AxisProperties& rAxisProperties , const css::uno::Reference< css::util::XNumberFormatsSupplier >& xNumberFormatsSupplier , sal_Int32 nDimensionIndex, sal_Int32 nDimensionCount ); diff --git a/compilerplugins/clang/makeshared.cxx b/compilerplugins/clang/makeshared.cxx index 398a3acc4654..9f12b6c3bd6b 100644 --- a/compilerplugins/clang/makeshared.cxx +++ b/compilerplugins/clang/makeshared.cxx @@ -47,6 +47,43 @@ public: return false; if (loplugin::isSamePathname(fn, SRCDIR "/sc/source/filter/excel/xecontent.cxx")) return false; + // no idea what is going on here + if (loplugin::isSamePathname(fn, SRCDIR "/svx/source/sidebar/nbdtmg.cxx")) + return false; + + // legitimate use of moving std::unique_ptr to std::shared_ptr + if (loplugin::isSamePathname(fn, SRCDIR "/comphelper/source/container/enumerablemap.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/svl/source/items/style.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/vcl/source/app/weldutils.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sfx2/source/appl/appopen.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/svx/source/table/tablertfimporter.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sc/source/ui/docshell/externalrefmgr.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sw/source/core/attr/swatrset.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sc/source/ui/condformat/condformatdlg.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sw/source/core/layout/frmtool.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sc/source/filter/excel/xihelper.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sc/source/filter/excel/xeformula.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sc/source/filter/excel/xichart.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sc/source/filter/html/htmlpars.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sc/source/ui/view/cellsh1.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sw/source/filter/html/htmltab.cxx")) + return false; + if (loplugin::isSamePathname(fn, SRCDIR "/sw/source/filter/ww8/docxattributeoutput.cxx")) + return false; return true; } @@ -60,6 +97,8 @@ public: bool VisitCXXConstructExpr(CXXConstructExpr const*); bool VisitCXXMemberCallExpr(CXXMemberCallExpr const*); + bool VisitCXXOperatorCallExpr(CXXOperatorCallExpr const*); + bool VisitVarDecl(VarDecl const*); }; bool MakeShared::VisitCXXConstructExpr(CXXConstructExpr const* constructExpr) @@ -71,25 +110,39 @@ bool MakeShared::VisitCXXConstructExpr(CXXConstructExpr const* constructExpr) if (!(constructExpr->getNumArgs() == 1 || (constructExpr->getNumArgs() > 1 && isa<CXXDefaultArgExpr>(constructExpr->getArg(1))))) return true; - auto cxxNewExpr = dyn_cast<CXXNewExpr>(constructExpr->getArg(0)->IgnoreParenImpCasts()); - if (!cxxNewExpr) - return true; - auto construct2 = cxxNewExpr->getConstructExpr(); - if (construct2) + auto arg0 = constructExpr->getArg(0)->IgnoreParenImpCasts(); + auto cxxNewExpr = dyn_cast<CXXNewExpr>(arg0); + if (cxxNewExpr) { - if (construct2->getConstructor()->getAccess() != AS_public) - return true; - if (construct2->getNumArgs() == 1 && isa<CXXStdInitializerListExpr>(construct2->getArg(0))) - return true; + auto construct2 = cxxNewExpr->getConstructExpr(); + if (construct2) + { + if (construct2->getConstructor()->getAccess() != AS_public) + return true; + if (construct2->getNumArgs() == 1 + && isa<CXXStdInitializerListExpr>(construct2->getArg(0))) + return true; + } } + else if (loplugin::TypeCheck(arg0->getType()).ClassOrStruct("shared_ptr").StdNamespace()) + return true; + else if (loplugin::TypeCheck(arg0->getType()).ClassOrStruct("weak_ptr").StdNamespace()) + return true; + else if (arg0->getType()->isDependentType()) + return true; + else if (isa<CXXNullPtrLiteralExpr>(arg0)) + return true; StringRef fn = getFilenameOfLocation( compiler.getSourceManager().getSpellingLoc(compat::getBeginLoc(constructExpr))); if (loplugin::isSamePathname(fn, SRCDIR "/include/o3tl/make_shared.hxx")) return true; + if (loplugin::isSamePathname(fn, SRCDIR "/svl/source/items/stylepool.cxx")) + return true; - report(DiagnosticsEngine::Warning, "rather use make_shared", compat::getBeginLoc(cxxNewExpr)) - << cxxNewExpr->getSourceRange(); + report(DiagnosticsEngine::Warning, "rather use make_shared than constructing from %0", + compat::getBeginLoc(constructExpr)) + << arg0->getType() << constructExpr->getSourceRange(); return true; } @@ -97,6 +150,7 @@ bool MakeShared::VisitCXXMemberCallExpr(CXXMemberCallExpr const* cxxMemberCallEx { if (ignoreLocation(cxxMemberCallExpr)) return true; + if (cxxMemberCallExpr->getNumArgs() != 1) return true; @@ -132,6 +186,54 @@ bool MakeShared::VisitCXXMemberCallExpr(CXXMemberCallExpr const* cxxMemberCallEx return true; } +bool MakeShared::VisitCXXOperatorCallExpr(CXXOperatorCallExpr const* operCallExpr) +{ + if (ignoreLocation(operCallExpr)) + return true; + if (!operCallExpr->isAssignmentOp()) + return true; + + if (!loplugin::TypeCheck(operCallExpr->getType()).ClassOrStruct("shared_ptr").StdNamespace()) + return true; + + if (loplugin::TypeCheck(operCallExpr->getArg(1)->getType()) + .ClassOrStruct("shared_ptr") + .StdNamespace()) + return true; + + report(DiagnosticsEngine::Warning, "rather use make_shared than constructing from %0", + compat::getBeginLoc(operCallExpr)) + << operCallExpr->getArg(1)->getType() << operCallExpr->getSourceRange(); + + return true; +} + +bool MakeShared::VisitVarDecl(VarDecl const* varDecl) +{ + if (ignoreLocation(varDecl)) + return true; + if (!varDecl->hasInit()) + return true; + + if (!loplugin::TypeCheck(varDecl->getType()).ClassOrStruct("shared_ptr").StdNamespace()) + return true; + + if (varDecl->getInit()->getType().isNull()) + return true; + if (varDecl->getInit()->getType()->isDependentType()) + return true; + if (loplugin::TypeCheck(varDecl->getInit()->IgnoreParenImpCasts()->getType()) + .ClassOrStruct("shared_ptr") + .StdNamespace()) + return true; + + report(DiagnosticsEngine::Warning, "rather use make_shared than constructing from %0", + compat::getBeginLoc(varDecl)) + << varDecl->getInit()->getType() << varDecl->getSourceRange(); + + return true; +} + loplugin::Plugin::Registration<MakeShared> makeshared("makeshared"); } // namespace diff --git a/compilerplugins/clang/test/makeshared.cxx b/compilerplugins/clang/test/makeshared.cxx index 3bb4702a05d8..8833928e8c18 100644 --- a/compilerplugins/clang/test/makeshared.cxx +++ b/compilerplugins/clang/test/makeshared.cxx @@ -23,11 +23,12 @@ private: void test1() { - std::shared_ptr<int> x( - new int); // expected-error {{rather use make_shared [loplugin:makeshared]}} - x.reset(new int); // expected-error {{rather use make_shared [loplugin:makeshared]}} - x = std::shared_ptr<int>( - new int); // expected-error {{rather use make_shared [loplugin:makeshared]}} + // expected-error@+1 {{rather use make_shared than constructing from 'int *' [loplugin:makeshared]}} + std::shared_ptr<int> x(new int); + // expected-error@+1 {{rather use make_shared [loplugin:makeshared]}} + x.reset(new int); + // expected-error@+1 {{rather use make_shared than constructing from 'int *' [loplugin:makeshared]}} + x = std::shared_ptr<int>(new int); // no warning expected std::shared_ptr<int> y(new int, o3tl::default_delete<int>()); @@ -40,4 +41,23 @@ void test1() auto a = std::shared_ptr<o3tl::sorted_vector<int>>(new o3tl::sorted_vector<int>({ 1, 2 })); }; +void test2() +{ + // expected-error-re@+1 {{rather use make_shared than constructing from {{.+}} (aka 'unique_ptr<int>') [loplugin:makeshared]}} + std::shared_ptr<int> x = std::make_unique<int>(1); + // expected-error-re@+1 {{rather use make_shared than constructing from {{.+}} (aka 'unique_ptr<int>') [loplugin:makeshared]}} + x = std::make_unique<int>(1); + (void)x; + + // expected-error-re@+1 {{rather use make_shared than constructing from {{.+}} (aka 'unique_ptr<int>') [loplugin:makeshared]}} + std::shared_ptr<int> y(std::make_unique<int>(1)); + (void)y; + + std::unique_ptr<int> u1; + // expected-error-re@+1 {{rather use make_shared than constructing from {{.+}} (aka 'std::unique_ptr<int, std::default_delete<int> >') [loplugin:makeshared]}} + std::shared_ptr<int> z = std::move(u1); + // expected-error-re@+1 {{rather use make_shared than constructing from {{.+}} (aka 'std::unique_ptr<int, std::default_delete<int> >') [loplugin:makeshared]}} + z = std::move(u1); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/lotuswordpro/source/filter/lwpbulletstylemgr.cxx b/lotuswordpro/source/filter/lwpbulletstylemgr.cxx index ec3335766a19..6f5b638c8fea 100644 --- a/lotuswordpro/source/filter/lwpbulletstylemgr.cxx +++ b/lotuswordpro/source/filter/lwpbulletstylemgr.cxx @@ -126,7 +126,7 @@ OUString LwpBulletStyleMgr::RegisterBulletStyle(LwpPara* pPara, const LwpBulletO } LwpObjectID aBulletID = pBullOver->GetSilverBullet(); - std::shared_ptr<LwpBulletOverride> pBulletOver(pBullOver->clone()); + std::unique_ptr<LwpBulletOverride> pBulletOver(pBullOver->clone()); sal_uInt16 nNameIndex = 0; for (auto const& vIDsPair : m_vIDsPairList) @@ -142,7 +142,7 @@ OUString LwpBulletStyleMgr::RegisterBulletStyle(LwpPara* pPara, const LwpBulletO } } - m_vIDsPairList.emplace_back(pBulletOver, aIndentID); + m_vIDsPairList.emplace_back(std::move(pBulletOver), aIndentID); OUString aStyleName; LwpFribPtr& rBulletParaFribs = pBulletPara->GetFribs(); diff --git a/lotuswordpro/source/filter/lwpbulletstylemgr.hxx b/lotuswordpro/source/filter/lwpbulletstylemgr.hxx index 7a7e0a57c5f3..c4dd9d6c3be1 100644 --- a/lotuswordpro/source/filter/lwpbulletstylemgr.hxx +++ b/lotuswordpro/source/filter/lwpbulletstylemgr.hxx @@ -88,7 +88,7 @@ public: inline void SetCurrentSilverBullet(const LwpObjectID& rNewID); private: - typedef std::pair<std::shared_ptr<LwpBulletOverride>, LwpObjectID> OverridePair; + typedef std::pair<std::unique_ptr<LwpBulletOverride>, LwpObjectID> OverridePair; std::vector <OUString> m_vStyleNameList; std::vector <OverridePair> m_vIDsPairList; LwpFoundry* m_pFoundry; diff --git a/sd/qa/unit/export-tests-ooxml1.cxx b/sd/qa/unit/export-tests-ooxml1.cxx index 769bf6e52456..bb5d2add3f52 100644 --- a/sd/qa/unit/export-tests-ooxml1.cxx +++ b/sd/qa/unit/export-tests-ooxml1.cxx @@ -882,7 +882,7 @@ void SdOOXMLExportTest1::testCustomXml() assertXPath(pRelsDoc, "/rels:Relationships/rels:Relationship", 1); assertXPath(pRelsDoc, "/rels:Relationships/rels:Relationship[@Id='rId1']", "Target", "itemProps1.xml"); - std::shared_ptr<SvStream> pStream = parseExportStream(tempFile, "ddp/ddpfile.xen"); + std::unique_ptr<SvStream> pStream = parseExportStream(tempFile, "ddp/ddpfile.xen"); CPPUNIT_ASSERT(pStream); } diff --git a/sd/qa/unit/export-tests-ooxml2.cxx b/sd/qa/unit/export-tests-ooxml2.cxx index 6f77a2ecd849..7b0c9788e71b 100644 --- a/sd/qa/unit/export-tests-ooxml2.cxx +++ b/sd/qa/unit/export-tests-ooxml2.cxx @@ -2318,10 +2318,10 @@ void SdOOXMLExportTest2::testTdf44223() = loadURL(m_directories.getURLFromSrc("/sd/qa/unit/data/pptx/tdf44223.pptx"), PPTX); xDocShRef = saveAndReload(xDocShRef.get(), PPTX, &tempFile); - std::shared_ptr<SvStream> const pStream1(parseExportStream(tempFile, "ppt/media/audio1.wav")); + std::unique_ptr<SvStream> const pStream1(parseExportStream(tempFile, "ppt/media/audio1.wav")); CPPUNIT_ASSERT_EQUAL(sal_uInt64(11140), pStream1->remainingSize()); - std::shared_ptr<SvStream> const pStream2(parseExportStream(tempFile, "ppt/media/audio2.wav")); + std::unique_ptr<SvStream> const pStream2(parseExportStream(tempFile, "ppt/media/audio2.wav")); CPPUNIT_ASSERT_EQUAL(sal_uInt64(28074), pStream2->remainingSize()); xmlDocPtr pXmlContentType = parseExport(tempFile, "[Content_Types].xml"); diff --git a/sd/qa/unit/sdmodeltestbase.hxx b/sd/qa/unit/sdmodeltestbase.hxx index a490dcee60ee..b97313ffec6d 100644 --- a/sd/qa/unit/sdmodeltestbase.hxx +++ b/sd/qa/unit/sdmodeltestbase.hxx @@ -133,7 +133,7 @@ public: protected: /// Load the document. - sd::DrawDocShellRef loadURL( const OUString &rURL, sal_Int32 nFormat, std::unique_ptr<SfxAllItemSet> pParams = nullptr ) + sd::DrawDocShellRef loadURL( const OUString &rURL, sal_Int32 nFormat, std::shared_ptr<SfxAllItemSet> pParams = nullptr ) { FileFormat *pFmt = getFormat(nFormat); CPPUNIT_ASSERT_MESSAGE( "missing filter info", pFmt->pName != nullptr ); @@ -142,7 +142,7 @@ protected: SotClipboardFormatId nOptions = SotClipboardFormatId::NONE; if (pFmt->nFormatType != SfxFilterFlags::NONE) nOptions = SotClipboardFormatId::STARDRAW_8; - SfxFilter* pFilter = new SfxFilter( + auto pFilter = std::make_shared<SfxFilter>( OUString::createFromAscii( pFmt->pFilterName ), OUString(), pFmt->nFormatType, nOptions, OUString::createFromAscii( pFmt->pTypeName ), @@ -150,10 +150,9 @@ protected: OUString::createFromAscii( pFmt->pUserData ), "private:factory/sdraw*" ); pFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT); - std::shared_ptr<const SfxFilter> pFilt(pFilter); ::sd::DrawDocShellRef xDocShRef = new ::sd::GraphicDocShell(SfxObjectCreateMode::EMBEDDED); - SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ, pFilt, std::move(pParams)); + SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ, pFilter, std::move(pParams)); if ( !xDocShRef->DoLoad(pSrcMed) || !xDocShRef.is() ) { if (xDocShRef.is()) @@ -168,7 +167,7 @@ protected: SotClipboardFormatId nOptions = SotClipboardFormatId::NONE; if (pFmt->nFormatType != SfxFilterFlags::NONE) nOptions = SotClipboardFormatId::STARIMPRESS_8; - SfxFilter* pFilter = new SfxFilter( + auto pFilter = std::make_shared<SfxFilter>( OUString::createFromAscii( pFmt->pFilterName ), OUString(), pFmt->nFormatType, nOptions, OUString::createFromAscii( pFmt->pTypeName ), @@ -176,10 +175,9 @@ protected: OUString::createFromAscii( pFmt->pUserData ), "private:factory/simpress*" ); pFilter->SetVersion(SOFFICE_FILEFORMAT_CURRENT); - std::shared_ptr<const SfxFilter> pFilt(pFilter); ::sd::DrawDocShellRef xDocShRef = new ::sd::DrawDocShell(SfxObjectCreateMode::EMBEDDED, false, DocumentType::Impress); - SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ, pFilt, std::move(pParams)); + SfxMedium* pSrcMed = new SfxMedium(rURL, StreamMode::STD_READ, pFilter, std::move(pParams)); if ( !xDocShRef->DoLoad(pSrcMed) || !xDocShRef.is() ) { if (xDocShRef.is()) @@ -445,20 +443,20 @@ class SdModelTestBaseXML { public: - std::shared_ptr<SvStream> parseExportStream(utl::TempFile const & rTempFile, const OUString& rStreamName) + std::unique_ptr<SvStream> parseExportStream(utl::TempFile const & rTempFile, const OUString& rStreamName) { // Read the stream we're interested in. OUString const url(rTempFile.GetURL()); uno::Reference<packages::zip::XZipFileAccess2> const xZipNames(packages::zip::ZipFileAccess::createWithURL( comphelper::getComponentContext(m_xSFactory), url)); uno::Reference<io::XInputStream> const xInputStream(xZipNames->getByName(rStreamName), uno::UNO_QUERY); - std::shared_ptr<SvStream> const pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); return pStream; } xmlDocPtr parseExport(utl::TempFile const & rTempFile, OUString const& rStreamName) { - std::shared_ptr<SvStream> const pStream(parseExportStream(rTempFile, rStreamName)); + std::unique_ptr<SvStream> const pStream(parseExportStream(rTempFile, rStreamName)); xmlDocPtr const pXmlDoc = parseXmlStream(pStream.get()); OUString const url(rTempFile.GetURL()); pXmlDoc->name = reinterpret_cast<char *>(xmlStrdup( diff --git a/sd/source/ui/dlg/sddlgfact.cxx b/sd/source/ui/dlg/sddlgfact.cxx index 117064161ec5..8db686217c86 100644 --- a/sd/source/ui/dlg/sddlgfact.cxx +++ b/sd/source/ui/dlg/sddlgfact.cxx @@ -638,12 +638,12 @@ VclPtr<AbstractSdCustomShowDlg> SdAbstractDialogFactory_Impl::CreateSdCustomShow VclPtr<SfxAbstractTabDialog> SdAbstractDialogFactory_Impl::CreateSdTabCharDialog(weld::Window* pParent, const SfxItemSet* pAttr, SfxObjectShell* pDocShell) { - return VclPtr<SdAbstractTabController_Impl>::Create(std::make_unique<SdCharDlg>(pParent, pAttr, pDocShell)); + return VclPtr<SdAbstractTabController_Impl>::Create(std::make_shared<SdCharDlg>(pParent, pAttr, pDocShell)); } VclPtr<SfxAbstractTabDialog> SdAbstractDialogFactory_Impl::CreateSdTabPageDialog(weld::Window* pParent, const SfxItemSet* pAttr, SfxObjectShell* pDocShell, bool bAreaPage, bool bIsImpressDoc ) { - return VclPtr<SdAbstractTabController_Impl>::Create(std::make_unique<SdPageDlg>(pDocShell, pParent, pAttr, bAreaPage, bIsImpressDoc)); + return VclPtr<SdAbstractTabController_Impl>::Create(std::make_shared<SdPageDlg>(pDocShell, pParent, pAttr, bAreaPage, bIsImpressDoc)); } VclPtr<AbstractSdModifyFieldDlg> SdAbstractDialogFactory_Impl::CreateSdModifyFieldDlg(weld::Window* pParent, const SvxFieldData* pInField, const SfxItemSet& rSet) @@ -673,12 +673,12 @@ VclPtr<AbstractMorphDlg> SdAbstractDialogFactory_Impl::CreateMorphDlg(weld::Wind VclPtr<SfxAbstractTabDialog> SdAbstractDialogFactory_Impl::CreateSdOutlineBulletTabDlg(weld::Window* pParent, const SfxItemSet* pAttr, ::sd::View* pView) { - return VclPtr<AbstractBulletDialog_Impl>::Create(std::make_unique<::sd::OutlineBulletDlg>(pParent, pAttr, pView)); + return VclPtr<AbstractBulletDialog_Impl>::Create(std::make_shared<::sd::OutlineBulletDlg>(pParent, pAttr, pView)); } VclPtr<SfxAbstractTabDialog> SdAbstractDialogFactory_Impl::CreateSdParagraphTabDlg(weld::Window* pParent, const SfxItemSet* pAttr ) { - return VclPtr<SdAbstractTabController_Impl>::Create(std::make_unique<SdParagraphDlg>(pParent, pAttr)); + return VclPtr<SdAbstractTabController_Impl>::Create(std::make_shared<SdParagraphDlg>(pParent, pAttr)); } VclPtr<AbstractSdStartPresDlg> SdAbstractDialogFactory_Impl::CreateSdStartPresentationDlg(weld::Window* pParent, @@ -694,7 +694,7 @@ VclPtr<VclAbstractDialog> SdAbstractDialogFactory_Impl::CreateRemoteDialog(weld: VclPtr<SfxAbstractTabDialog> SdAbstractDialogFactory_Impl::CreateSdPresLayoutTemplateDlg(SfxObjectShell* pDocSh, weld::Window* pParent, bool bBackgroundDlg, SfxStyleSheetBase& rStyleBase, PresentationObjects ePO, SfxStyleSheetBasePool* pSSPool) { - return VclPtr<SdPresLayoutTemplateDlg_Impl>::Create(std::make_unique<SdPresLayoutTemplateDlg>(pDocSh, pParent, bBackgroundDlg, rStyleBase, ePO, pSSPool)); + return VclPtr<SdPresLayoutTemplateDlg_Impl>::Create(std::make_shared<SdPresLayoutTemplateDlg>(pDocSh, pParent, bBackgroundDlg, rStyleBase, ePO, pSSPool)); } VclPtr<AbstractSdPresLayoutDlg> SdAbstractDialogFactory_Impl::CreateSdPresLayoutDlg(weld::Window* pParent, ::sd::DrawDocShell* pDocShell, const SfxItemSet& rInAttrs) @@ -704,7 +704,7 @@ VclPtr<AbstractSdPresLayoutDlg> SdAbstractDialogFactory_Impl::CreateSdPresLayout VclPtr<SfxAbstractTabDialog> SdAbstractDialogFactory_Impl::CreateSdTabTemplateDlg(weld::Window* pParent, const SfxObjectShell* pDocShell, SfxStyleSheetBase& rStyleBase, SdrModel* pModel, SdrView* pView) { - return VclPtr<SdAbstractTabController_Impl>::Create(std::make_unique<SdTabTemplateDlg>(pParent, pDocShell, rStyleBase, pModel, pView)); + return VclPtr<SdAbstractTabController_Impl>::Create(std::make_shared<SdTabTemplateDlg>(pParent, pDocShell, rStyleBase, pModel, pView)); } VclPtr<SfxAbstractDialog> SdAbstractDialogFactory_Impl::CreatSdActionDialog(weld::Window* pParent, const SfxItemSet* pAttr, ::sd::View* pView ) @@ -751,7 +751,7 @@ VclPtr<VclAbstractDialog> SdAbstractDialogFactory_Impl::CreateMasterLayoutDialog VclPtr<AbstractHeaderFooterDialog> SdAbstractDialogFactory_Impl::CreateHeaderFooterDialog(sd::ViewShell* pViewShell, weld::Window* pParent, SdDrawDocument* pDoc, SdPage* pCurrentPage) { - return VclPtr<AbstractHeaderFooterDialog_Impl>::Create(std::make_unique<::sd::HeaderFooterDialog>(pViewShell, pParent, pDoc, pCurrentPage)); + return VclPtr<AbstractHeaderFooterDialog_Impl>::Create(std::make_shared<::sd::HeaderFooterDialog>(pViewShell, pParent, pDoc, pCurrentPage)); } VclPtr<VclAbstractDialog> SdAbstractDialogFactory_Impl::CreateSdPhotoAlbumDialog(weld::Window* pParent, SdDrawDocument* pDoc) diff --git a/sd/source/ui/dlg/sddlgfact.hxx b/sd/source/ui/dlg/sddlgfact.hxx index 257a1614dc6d..75071a54f07a 100644 --- a/sd/source/ui/dlg/sddlgfact.hxx +++ b/sd/source/ui/dlg/sddlgfact.hxx @@ -146,7 +146,7 @@ class SdAbstractTabController_Impl : public SfxAbstractTabDialog { std::shared_ptr<SfxTabDialogController> m_xDlg; public: - explicit SdAbstractTabController_Impl(std::unique_ptr<SfxTabDialogController> p) + explicit SdAbstractTabController_Impl(std::shared_ptr<SfxTabDialogController> p) : m_xDlg(std::move(p)) { } @@ -167,7 +167,7 @@ class AbstractBulletDialog_Impl : public SfxAbstractTabDialog { std::shared_ptr<SfxTabDialogController> m_xDlg; public: - explicit AbstractBulletDialog_Impl(std::unique_ptr<SfxTabDialogController> p) + explicit AbstractBulletDialog_Impl(std::shared_ptr<SfxTabDialogController> p) : m_xDlg(std::move(p)) { } @@ -188,7 +188,7 @@ class SdPresLayoutTemplateDlg_Impl : public SfxAbstractTabDialog { std::shared_ptr<SdPresLayoutTemplateDlg> m_xDlg; public: - explicit SdPresLayoutTemplateDlg_Impl(std::unique_ptr<SdPresLayoutTemplateDlg> p) + explicit SdPresLayoutTemplateDlg_Impl(std::shared_ptr<SdPresLayoutTemplateDlg> p) : m_xDlg(std::move(p)) { } @@ -388,7 +388,7 @@ class AbstractHeaderFooterDialog_Impl :public AbstractHeaderFooterDialog private: std::shared_ptr<::sd::HeaderFooterDialog> m_xDlg; public: - AbstractHeaderFooterDialog_Impl(std::unique_ptr<::sd::HeaderFooterDialog> pDlg) + AbstractHeaderFooterDialog_Impl(std::shared_ptr<::sd::HeaderFooterDialog> pDlg) : m_xDlg(std::move(pDlg)) { } diff --git a/sd/source/ui/slidesorter/cache/SlsBitmapCompressor.cxx b/sd/source/ui/slidesorter/cache/SlsBitmapCompressor.cxx index da5a440dd882..04b99dbf6c15 100644 --- a/sd/source/ui/slidesorter/cache/SlsBitmapCompressor.cxx +++ b/sd/source/ui/slidesorter/cache/SlsBitmapCompressor.cxx @@ -102,7 +102,7 @@ sal_Int32 ResolutionReduction::ResolutionReducedReplacement::GetMemorySize() con std::shared_ptr<BitmapReplacement> ResolutionReduction::Compress ( const BitmapEx& rBitmap) const { - ResolutionReducedReplacement* pResult = new ResolutionReducedReplacement; + auto pResult = std::make_shared<ResolutionReducedReplacement>(); pResult->maPreview = rBitmap; Size aSize (rBitmap.GetSizePixel()); pResult->maOriginalSize = aSize; @@ -112,7 +112,7 @@ std::shared_ptr<BitmapReplacement> ResolutionReduction::Compress ( pResult->maPreview.Scale(Size(mnWidth,nHeight)); } - return std::shared_ptr<BitmapReplacement>(pResult); + return pResult; } BitmapEx ResolutionReduction::Decompress (const BitmapReplacement& rBitmapData) const @@ -164,12 +164,12 @@ std::shared_ptr<BitmapReplacement> PngCompression::Compress (const BitmapEx& rBi SvMemoryStream aStream (32768, 32768); aWriter.Write(aStream); - PngReplacement* pResult = new PngReplacement(); + auto pResult = std::make_shared<PngReplacement>(); pResult->mnDataSize = aStream.Tell(); pResult->mpData = new char[pResult->mnDataSize]; memcpy(pResult->mpData, aStream.GetData(), pResult->mnDataSize); - return std::shared_ptr<BitmapReplacement>(pResult); + return pResult; } BitmapEx PngCompression::Decompress ( diff --git a/sfx2/qa/cppunit/test_misc.cxx b/sfx2/qa/cppunit/test_misc.cxx index 587cec0047fe..f616b3e8cea2 100644 --- a/sfx2/qa/cppunit/test_misc.cxx +++ b/sfx2/qa/cppunit/test_misc.cxx @@ -87,7 +87,7 @@ CPPUNIT_TEST_FIXTURE(MiscTest, testODFCustomMetadata) uno::Reference<packages::zip::XZipFileAccess2> const xZip( packages::zip::ZipFileAccess::createWithURL(m_xContext, aTempFile.GetURL())); uno::Reference<io::XInputStream> const xInputStream(xZip->getByName("meta.xml"), uno::UNO_QUERY); - std::shared_ptr<SvStream> const pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + std::unique_ptr<SvStream> const pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); xmlDocPtr pXmlDoc = parseXmlStream(pStream.get()); assertXPathContent(pXmlDoc, "/office:document-meta/office:meta/bork", "bork"); assertXPath(pXmlDoc, "/office:document-meta/office:meta/foo:bar", 1); diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 67e642171f06..ff64c1491382 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -2481,7 +2481,7 @@ bool SfxObjectShell::DoSave_Impl( const SfxItemSet* pArgs ) // copy the original itemset, but remove the "version" item, because pMediumTmp // is a new medium "from scratch", so no version should be stored into it - std::unique_ptr<SfxItemSet> pSet(new SfxAllItemSet(*pRetrMedium->GetItemSet())); + std::shared_ptr<SfxItemSet> pSet = std::make_shared<SfxAllItemSet>(*pRetrMedium->GetItemSet()); pSet->ClearItem( SID_VERSION ); pSet->ClearItem( SID_DOC_BASEURL ); @@ -2745,52 +2745,51 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString& const uno::Sequence<beans::PropertyValue>& rArgs) { // copy all items stored in the itemset of the current medium - std::unique_ptr<SfxAllItemSet> pMergedParams(new SfxAllItemSet( *pMedium->GetItemSet() )); + std::shared_ptr<SfxAllItemSet> xMergedParams = std::make_shared<SfxAllItemSet>( *pMedium->GetItemSet() ); // in "SaveAs" title and password will be cleared ( maybe the new itemset contains new values, otherwise they will be empty ) // #i119366# - As the SID_ENCRYPTIONDATA and SID_PASSWORD are using for setting password together, we need to clear them both. // Also, ( maybe the new itemset contains new values, otherwise they will be empty ) - if (pMergedParams->HasItem( SID_PASSWORD )) + if (xMergedParams->HasItem( SID_PASSWORD )) { - pMergedParams->ClearItem( SID_PASSWORD ); - pMergedParams->ClearItem( SID_ENCRYPTIONDATA ); + xMergedParams->ClearItem( SID_PASSWORD ); + xMergedParams->ClearItem( SID_ENCRYPTIONDATA ); } - pMergedParams->ClearItem( SID_DOCINFO_TITLE ); + xMergedParams->ClearItem( SID_DOCINFO_TITLE ); - pMergedParams->ClearItem( SID_INPUTSTREAM ); - pMergedParams->ClearItem( SID_STREAM ); - pMergedParams->ClearItem( SID_CONTENT ); - pMergedParams->ClearItem( SID_DOC_READONLY ); - pMergedParams->ClearItem( SID_DOC_BASEURL ); + xMergedParams->ClearItem( SID_INPUTSTREAM ); + xMergedParams->ClearItem( SID_STREAM ); + xMergedParams->ClearItem( SID_CONTENT ); + xMergedParams->ClearItem( SID_DOC_READONLY ); + xMergedParams->ClearItem( SID_DOC_BASEURL ); - pMergedParams->ClearItem( SID_REPAIRPACKAGE ); + xMergedParams->ClearItem( SID_REPAIRPACKAGE ); // "SaveAs" will never store any version information - it's a complete new file ! - pMergedParams->ClearItem( SID_VERSION ); + xMergedParams->ClearItem( SID_VERSION ); // merge the new parameters into the copy // all values present in both itemsets will be overwritten by the new parameters - pMergedParams->Put(rItemSet); + xMergedParams->Put(rItemSet); - SAL_WARN_IF( pMergedParams->GetItemState( SID_DOC_SALVAGE) >= SfxItemState::SET, + SAL_WARN_IF( xMergedParams->GetItemState( SID_DOC_SALVAGE) >= SfxItemState::SET, "sfx.doc","Salvage item present in Itemset, check the parameters!"); // should be unnecessary - too hot to handle! - pMergedParams->ClearItem( SID_DOC_SALVAGE ); + xMergedParams->ClearItem( SID_DOC_SALVAGE ); // create a medium for the target URL - auto pMergedParamsTmp = pMergedParams.get(); - SfxMedium *pNewFile = new SfxMedium( rFileName, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC, nullptr, std::move(pMergedParams) ); + SfxMedium *pNewFile = new SfxMedium( rFileName, StreamMode::READWRITE | StreamMode::SHARE_DENYWRITE | StreamMode::TRUNC, nullptr, xMergedParams ); pNewFile->SetArgs(rArgs); - const SfxBoolItem* pNoFileSync = pMergedParamsTmp->GetItem<SfxBoolItem>(SID_NO_FILE_SYNC, false); + const SfxBoolItem* pNoFileSync = xMergedParams->GetItem<SfxBoolItem>(SID_NO_FILE_SYNC, false); if (pNoFileSync && pNoFileSync->GetValue()) pNewFile->DisableFileSync(true); bool bUseThumbnailSave = IsUseThumbnailSave(); comphelper::ScopeGuard aThumbnailGuard( [this, bUseThumbnailSave] { this->SetUseThumbnailSave(bUseThumbnailSave); }); - const SfxBoolItem* pNoThumbnail = pMergedParamsTmp->GetItem<SfxBoolItem>(SID_NO_THUMBNAIL, false); + const SfxBoolItem* pNoThumbnail = xMergedParams->GetItem<SfxBoolItem>(SID_NO_THUMBNAIL, false); if (pNoThumbnail) // Thumbnail generation should be avoided just for this save. SetUseThumbnailSave(!pNoThumbnail->GetValue()); @@ -2818,7 +2817,7 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString& } // check if a "SaveTo" is wanted, no "SaveAs" - const SfxBoolItem* pSaveToItem = pMergedParamsTmp->GetItem<SfxBoolItem>(SID_SAVETO, false); + const SfxBoolItem* pSaveToItem = xMergedParams->GetItem<SfxBoolItem>(SID_SAVETO, false); bool bCopyTo = GetCreateMode() == SfxObjectCreateMode::EMBEDDED || (pSaveToItem && pSaveToItem->GetValue()); // distinguish between "Save" and "SaveAs" diff --git a/sfx2/source/doc/oleprops.cxx b/sfx2/source/doc/oleprops.cxx index 14b6e4863ad6..c3baa5d21151 100644 --- a/sfx2/source/doc/oleprops.cxx +++ b/sfx2/source/doc/oleprops.cxx @@ -845,20 +845,17 @@ void SfxOleSection::SetDateValue( sal_Int32 nPropId, const util::Date& rValue ) void SfxOleSection::SetThumbnailValue( sal_Int32 nPropId, const uno::Sequence<sal_Int8> & i_rData) { - SfxOleThumbnailProperty* pThumbnail = new SfxOleThumbnailProperty( nPropId, i_rData ); - SfxOlePropertyRef xProp( pThumbnail ); // take ownership + auto pThumbnail = std::make_shared<SfxOleThumbnailProperty>( nPropId, i_rData ); if( pThumbnail->IsValid() ) - SetProperty( xProp ); + SetProperty( pThumbnail ); } void SfxOleSection::SetBlobValue( sal_Int32 nPropId, const uno::Sequence<sal_Int8> & i_rData) { - SfxOleBlobProperty* pBlob( new SfxOleBlobProperty( nPropId, i_rData ) ); - SfxOlePropertyRef xProp( pBlob ); - if( pBlob->IsValid() ) { - SetProperty( xProp ); - } + auto pBlob = std::make_shared<SfxOleBlobProperty>( nPropId, i_rData ); + if( pBlob->IsValid() ) + SetProperty( pBlob ); } Any SfxOleSection::GetAnyValue( sal_Int32 nPropId ) const diff --git a/svx/source/dialog/imapwnd.cxx b/svx/source/dialog/imapwnd.cxx index 3c6270df9086..bd95ca8237f3 100644 --- a/svx/source/dialog/imapwnd.cxx +++ b/svx/source/dialog/imapwnd.cxx @@ -306,9 +306,9 @@ void IMapWindow::SdrObjCreated( const SdrObject& rObj ) case OBJ_RECT: { SdrRectObj* pRectObj = const_cast<SdrRectObj*>(static_cast<const SdrRectObj*>(&rObj)); - IMapRectangleObject* pObj = new IMapRectangleObject( pRectObj->GetLogicRect(), "", "", "", "", "", true, false ); + auto pObj = std::make_shared<IMapRectangleObject>( pRectObj->GetLogicRect(), "", "", "", "", "", true, false ); - pRectObj->AppendUserData( std::unique_ptr<SdrObjUserData>(new IMapUserData( IMapObjectPtr(pObj) )) ); + pRectObj->AppendUserData( std::unique_ptr<SdrObjUserData>(new IMapUserData( pObj )) ); } break; @@ -322,9 +322,9 @@ void IMapWindow::SdrObjCreated( const SdrObject& rObj ) SdrObject* pTemp(pPathObj); SdrObject::Free(pTemp); - IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, "", "", "", "", "", true, false ); + auto pObj = std::make_shared<IMapPolygonObject>( aPoly, "", "", "", "", "", true, false ); pObj->SetExtraEllipse( aPoly.GetBoundRect() ); - pCircObj->AppendUserData( std::unique_ptr<SdrObjUserData>(new IMapUserData( IMapObjectPtr(pObj) )) ); + pCircObj->AppendUserData( std::unique_ptr<SdrObjUserData>(new IMapUserData( pObj )) ); } break; @@ -339,8 +339,8 @@ void IMapWindow::SdrObjCreated( const SdrObject& rObj ) if ( rXPolyPoly.count() ) { tools::Polygon aPoly(rXPolyPoly.getB2DPolygon(0)); - IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, "", "", "", "", "", true, false ); - pPathObj->AppendUserData( std::unique_ptr<SdrObjUserData>(new IMapUserData( IMapObjectPtr(pObj) )) ); + auto pObj = std::make_shared<IMapPolygonObject>( aPoly, "", "", "", "", "", true, false ); + pPathObj->AppendUserData( std::unique_ptr<SdrObjUserData>(new IMapUserData( pObj )) ); } } break; @@ -387,7 +387,7 @@ void IMapWindow::SdrObjChanged( const SdrObject& rObj ) SdrPathObj* pPathObj = static_cast<SdrPathObj*>( rCircObj.ConvertToPolyObj( false, false ).release() ); tools::Polygon aPoly(pPathObj->GetPathPoly().getB2DPolygon(0)); - IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, "", bActive, false ); + auto pObj = std::make_shared<IMapPolygonObject>( aPoly, aURL, aAltText, aDesc, aTarget, "", bActive, false ); pObj->SetExtraEllipse( aPoly.GetBoundRect() ); // was only created by us temporarily @@ -395,7 +395,7 @@ void IMapWindow::SdrObjChanged( const SdrObject& rObj ) SdrObject* pTemp(pPathObj); SdrObject::Free(pTemp); - pUserData->ReplaceObject( IMapObjectPtr(pObj) ); + pUserData->ReplaceObject( pObj ); } break; @@ -410,8 +410,8 @@ void IMapWindow::SdrObjChanged( const SdrObject& rObj ) if ( rXPolyPoly.count() ) { tools::Polygon aPoly(rPathObj.GetPathPoly().getB2DPolygon(0)); - IMapPolygonObject* pObj = new IMapPolygonObject( aPoly, aURL, aAltText, aDesc, aTarget, "", bActive, false ); - pUserData->ReplaceObject( IMapObjectPtr(pObj) ); + auto pObj = std::make_shared<IMapPolygonObject>( aPoly, aURL, aAltText, aDesc, aTarget, "", bActive, false ); + pUserData->ReplaceObject( pObj ); } } break; diff --git a/svx/source/form/formcontroller.cxx b/svx/source/form/formcontroller.cxx index f32789ceafd6..be6e956cc478 100644 --- a/svx/source/form/formcontroller.cxx +++ b/svx/source/form/formcontroller.cxx @@ -797,7 +797,7 @@ void FormController::getFastPropertyValue( Any& rValue, sal_Int32 nHandle ) cons OUString sFilterValue( condition->second ); OUString sErrorMsg, sCriteria; - const std::shared_ptr< OSQLParseNode > pParseNode = + const std::unique_ptr< OSQLParseNode > pParseNode = predicateTree( sErrorMsg, sFilterValue, xFormatter, xField ); OSL_ENSURE( pParseNode != nullptr, "FormController::getFastPropertyValue: could not parse the field value predicate!" ); if ( pParseNode != nullptr ) @@ -3112,7 +3112,7 @@ void FormController::setFilter(::std::vector<FmFieldInfo>& rFieldInfos) { OUString sPredicate,sErrorMsg; rRefValue.Value >>= sPredicate; - std::shared_ptr< OSQLParseNode > pParseNode = predicateTree(sErrorMsg, sPredicate, xFormatter, xField); + std::unique_ptr< OSQLParseNode > pParseNode = predicateTree(sErrorMsg, sPredicate, xFormatter, xField); if ( pParseNode != nullptr ) { OUString sCriteria; diff --git a/svx/source/sidebar/nbdtmg.cxx b/svx/source/sidebar/nbdtmg.cxx index e89f48a9bf6a..627da9eaee8e 100644 --- a/svx/source/sidebar/nbdtmg.cxx +++ b/svx/source/sidebar/nbdtmg.cxx @@ -425,11 +425,11 @@ void NumberingTypeMgr::Init() for(sal_Int32 i = 0; i < nLength; i++) { NumSettings_Impl* pNew = lcl_CreateNumberingSettingsPtr(pValuesArr[i]); - NumberSettings_Impl* pNumEntry = new NumberSettings_Impl; + std::shared_ptr<NumberSettings_Impl> pNumEntry = std::make_shared<NumberSettings_Impl>(); pNumEntry->pNumSetting = pNew; if ( i < 8 ) pNumEntry->sDescription = SvxResId(RID_SVXSTR_SINGLENUM_DESCRIPTIONS[i]); - maNumberSettingsArr.push_back(std::shared_ptr<NumberSettings_Impl>(pNumEntry)); + maNumberSettingsArr.push_back(pNumEntry); } } catch(Exception&) diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 1ccff383fba9..64bd15d76a04 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -809,7 +809,7 @@ private: css::uno::Reference<css::task::XStatusIndicator> const& m_xStatusIndicator; css::uno::Reference<css::lang::XMultiServiceFactory> m_xModelFactory; css::uno::Reference<css::document::XDocumentProperties> m_xDocumentProperties; - std::shared_ptr<SvStream> m_pInStream; + std::unique_ptr<SvStream> m_pInStream; Stream* m_pMapperStream; tools::SvRef<RTFSdrImport> m_pSdrImport; tools::SvRef<RTFTokenizer> m_pTokenizer; diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx index c6518433de0e..cf50d2d9da52 100644 --- a/writerperfect/qa/unit/EPUBExportTest.cxx +++ b/writerperfect/qa/unit/EPUBExportTest.cxx @@ -111,7 +111,7 @@ void EPUBExportTest::createDoc(const OUString& rFile, xmlDocPtr EPUBExportTest::parseExport(const OUString& rName) { uno::Reference<io::XInputStream> xInputStream(mxZipFile->getByName(rName), uno::UNO_QUERY); - std::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); return parseXmlStream(pStream.get()); } @@ -120,7 +120,7 @@ std::map<OUString, std::vector<OUString>> EPUBExportTest::parseCss(const OUStrin std::map<OUString, std::vector<OUString>> aRet; uno::Reference<io::XInputStream> xInputStream(mxZipFile->getByName(rName), uno::UNO_QUERY); - std::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); // Minimal CSS handler till orcus is up to our needs. OString aLine; @@ -797,7 +797,7 @@ CPPUNIT_TEST_FIXTURE(EPUBExportTest, testSVG) CPPUNIT_ASSERT(mxZipFile->hasByName("OEBPS/images/image0001.svg")); uno::Reference<io::XInputStream> xInputStream( mxZipFile->getByName("OEBPS/images/image0001.svg"), uno::UNO_QUERY); - std::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); SvMemoryStream aMemoryStream; aMemoryStream.WriteStream(*pStream); diff --git a/writerperfect/qa/unit/WPXSvStreamTest.cxx b/writerperfect/qa/unit/WPXSvStreamTest.cxx index 368a8223368e..e9680510b43a 100644 --- a/writerperfect/qa/unit/WPXSvStreamTest.cxx +++ b/writerperfect/qa/unit/WPXSvStreamTest.cxx @@ -31,6 +31,7 @@ namespace ucb = com::sun::star::ucb; namespace uno = com::sun::star::uno; using std::shared_ptr; +using std::unique_ptr; using librevenge::RVNGInputStream; using librevenge::RVNG_SEEK_CUR; @@ -303,7 +304,7 @@ void WPXSvStreamTest::testStructured() // check for existing substream CPPUNIT_ASSERT(pInput->existsSubStream("WordDocument")); - shared_ptr<RVNGInputStream> pSubStream(pInput->getSubStreamByName("WordDocument")); + unique_ptr<RVNGInputStream> pSubStream(pInput->getSubStreamByName("WordDocument")); CPPUNIT_ASSERT(bool(pSubStream)); CPPUNIT_ASSERT(!pSubStream->isEnd()); @@ -325,7 +326,7 @@ void WPXSvStreamTest::testStructured() // check for existing substream CPPUNIT_ASSERT(pInput->existsSubStream("content.xml")); - shared_ptr<RVNGInputStream> pSubStream(pInput->getSubStreamByName("content.xml")); + unique_ptr<RVNGInputStream> pSubStream(pInput->getSubStreamByName("content.xml")); CPPUNIT_ASSERT(bool(pSubStream)); CPPUNIT_ASSERT(!pSubStream->isEnd()); diff --git a/writerperfect/source/impress/KeynoteImportFilter.cxx b/writerperfect/source/impress/KeynoteImportFilter.cxx index 1e69e85dc883..c212c5ab85d0 100644 --- a/writerperfect/source/impress/KeynoteImportFilter.cxx +++ b/writerperfect/source/impress/KeynoteImportFilter.cxx @@ -97,8 +97,8 @@ KeynoteImportFilter::detect(css::uno::Sequence<css::beans::PropertyValue>& Descr if (!xInputStream.is()) return OUString(); - std::shared_ptr<librevenge::RVNGInputStream> input - = std::make_shared<WPXSvInputStream>(xInputStream); + std::unique_ptr<librevenge::RVNGInputStream> input + = std::make_unique<WPXSvInputStream>(xInputStream); /* Apple Keynote documents come in two variants: * * actual files (zip), only produced by Keynote 5 (at least with @@ -121,7 +121,7 @@ KeynoteImportFilter::detect(css::uno::Sequence<css::beans::PropertyValue>& Descr { if (aContent.isFolder()) { - input = std::make_shared<writerperfect::DirectoryStream>(xContent); + input = std::make_unique<writerperfect::DirectoryStream>(xContent); bIsPackage = true; } } @@ -143,9 +143,10 @@ KeynoteImportFilter::detect(css::uno::Sequence<css::beans::PropertyValue>& Descr if (bIsPackage) // we passed a directory stream, but the filter claims it's APXL file? return OUString(); - const std::shared_ptr<writerperfect::DirectoryStream> pDir + std::unique_ptr<writerperfect::DirectoryStream> xDir = writerperfect::DirectoryStream::createForParent(xContent); - input = pDir; + auto pDir = xDir.get(); + input = std::move(xDir); if (bool(input)) { if (libetonyek::EtonyekDocument::CONFIDENCE_EXCELLENT diff --git a/xmloff/source/draw/xexptran.cxx b/xmloff/source/draw/xexptran.cxx index ca9a7a2c55fd..49e003307242 100644 --- a/xmloff/source/draw/xexptran.cxx +++ b/xmloff/source/draw/xexptran.cxx @@ -224,19 +224,19 @@ struct ImpSdXMLExpTransObj2DMatrix : public ImpSdXMLExpTransObj2DBase void SdXMLImExTransform2D::AddRotate(double fNew) { if(fNew != 0.0) - maList.push_back(make_unique<ImpSdXMLExpTransObj2DRotate>(fNew)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj2DRotate>(fNew)); } void SdXMLImExTransform2D::AddTranslate(const ::basegfx::B2DTuple& rNew) { if(!rNew.equalZero()) - maList.push_back(make_unique<ImpSdXMLExpTransObj2DTranslate>(rNew)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj2DTranslate>(rNew)); } void SdXMLImExTransform2D::AddSkewX(double fNew) { if(fNew != 0.0) - maList.push_back(make_unique<ImpSdXMLExpTransObj2DSkewX>(fNew)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj2DSkewX>(fNew)); } // gen string for export @@ -376,7 +376,7 @@ void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen); fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue); if(fValue != 0.0) - maList.push_back(make_unique<ImpSdXMLExpTransObj2DRotate>(fValue)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj2DRotate>(fValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -390,7 +390,7 @@ void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConver aValue.setY(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getY())); if(aValue.getX() != 1.0 || aValue.getY() != 1.0) - maList.push_back(make_unique<ImpSdXMLExpTransObj2DScale>(aValue)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj2DScale>(aValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -404,7 +404,7 @@ void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConver aValue.setY(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getY(), true)); if(!aValue.equalZero()) - maList.push_back(make_unique<ImpSdXMLExpTransObj2DTranslate>(aValue)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj2DTranslate>(aValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -415,7 +415,7 @@ void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen); fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue); if(fValue != 0.0) - maList.push_back(make_unique<ImpSdXMLExpTransObj2DSkewX>(fValue)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj2DSkewX>(fValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -426,7 +426,7 @@ void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen); fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue); if(fValue != 0.0) - maList.push_back(make_unique<ImpSdXMLExpTransObj2DSkewY>(fValue)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj2DSkewY>(fValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -462,7 +462,7 @@ void SdXMLImExTransform2D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndCommas(aStr, nPos, nLen); if(!aValue.isIdentity()) - maList.push_back(make_unique<ImpSdXMLExpTransObj2DMatrix>(aValue)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj2DMatrix>(aValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -604,7 +604,7 @@ struct ImpSdXMLExpTransObj3DMatrix : public ImpSdXMLExpTransObj3DBase void SdXMLImExTransform3D::AddMatrix(const ::basegfx::B3DHomMatrix& rNew) { if(!rNew.isIdentity()) - maList.push_back(make_unique<ImpSdXMLExpTransObj3DMatrix>(rNew)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj3DMatrix>(rNew)); } void SdXMLImExTransform3D::AddHomogenMatrix(const drawing::HomogenMatrix& xHomMat) @@ -784,7 +784,7 @@ void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen); fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue); if(fValue != 0.0) - maList.push_back(make_unique<ImpSdXMLExpTransObj3DRotateX>(basegfx::deg2rad(fValue))); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj3DRotateX>(basegfx::deg2rad(fValue))); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -796,7 +796,7 @@ void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen); fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue); if(fValue != 0.0) - maList.push_back(make_unique<ImpSdXMLExpTransObj3DRotateY>(basegfx::deg2rad(fValue))); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj3DRotateY>(basegfx::deg2rad(fValue))); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -808,7 +808,7 @@ void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndOpeningBraces(aStr, nPos, nLen); fValue = Imp_GetDoubleChar(aStr, nPos, nLen, rConv, fValue); if(fValue != 0.0) - maList.push_back(make_unique<ImpSdXMLExpTransObj3DRotateZ>(basegfx::deg2rad(fValue))); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj3DRotateZ>(basegfx::deg2rad(fValue))); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -825,7 +825,7 @@ void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConver aValue.setZ(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getZ())); if(1.0 != aValue.getX() || 1.0 != aValue.getY() || 1.0 != aValue.getZ()) - maList.push_back(make_unique<ImpSdXMLExpTransObj3DScale>(aValue)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj3DScale>(aValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -842,7 +842,7 @@ void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConver aValue.setZ(Imp_GetDoubleChar(aStr, nPos, nLen, rConv, aValue.getZ(), true)); if(!aValue.equalZero()) - maList.push_back(make_unique<ImpSdXMLExpTransObj3DTranslate>(aValue)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj3DTranslate>(aValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } @@ -902,7 +902,7 @@ void SdXMLImExTransform3D::SetString(const OUString& rNew, const SvXMLUnitConver Imp_SkipSpacesAndCommas(aStr, nPos, nLen); if(!aValue.isIdentity()) - maList.push_back(make_unique<ImpSdXMLExpTransObj3DMatrix>(aValue)); + maList.push_back(std::make_shared<ImpSdXMLExpTransObj3DMatrix>(aValue)); Imp_SkipSpacesAndClosingBraces(aStr, nPos, nLen); } diff --git a/xmlsecurity/qa/unit/signing/signing.cxx b/xmlsecurity/qa/unit/signing/signing.cxx index e3eae81c445e..0475ff966127 100644 --- a/xmlsecurity/qa/unit/signing/signing.cxx +++ b/xmlsecurity/qa/unit/signing/signing.cxx @@ -745,7 +745,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testXAdESNotype) uno::Reference<io::XInputStream> xInputStream( xMetaInf->openStreamElement("documentsignatures.xml", embed::ElementModes::READ), uno::UNO_QUERY); - std::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); xmlDocPtr pXmlDoc = parseXmlStream(pStream.get()); // Without the accompanying fix in place, this test would have failed with "unexpected 'Type' @@ -805,7 +805,7 @@ CPPUNIT_TEST_FIXTURE(SigningTest, testXAdES) uno::Reference<io::XInputStream> xInputStream( xMetaInf->openStreamElement("documentsignatures.xml", embed::ElementModes::READ), uno::UNO_QUERY); - std::shared_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); + std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream, true)); xmlDocPtr pXmlDoc = parseXmlStream(pStream.get()); // Assert that the digest algorithm is SHA-256 in the bAdESCompliant case, not SHA-1. |