Kaydet (Commit) c9f01cc7 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in StyleTree_Impl

Change-Id: I0541283ad9b5719f0b181ba1bdedeb287316c8a2
Reviewed-on: https://gerrit.libreoffice.org/50661Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 260a443b
...@@ -73,8 +73,10 @@ typedef std::vector<SfxObjectUI_Impl*> SfxObjectUIArr_Impl; ...@@ -73,8 +73,10 @@ typedef std::vector<SfxObjectUI_Impl*> SfxObjectUIArr_Impl;
struct SfxInterface_Impl struct SfxInterface_Impl
{ {
SfxObjectUIArr_Impl aObjectBars; // registered ObjectBars std::vector<std::unique_ptr<SfxObjectUI_Impl>>
SfxObjectUIArr_Impl aChildWindows; // registered ChildWindows aObjectBars; // registered ObjectBars
std::vector<std::unique_ptr<SfxObjectUI_Impl>>
aChildWindows; // registered ChildWindows
OUString aPopupName; // registered PopupMenu OUString aPopupName; // registered PopupMenu
StatusBarId eStatBarResId; // registered StatusBar StatusBarId eStatBarResId; // registered StatusBar
SfxModule* pModule; SfxModule* pModule;
...@@ -86,15 +88,6 @@ struct SfxInterface_Impl ...@@ -86,15 +88,6 @@ struct SfxInterface_Impl
, bRegistered(false) , bRegistered(false)
{ {
} }
~SfxInterface_Impl()
{
for (auto const& objectBar : aObjectBars)
delete objectBar;
for (auto const& childWindow : aChildWindows)
delete childWindow;
}
}; };
static SfxObjectUI_Impl* CreateObjectBarUI_Impl(sal_uInt16 nPos, SfxVisibilityFlags nFlags, ToolbarId eId, SfxShellFeature nFeature); static SfxObjectUI_Impl* CreateObjectBarUI_Impl(sal_uInt16 nPos, SfxVisibilityFlags nFlags, ToolbarId eId, SfxShellFeature nFeature);
...@@ -280,7 +273,7 @@ void SfxInterface::RegisterObjectBar(sal_uInt16 nPos, SfxVisibilityFlags nFlags, ...@@ -280,7 +273,7 @@ void SfxInterface::RegisterObjectBar(sal_uInt16 nPos, SfxVisibilityFlags nFlags,
{ {
SfxObjectUI_Impl* pUI = CreateObjectBarUI_Impl(nPos, nFlags, eId, nFeature); SfxObjectUI_Impl* pUI = CreateObjectBarUI_Impl(nPos, nFlags, eId, nFeature);
if ( pUI ) if ( pUI )
pImplData->aObjectBars.push_back(pUI); pImplData->aObjectBars.emplace_back(pUI);
} }
SfxObjectUI_Impl* CreateObjectBarUI_Impl(sal_uInt16 nPos, SfxVisibilityFlags nFlags, ToolbarId eId, SfxShellFeature nFeature) SfxObjectUI_Impl* CreateObjectBarUI_Impl(sal_uInt16 nPos, SfxVisibilityFlags nFlags, ToolbarId eId, SfxShellFeature nFeature)
...@@ -365,7 +358,7 @@ void SfxInterface::RegisterChildWindow(sal_uInt16 nId, bool bContext, SfxShellFe ...@@ -365,7 +358,7 @@ void SfxInterface::RegisterChildWindow(sal_uInt16 nId, bool bContext, SfxShellFe
{ {
SfxObjectUI_Impl* pUI = new SfxObjectUI_Impl(0, SfxVisibilityFlags::Invisible, nId, nFeature); SfxObjectUI_Impl* pUI = new SfxObjectUI_Impl(0, SfxVisibilityFlags::Invisible, nId, nFeature);
pUI->bContext = bContext; pUI->bContext = bContext;
pImplData->aChildWindows.push_back(pUI); pImplData->aChildWindows.emplace_back(pUI);
} }
void SfxInterface::RegisterStatusBar(StatusBarId eId) void SfxInterface::RegisterStatusBar(StatusBarId eId)
......
...@@ -499,7 +499,7 @@ void StyleTreeListBox_Impl::Recalc() ...@@ -499,7 +499,7 @@ void StyleTreeListBox_Impl::Recalc()
/** Internal structure for the establishment of the hierarchical view */ /** Internal structure for the establishment of the hierarchical view */
class StyleTree_Impl; class StyleTree_Impl;
typedef std::vector<StyleTree_Impl*> StyleTreeArr_Impl; typedef std::vector<std::unique_ptr<StyleTree_Impl>> StyleTreeArr_Impl;
class StyleTree_Impl class StyleTree_Impl
{ {
...@@ -513,20 +513,14 @@ public: ...@@ -513,20 +513,14 @@ public:
StyleTree_Impl(const OUString &rName, const OUString &rParent): StyleTree_Impl(const OUString &rName, const OUString &rParent):
aName(rName), aParent(rParent), pChildren(0) {} aName(rName), aParent(rParent), pChildren(0) {}
~StyleTree_Impl();
const OUString& getName() { return aName; } const OUString& getName() { return aName; }
const OUString& getParent() { return aParent; } const OUString& getParent() { return aParent; }
StyleTreeArr_Impl& getChildren() { return pChildren; } StyleTreeArr_Impl& getChildren() { return pChildren; }
}; };
StyleTree_Impl::~StyleTree_Impl()
{
for (auto const& child : pChildren)
delete child;
}
StyleTreeArr_Impl& MakeTree_Impl(StyleTreeArr_Impl& rArr) void MakeTree_Impl(StyleTreeArr_Impl& rArr)
{ {
const comphelper::string::NaturalStringSorter aSorter( const comphelper::string::NaturalStringSorter aSorter(
::comphelper::getProcessComponentContext(), ::comphelper::getProcessComponentContext(),
...@@ -536,11 +530,11 @@ StyleTreeArr_Impl& MakeTree_Impl(StyleTreeArr_Impl& rArr) ...@@ -536,11 +530,11 @@ StyleTreeArr_Impl& MakeTree_Impl(StyleTreeArr_Impl& rArr)
styleFinder.reserve(rArr.size()); styleFinder.reserve(rArr.size());
for (const auto& pEntry : rArr) for (const auto& pEntry : rArr)
{ {
styleFinder.emplace(pEntry->getName(), pEntry); styleFinder.emplace(pEntry->getName(), pEntry.get());
} }
// Arrange all under their Parents // Arrange all under their Parents
for (const auto& pEntry : rArr) for (auto& pEntry : rArr)
{ {
if (!pEntry->HasParent()) if (!pEntry->HasParent())
continue; continue;
...@@ -550,21 +544,19 @@ StyleTreeArr_Impl& MakeTree_Impl(StyleTreeArr_Impl& rArr) ...@@ -550,21 +544,19 @@ StyleTreeArr_Impl& MakeTree_Impl(StyleTreeArr_Impl& rArr)
StyleTree_Impl* pCmp = it->second; StyleTree_Impl* pCmp = it->second;
// Insert child entries sorted // Insert child entries sorted
auto iPos = std::lower_bound(pCmp->getChildren().begin(), pCmp->getChildren().end(), pEntry, auto iPos = std::lower_bound(pCmp->getChildren().begin(), pCmp->getChildren().end(), pEntry,
[&aSorter](StyleTree_Impl* pEntry1, StyleTree_Impl* pEntry2) { return aSorter.compare(pEntry1->getName(), pEntry2->getName()) < 0; }); [&aSorter](std::unique_ptr<StyleTree_Impl> const & pEntry1, std::unique_ptr<StyleTree_Impl> const & pEntry2) { return aSorter.compare(pEntry1->getName(), pEntry2->getName()) < 0; });
pCmp->getChildren().insert(iPos, pEntry); pCmp->getChildren().insert(iPos, std::move(pEntry));
} }
} }
// Only keep tree roots in rArr, child elements can be accessed through the hierarchy // Only keep tree roots in rArr, child elements can be accessed through the hierarchy
rArr.erase(std::remove_if(rArr.begin(), rArr.end(), [](StyleTree_Impl* pEntry) { return pEntry->HasParent(); }), rArr.end()); rArr.erase(std::remove_if(rArr.begin(), rArr.end(), [](std::unique_ptr<StyleTree_Impl> const & pEntry) { return !pEntry; }), rArr.end());
// tdf#91106 sort top level styles // tdf#91106 sort top level styles
std::sort(rArr.begin(), rArr.end(), std::sort(rArr.begin(), rArr.end(),
[&aSorter](StyleTree_Impl* pEntry1, StyleTree_Impl* pEntry2) { [&aSorter](std::unique_ptr<StyleTree_Impl> const & pEntry1, std::unique_ptr<StyleTree_Impl> const & pEntry2) {
return aSorter.compare(pEntry1->getName(), pEntry2->getName()) < 0; return aSorter.compare(pEntry1->getName(), pEntry2->getName()) < 0;
}); });
return rArr;
} }
inline bool IsExpanded_Impl( const ExpandedEntries_t& rEntries, inline bool IsExpanded_Impl( const ExpandedEntries_t& rEntries,
...@@ -595,7 +587,7 @@ SvTreeListEntry* FillBox_Impl(SvTreeListBox* pBox, ...@@ -595,7 +587,7 @@ SvTreeListEntry* FillBox_Impl(SvTreeListBox* pBox,
for(size_t i = 0; i < pEntry->getChildren().size(); ++i) for(size_t i = 0; i < pEntry->getChildren().size(); ++i)
{ {
FillBox_Impl(pBox, pEntry->getChildren()[i], rEntries, eStyleFamily, pTreeListEntry); FillBox_Impl(pBox, pEntry->getChildren()[i].get(), rEntries, eStyleFamily, pTreeListEntry);
} }
return pTreeListEntry; return pTreeListEntry;
} }
...@@ -1033,7 +1025,7 @@ void SfxCommonTemplateDialog_Impl::FillTreeBox() ...@@ -1033,7 +1025,7 @@ void SfxCommonTemplateDialog_Impl::FillTreeBox()
while (pStyle) while (pStyle)
{ {
StyleTree_Impl* pNew = new StyleTree_Impl(pStyle->GetName(), pStyle->GetParent()); StyleTree_Impl* pNew = new StyleTree_Impl(pStyle->GetName(), pStyle->GetParent());
aArr.push_back(pNew); aArr.emplace_back(pNew);
pStyle = pStyleSheetPool->Next(); pStyle = pStyleSheetPool->Next();
} }
...@@ -1046,8 +1038,8 @@ void SfxCommonTemplateDialog_Impl::FillTreeBox() ...@@ -1046,8 +1038,8 @@ void SfxCommonTemplateDialog_Impl::FillTreeBox()
for (sal_uInt16 i = 0; i < nCount; ++i) for (sal_uInt16 i = 0; i < nCount; ++i)
{ {
FillBox_Impl(pTreeBox, aArr[i], aEntries, pItem->GetFamily(), nullptr); FillBox_Impl(pTreeBox, aArr[i].get(), aEntries, pItem->GetFamily(), nullptr);
delete aArr[i]; aArr[i].reset();
} }
pTreeBox->Recalc(); pTreeBox->Recalc();
......
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