Kaydet (Commit) 0a601a0c authored tarafından Michael Stahl's avatar Michael Stahl

sw: replace boost::ptr_vector with std::vector<std::unique_ptr>

Change-Id: I3bfb0933d5233b89f24773500f07fdc92d0011e9
üst 529f5441
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
#include "fmtinfmt.hxx" #include "fmtinfmt.hxx"
#include "rtl/ustring.hxx" #include "rtl/ustring.hxx"
#include <boost/ptr_container/ptr_vector.hpp> #include <memory>
#include <vector>
class SwTextNode; class SwTextNode;
...@@ -76,9 +77,9 @@ private: ...@@ -76,9 +77,9 @@ private:
sal_Int32 mEndTextPos; sal_Int32 mEndTextPos;
}; };
boost::ptr_vector<ClosedLink> mClosedLinks; std::vector<std::unique_ptr<ClosedLink>> m_ClosedLinks;
boost::ptr_vector<StartedLink> mStartedLinks; std::vector<std::unique_ptr<StartedLink>> m_StartedLinks;
friend class ::ToxLinkProcessorTest; friend class ::ToxLinkProcessorTest;
}; };
......
...@@ -81,8 +81,8 @@ ToxLinkProcessorTest::StandardOpenLinkIsAddedWhenMoreLinksThanAvaiableAreClosed( ...@@ -81,8 +81,8 @@ ToxLinkProcessorTest::StandardOpenLinkIsAddedWhenMoreLinksThanAvaiableAreClosed(
sut.StartNewLink(0, STYLE_NAME_1); sut.StartNewLink(0, STYLE_NAME_1);
sut.CloseLink(1, URL_1); sut.CloseLink(1, URL_1);
sut.CloseLink(1, URL_1); sut.CloseLink(1, URL_1);
CPPUNIT_ASSERT_EQUAL(2u, static_cast<unsigned>(sut.mClosedLinks.size())); CPPUNIT_ASSERT_EQUAL(2u, static_cast<unsigned>(sut.m_ClosedLinks.size()));
CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned>(sut.mClosedLinks.at(1).mEndTextPos)); CPPUNIT_ASSERT_EQUAL(0u, static_cast<unsigned>(sut.m_ClosedLinks.at(1)->mEndTextPos));
} }
void void
...@@ -93,8 +93,8 @@ ToxLinkProcessorTest::AddingAndClosingTwoLinksResultsInTwoClosedLinks() ...@@ -93,8 +93,8 @@ ToxLinkProcessorTest::AddingAndClosingTwoLinksResultsInTwoClosedLinks()
sut.StartNewLink(0, STYLE_NAME_2); sut.StartNewLink(0, STYLE_NAME_2);
sut.CloseLink(1, URL_1); sut.CloseLink(1, URL_1);
sut.CloseLink(1, URL_2); sut.CloseLink(1, URL_2);
CPPUNIT_ASSERT_EQUAL(2u, static_cast<unsigned>(sut.mClosedLinks.size())); CPPUNIT_ASSERT_EQUAL(2u, static_cast<unsigned>(sut.m_ClosedLinks.size()));
CPPUNIT_ASSERT_MESSAGE("no links are open", sut.mStartedLinks.empty()); CPPUNIT_ASSERT_MESSAGE("no links are open", sut.m_StartedLinks.empty());
} }
class ToxLinkProcessorWithOverriddenObtainPoolId : public ToxLinkProcessor { class ToxLinkProcessorWithOverriddenObtainPoolId : public ToxLinkProcessor {
...@@ -120,8 +120,8 @@ ToxLinkProcessorTest::LinkIsCreatedCorrectly() ...@@ -120,8 +120,8 @@ ToxLinkProcessorTest::LinkIsCreatedCorrectly()
sut.StartNewLink(0, STYLE_NAME_1); sut.StartNewLink(0, STYLE_NAME_1);
sut.CloseLink(1, URL_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("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.mClosedLinks.at(0).mINetFormat.GetValue()); CPPUNIT_ASSERT_EQUAL_MESSAGE("Url is stored correctly in link", URL_1, sut.m_ClosedLinks.at(0)->mINetFormat.GetValue());
} }
void void
...@@ -138,18 +138,18 @@ ToxLinkProcessorTest::LinkSequenceIsPreserved() ...@@ -138,18 +138,18 @@ ToxLinkProcessorTest::LinkSequenceIsPreserved()
// check first closed element // check first closed element
CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link", 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", 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", 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 // check second closed element
CPPUNIT_ASSERT_EQUAL_MESSAGE("Style is stored correctly in link", 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", 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", 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 // Put the test suite in the registry
......
...@@ -20,32 +20,34 @@ namespace sw { ...@@ -20,32 +20,34 @@ namespace sw {
void void
ToxLinkProcessor::StartNewLink(sal_Int32 startPosition, const OUString& characterStyle) ToxLinkProcessor::StartNewLink(sal_Int32 startPosition, const OUString& characterStyle)
{ {
mStartedLinks.push_back(new StartedLink(startPosition, characterStyle)); m_StartedLinks.push_back(std::unique_ptr<StartedLink>(
new StartedLink(startPosition, characterStyle)));
} }
void void
ToxLinkProcessor::CloseLink(sal_Int32 endPosition, const OUString& url) 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)) ? StartedLink(0, SW_RES(STR_POOLCHR_TOXJUMP))
: mStartedLinks.back() ); : *m_StartedLinks.back() );
if (!mStartedLinks.empty()) if (!m_StartedLinks.empty())
{ {
mStartedLinks.pop_back(); m_StartedLinks.pop_back();
} }
if (url.isEmpty()) { if (url.isEmpty()) {
return; return;
} }
ClosedLink* closedLink = new ClosedLink(url, startedLink.mStartPosition, endPosition); std::unique_ptr<ClosedLink> pClosedLink(
new ClosedLink(url, startedLink.mStartPosition, endPosition));
const OUString& characterStyle = startedLink.mCharacterStyle; const OUString& characterStyle = startedLink.mCharacterStyle;
sal_uInt16 poolId = ObtainPoolId(characterStyle); sal_uInt16 poolId = ObtainPoolId(characterStyle);
closedLink->mINetFormat.SetVisitedFormatAndId(characterStyle, poolId); pClosedLink->mINetFormat.SetVisitedFormatAndId(characterStyle, poolId);
closedLink->mINetFormat.SetINetFormatAndId(characterStyle, poolId); pClosedLink->mINetFormat.SetINetFormatAndId(characterStyle, poolId);
mClosedLinks.push_back(closedLink); m_ClosedLinks.push_back(std::move(pClosedLink));
} }
sal_uInt16 sal_uInt16
...@@ -63,8 +65,9 @@ ToxLinkProcessor::ObtainPoolId(const OUString& characterStyle) const ...@@ -63,8 +65,9 @@ ToxLinkProcessor::ObtainPoolId(const OUString& characterStyle) const
void void
ToxLinkProcessor::InsertLinkAttributes(SwTextNode& node) ToxLinkProcessor::InsertLinkAttributes(SwTextNode& node)
{ {
for (ClosedLink& clink : mClosedLinks) { for (auto const& clink : m_ClosedLinks)
node.InsertItem(clink.mINetFormat, clink.mStartTextPos, clink.mEndTextPos); {
node.InsertItem(clink->mINetFormat, clink->mStartTextPos, clink->mEndTextPos);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment