diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-09-11 17:13:03 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-09-12 09:08:13 +0200 |
commit | 7281f4a73ec3679798a6271ab5a0ad839f278e37 (patch) | |
tree | 3cca53740da25547641c8c8d31dd673aee9d7b35 | |
parent | use more GetColumnsRange (diff) | |
download | core-7281f4a73ec3679798a6271ab5a0ad839f278e37.tar.gz core-7281f4a73ec3679798a6271ab5a0ad839f278e37.zip |
use std::unique_ptr in TItemInfo
and inline the TItems typedef
Change-Id: I0c50d12d53ce4b52c330cad8790a65065ebdd82e
Reviewed-on: https://gerrit.libreoffice.org/42182
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | include/unotools/itemholderbase.hxx | 14 | ||||
-rw-r--r-- | svl/source/config/itemholder2.cxx | 22 | ||||
-rw-r--r-- | svl/source/config/itemholder2.hxx | 2 | ||||
-rw-r--r-- | svtools/source/config/itemholder2.cxx | 33 | ||||
-rw-r--r-- | svtools/source/config/itemholder2.hxx | 2 | ||||
-rw-r--r-- | unotools/source/config/itemholder1.cxx | 62 | ||||
-rw-r--r-- | unotools/source/config/itemholder1.hxx | 2 |
7 files changed, 55 insertions, 82 deletions
diff --git a/include/unotools/itemholderbase.hxx b/include/unotools/itemholderbase.hxx index 13a11f7e5789..9cb50417c163 100644 --- a/include/unotools/itemholderbase.hxx +++ b/include/unotools/itemholderbase.hxx @@ -20,6 +20,7 @@ #ifndef INCLUDED_UNOTOOLS_ITEMHOLDERBASE_HXX #define INCLUDED_UNOTOOLS_ITEMHOLDERBASE_HXX +#include <memory> #include <vector> #include <osl/mutex.hxx> @@ -80,17 +81,20 @@ enum class EItem struct TItemInfo { TItemInfo() - : pItem(nullptr) - , eItem(EItem::UserOptions) + : eItem(EItem::UserOptions) { } - utl::detail::Options * pItem; + TItemInfo(TItemInfo&& other) + : pItem(std::move(other.pItem)) + , eItem(other.eItem) + { + } + + std::unique_ptr<utl::detail::Options> pItem; EItem eItem; }; -typedef ::std::vector< TItemInfo > TItems; - #endif // INCLUDED_UNOTOOLS_ITEMHOLDERBASE_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/config/itemholder2.cxx b/svl/source/config/itemholder2.cxx index 1511b47082a3..b809eba57b1d 100644 --- a/svl/source/config/itemholder2.cxx +++ b/svl/source/config/itemholder2.cxx @@ -79,12 +79,8 @@ void ItemHolder2::impl_addItem(EItem eItem) { ::osl::ResettableMutexGuard aLock(m_aLock); - TItems::const_iterator pIt; - for ( pIt = m_lItems.begin(); - pIt != m_lItems.end() ; - ++pIt ) + for ( auto const & rInfo : m_lItems ) { - const TItemInfo& rInfo = *pIt; if (rInfo.eItem == eItem) return; } @@ -93,24 +89,18 @@ void ItemHolder2::impl_addItem(EItem eItem) aNewItem.eItem = eItem; impl_newItem(aNewItem); if (aNewItem.pItem) - m_lItems.push_back(aNewItem); + m_lItems.emplace_back(std::move(aNewItem)); } void ItemHolder2::impl_releaseAllItems() { - TItems items; + std::vector< TItemInfo > items; { ::osl::MutexGuard aLock(m_aLock); items.swap(m_lItems); } - TItems::iterator pIt; - for ( pIt = items.begin(); - pIt != items.end() ; - ++pIt ) - { - delete pIt->pItem; - } + // items will be freed when the block exits } void ItemHolder2::impl_newItem(TItemInfo& rItem) @@ -118,11 +108,11 @@ void ItemHolder2::impl_newItem(TItemInfo& rItem) switch(rItem.eItem) { case EItem::CJKOptions : - rItem.pItem = new SvtCJKOptions(); + rItem.pItem.reset( new SvtCJKOptions() ); break; case EItem::CTLOptions : - rItem.pItem = new SvtCTLOptions(); + rItem.pItem.reset( new SvtCTLOptions() ); break; default: diff --git a/svl/source/config/itemholder2.hxx b/svl/source/config/itemholder2.hxx index 3246cc37b4dd..27d9f182ff03 100644 --- a/svl/source/config/itemholder2.hxx +++ b/svl/source/config/itemholder2.hxx @@ -30,7 +30,7 @@ class ItemHolder2 : private ItemHolderMutexBase // member private: - TItems m_lItems; + std::vector<TItemInfo> m_lItems; // c++ interface public: diff --git a/svtools/source/config/itemholder2.cxx b/svtools/source/config/itemholder2.cxx index 5989157f5e8b..2512715caab8 100644 --- a/svtools/source/config/itemholder2.cxx +++ b/svtools/source/config/itemholder2.cxx @@ -91,12 +91,8 @@ void ItemHolder2::impl_addItem(EItem eItem) { ::osl::ResettableMutexGuard aLock(m_aLock); - TItems::const_iterator pIt; - for ( pIt = m_lItems.begin(); - pIt != m_lItems.end() ; - ++pIt ) + for ( auto const & rInfo : m_lItems ) { - const TItemInfo& rInfo = *pIt; if (rInfo.eItem == eItem) return; } @@ -105,26 +101,19 @@ void ItemHolder2::impl_addItem(EItem eItem) aNewItem.eItem = eItem; impl_newItem(aNewItem); if (aNewItem.pItem) - m_lItems.push_back(aNewItem); + m_lItems.emplace_back(std::move(aNewItem)); } void ItemHolder2::impl_releaseAllItems() { - TItems items; + std::vector<TItemInfo> items; { ::osl::ResettableMutexGuard aLock(m_aLock); items.swap(m_lItems); } - TItems::iterator pIt; - for ( pIt = items.begin(); - pIt != items.end() ; - ++pIt ) - { - delete pIt->pItem; - } - m_lItems.clear(); + // items will be freed when the block exits } @@ -133,31 +122,31 @@ void ItemHolder2::impl_newItem(TItemInfo& rItem) switch(rItem.eItem) { case EItem::AccessibilityOptions : - rItem.pItem = new SvtAccessibilityOptions(); + rItem.pItem.reset( new SvtAccessibilityOptions() ); break; case EItem::ColorConfig : - rItem.pItem = new ::svtools::ColorConfig(); + rItem.pItem.reset( new ::svtools::ColorConfig() ); break; case EItem::HelpOptions : - rItem.pItem = new SvtHelpOptions(); + rItem.pItem.reset( new SvtHelpOptions() ); break; case EItem::MenuOptions : - rItem.pItem = new SvtMenuOptions(); + rItem.pItem.reset( new SvtMenuOptions() ); break; case EItem::PrintOptions : - rItem.pItem = new SvtPrinterOptions(); + rItem.pItem.reset( new SvtPrinterOptions() ); break; case EItem::PrintFileOptions : - rItem.pItem = new SvtPrintFileOptions(); + rItem.pItem.reset( new SvtPrintFileOptions() ); break; case EItem::MiscOptions : - rItem.pItem = new SvtMiscOptions(); + rItem.pItem.reset( new SvtMiscOptions() ); break; default: diff --git a/svtools/source/config/itemholder2.hxx b/svtools/source/config/itemholder2.hxx index bf344e4f3b92..110fbe254fd4 100644 --- a/svtools/source/config/itemholder2.hxx +++ b/svtools/source/config/itemholder2.hxx @@ -34,7 +34,7 @@ class ItemHolder2 : private ItemHolderMutexBase // member private: - TItems m_lItems; + std::vector<TItemInfo> m_lItems; // c++ interface diff --git a/unotools/source/config/itemholder1.cxx b/unotools/source/config/itemholder1.cxx index ea658bc0dc1d..a11fd059fead 100644 --- a/unotools/source/config/itemholder1.cxx +++ b/unotools/source/config/itemholder1.cxx @@ -93,12 +93,8 @@ void ItemHolder1::impl_addItem(EItem eItem) { ::osl::ResettableMutexGuard aLock(m_aLock); - TItems::const_iterator pIt; - for ( pIt = m_lItems.begin(); - pIt != m_lItems.end(); - ++pIt ) + for ( auto const & rInfo : m_lItems ) { - const TItemInfo& rInfo = *pIt; if (rInfo.eItem == eItem) return; } @@ -107,24 +103,18 @@ void ItemHolder1::impl_addItem(EItem eItem) aNewItem.eItem = eItem; impl_newItem(aNewItem); if (aNewItem.pItem) - m_lItems.push_back(aNewItem); + m_lItems.emplace_back(std::move(aNewItem)); } void ItemHolder1::impl_releaseAllItems() { - TItems items; + std::vector< TItemInfo > items; { ::osl::MutexGuard aLock(m_aLock); items.swap(m_lItems); } - TItems::iterator pIt; - for ( pIt = items.begin(); - pIt != items.end(); - ++pIt ) - { - delete pIt->pItem; - } + // items will be freed when the block exits } void ItemHolder1::impl_newItem(TItemInfo& rItem) @@ -132,91 +122,91 @@ void ItemHolder1::impl_newItem(TItemInfo& rItem) switch(rItem.eItem) { case EItem::CmdOptions : - rItem.pItem = new SvtCommandOptions(); + rItem.pItem.reset( new SvtCommandOptions() ); break; case EItem::Compatibility : - rItem.pItem = new SvtCompatibilityOptions(); + rItem.pItem.reset( new SvtCompatibilityOptions() ); break; case EItem::DefaultOptions : - rItem.pItem = new SvtDefaultOptions(); + rItem.pItem.reset( new SvtDefaultOptions() ); break; case EItem::DynamicMenuOptions : - rItem.pItem = new SvtDynamicMenuOptions(); + rItem.pItem.reset( new SvtDynamicMenuOptions() ); break; case EItem::EventConfig : - //rItem.pItem = new GlobalEventConfig(); + //rItem.pItem.reset( new GlobalEventConfig() ); break; case EItem::ExtendedSecurityOptions : - rItem.pItem = new SvtExtendedSecurityOptions(); + rItem.pItem.reset( new SvtExtendedSecurityOptions() ); break; case EItem::FontOptions : - rItem.pItem = new SvtFontOptions(); + rItem.pItem.reset( new SvtFontOptions() ); break; case EItem::HistoryOptions : - rItem.pItem = new SvtHistoryOptions(); + rItem.pItem.reset( new SvtHistoryOptions() ); break; case EItem::LinguConfig : - rItem.pItem = new SvtLinguConfig(); + rItem.pItem.reset( new SvtLinguConfig() ); break; case EItem::ModuleOptions : - rItem.pItem = new SvtModuleOptions(); + rItem.pItem.reset( new SvtModuleOptions() ); break; case EItem::OptionsDialogOptions : - rItem.pItem = new SvtOptionsDialogOptions(); + rItem.pItem.reset( new SvtOptionsDialogOptions() ); break; case EItem::PathOptions : - rItem.pItem = new SvtPathOptions(); + rItem.pItem.reset( new SvtPathOptions() ); break; case EItem::PrintWarningOptions : - rItem.pItem = new SvtPrintWarningOptions(); + rItem.pItem.reset( new SvtPrintWarningOptions() ); break; case EItem::MiscConfig : - rItem.pItem = new ::utl::MiscCfg(); + rItem.pItem.reset( new ::utl::MiscCfg() ); break; case EItem::SaveOptions : - rItem.pItem = new SvtSaveOptions(); + rItem.pItem.reset( new SvtSaveOptions() ); break; case EItem::SecurityOptions : - rItem.pItem = new SvtSecurityOptions(); + rItem.pItem.reset( new SvtSecurityOptions() ); break; case EItem::ViewOptionsDialog : - rItem.pItem = new SvtViewOptions(EViewType::Dialog, OUString()); + rItem.pItem.reset( new SvtViewOptions(EViewType::Dialog, OUString()) ); break; case EItem::ViewOptionsTabDialog : - rItem.pItem = new SvtViewOptions(EViewType::TabDialog, OUString()); + rItem.pItem.reset( new SvtViewOptions(EViewType::TabDialog, OUString()) ); break; case EItem::ViewOptionsTabPage : - rItem.pItem = new SvtViewOptions(EViewType::TabPage, OUString()); + rItem.pItem.reset( new SvtViewOptions(EViewType::TabPage, OUString()) ); break; case EItem::ViewOptionsWindow : - rItem.pItem = new SvtViewOptions(EViewType::Window, OUString()); + rItem.pItem.reset( new SvtViewOptions(EViewType::Window, OUString()) ); break; case EItem::UserOptions : - rItem.pItem = new SvtUserOptions(); + rItem.pItem.reset( new SvtUserOptions() ); break; case EItem::SysLocaleOptions : - rItem.pItem = new SvtSysLocaleOptions(); + rItem.pItem.reset( new SvtSysLocaleOptions() ); break; default: diff --git a/unotools/source/config/itemholder1.hxx b/unotools/source/config/itemholder1.hxx index 406a34eaec56..c632eedc72e7 100644 --- a/unotools/source/config/itemholder1.hxx +++ b/unotools/source/config/itemholder1.hxx @@ -31,7 +31,7 @@ class ItemHolder1 : private ItemHolderMutexBase // member private: - TItems m_lItems; + std::vector<TItemInfo> m_lItems; // c++ interface public: |