From 0a601a0cb14dc0f60e00eb46929f53eebe59a6af Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Wed, 16 Sep 2015 12:40:14 +0200 Subject: sw: replace boost::ptr_vector with std::vector Change-Id: I3bfb0933d5233b89f24773500f07fdc92d0011e9 --- sw/inc/ToxLinkProcessor.hxx | 7 ++++--- sw/qa/core/test_ToxLinkProcessor.cxx | 24 ++++++++++++------------ sw/source/core/tox/ToxLinkProcessor.cxx | 25 ++++++++++++++----------- 3 files changed, 30 insertions(+), 26 deletions(-) diff --git a/sw/inc/ToxLinkProcessor.hxx b/sw/inc/ToxLinkProcessor.hxx index 3887121e06dc..699c0ec9887e 100644 --- a/sw/inc/ToxLinkProcessor.hxx +++ b/sw/inc/ToxLinkProcessor.hxx @@ -13,7 +13,8 @@ #include "fmtinfmt.hxx" #include "rtl/ustring.hxx" -#include +#include +#include class SwTextNode; @@ -76,9 +77,9 @@ private: sal_Int32 mEndTextPos; }; - boost::ptr_vector mClosedLinks; + std::vector> m_ClosedLinks; - boost::ptr_vector mStartedLinks; + std::vector> m_StartedLinks; friend class ::ToxLinkProcessorTest; }; diff --git a/sw/qa/core/test_ToxLinkProcessor.cxx b/sw/qa/core/test_ToxLinkProcessor.cxx index 660d7458a7f1..03c85505b027 100644 --- a/sw/qa/core/test_ToxLinkProcessor.cxx +++ b/sw/qa/core/test_ToxLinkProcessor.cxx @@ -81,8 +81,8 @@ ToxLinkProcessorTest::StandardOpenLinkIsAddedWhenMoreLinksThanAvaiableAreClosed( sut.StartNewLink(0, STYLE_NAME_1); sut.CloseLink(1, URL_1); sut.CloseLink(1, URL_1); - CPPUNIT_ASSERT_EQUAL(2u, static_cast(sut.mClosedLinks.size())); - CPPUNIT_ASSERT_EQUAL(0u, static_cast(sut.mClosedLinks.at(1).mEndTextPos)); + CPPUNIT_ASSERT_EQUAL(2u, static_cast(sut.m_ClosedLinks.size())); + CPPUNIT_ASSERT_EQUAL(0u, static_cast(sut.m_ClosedLinks.at(1)->mEndTextPos)); } void @@ -93,8 +93,8 @@ ToxLinkProcessorTest::AddingAndClosingTwoLinksResultsInTwoClosedLinks() sut.StartNewLink(0, STYLE_NAME_2); sut.CloseLink(1, URL_1); sut.CloseLink(1, URL_2); - CPPUNIT_ASSERT_EQUAL(2u, static_cast(sut.mClosedLinks.size())); - CPPUNIT_ASSERT_MESSAGE("no links are open", sut.mStartedLinks.empty()); + CPPUNIT_ASSERT_EQUAL(2u, static_cast(sut.m_ClosedLinks.size())); + CPPUNIT_ASSERT_MESSAGE("no links are open", sut.m_StartedLinks.empty()); } class ToxLinkProcessorWithOverriddenObtainPoolId : public ToxLinkProcessor { @@ -120,8 +120,8 @@ ToxLinkProcessorTest::LinkIsCreatedCorrectly() sut.StartNewLink(0, STYLE_NAME_1); sut.CloseLink(1, URL_1); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link", STYLE_NAME_1, sut.mClosedLinks.at(0).mINetFormat.GetVisitedFormat()); - CPPUNIT_ASSERT_EQUAL_MESSAGE("Url is stored correctly in link", URL_1, sut.mClosedLinks.at(0).mINetFormat.GetValue()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link", STYLE_NAME_1, sut.m_ClosedLinks.at(0)->mINetFormat.GetVisitedFormat()); + CPPUNIT_ASSERT_EQUAL_MESSAGE("Url is stored correctly in link", URL_1, sut.m_ClosedLinks.at(0)->mINetFormat.GetValue()); } void @@ -138,18 +138,18 @@ ToxLinkProcessorTest::LinkSequenceIsPreserved() // check first closed element CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link", - STYLE_NAME_2, sut.mClosedLinks.at(0).mINetFormat.GetVisitedFormat()); + STYLE_NAME_2, sut.m_ClosedLinks.at(0)->mINetFormat.GetVisitedFormat()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Pool id is stored correctly in link", - POOL_ID_2, sut.mClosedLinks.at(0).mINetFormat.GetINetFormatId()); + POOL_ID_2, sut.m_ClosedLinks.at(0)->mINetFormat.GetINetFormatId()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Url is stored correctly in link", - URL_2, sut.mClosedLinks.at(0).mINetFormat.GetValue()); + URL_2, sut.m_ClosedLinks.at(0)->mINetFormat.GetValue()); // check second closed element CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link", - STYLE_NAME_1, sut.mClosedLinks.at(1).mINetFormat.GetVisitedFormat()); + STYLE_NAME_1, sut.m_ClosedLinks.at(1)->mINetFormat.GetVisitedFormat()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Pool id is stored correctly in link", - POOL_ID_1, sut.mClosedLinks.at(1).mINetFormat.GetINetFormatId()); + POOL_ID_1, sut.m_ClosedLinks.at(1)->mINetFormat.GetINetFormatId()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Url is stored correctly in link", - URL_1, sut.mClosedLinks.at(1).mINetFormat.GetValue()); + URL_1, sut.m_ClosedLinks.at(1)->mINetFormat.GetValue()); } // Put the test suite in the registry diff --git a/sw/source/core/tox/ToxLinkProcessor.cxx b/sw/source/core/tox/ToxLinkProcessor.cxx index bd2d6f8937e7..cbb7275ca42f 100644 --- a/sw/source/core/tox/ToxLinkProcessor.cxx +++ b/sw/source/core/tox/ToxLinkProcessor.cxx @@ -20,32 +20,34 @@ namespace sw { void ToxLinkProcessor::StartNewLink(sal_Int32 startPosition, const OUString& characterStyle) { - mStartedLinks.push_back(new StartedLink(startPosition, characterStyle)); + m_StartedLinks.push_back(std::unique_ptr( + new StartedLink(startPosition, characterStyle))); } void ToxLinkProcessor::CloseLink(sal_Int32 endPosition, const OUString& url) { - StartedLink const startedLink( (mStartedLinks.empty()) + StartedLink const startedLink( (m_StartedLinks.empty()) ? StartedLink(0, SW_RES(STR_POOLCHR_TOXJUMP)) - : mStartedLinks.back() ); - if (!mStartedLinks.empty()) + : *m_StartedLinks.back() ); + if (!m_StartedLinks.empty()) { - mStartedLinks.pop_back(); + m_StartedLinks.pop_back(); } if (url.isEmpty()) { return; } - ClosedLink* closedLink = new ClosedLink(url, startedLink.mStartPosition, endPosition); + std::unique_ptr pClosedLink( + new ClosedLink(url, startedLink.mStartPosition, endPosition)); const OUString& characterStyle = startedLink.mCharacterStyle; sal_uInt16 poolId = ObtainPoolId(characterStyle); - closedLink->mINetFormat.SetVisitedFormatAndId(characterStyle, poolId); - closedLink->mINetFormat.SetINetFormatAndId(characterStyle, poolId); + pClosedLink->mINetFormat.SetVisitedFormatAndId(characterStyle, poolId); + pClosedLink->mINetFormat.SetINetFormatAndId(characterStyle, poolId); - mClosedLinks.push_back(closedLink); + m_ClosedLinks.push_back(std::move(pClosedLink)); } sal_uInt16 @@ -63,8 +65,9 @@ ToxLinkProcessor::ObtainPoolId(const OUString& characterStyle) const void ToxLinkProcessor::InsertLinkAttributes(SwTextNode& node) { - for (ClosedLink& clink : mClosedLinks) { - node.InsertItem(clink.mINetFormat, clink.mStartTextPos, clink.mEndTextPos); + for (auto const& clink : m_ClosedLinks) + { + node.InsertItem(clink->mINetFormat, clink->mStartTextPos, clink->mEndTextPos); } } -- cgit