diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-06-25 16:46:32 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2018-06-27 08:32:19 +0200 |
commit | 5be0637827cd987b7b7dda7ca2c54a3548d9ef51 (patch) | |
tree | 35d67a96c272cefe48df458a53e3f3310af6a563 /sc | |
parent | ecdca6ee0c56371253e1f62ec49d512c1aa7e6dc (diff) |
loplugin:useuniqueptr in ScSheetEvents
Change-Id: I7dce11ddf85fc92d6ac69ea307c4c1c181521460
Reviewed-on: https://gerrit.libreoffice.org/56492
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/sheetevents.hxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/sheetevents.cxx | 30 |
2 files changed, 14 insertions, 20 deletions
diff --git a/sc/inc/sheetevents.hxx b/sc/inc/sheetevents.hxx index 267e442f25a3..8434cc209e4c 100644 --- a/sc/inc/sheetevents.hxx +++ b/sc/inc/sheetevents.hxx @@ -21,6 +21,8 @@ #define INCLUDED_SC_INC_SHEETEVENTS_HXX #include <rtl/ustring.hxx> +#include <memory> +#include <boost/optional.hpp> enum class ScSheetEventId { FOCUS, UNFOCUS, SELECT, DOUBLECLICK, RIGHTCLICK, CHANGE, CALCULATE, COUNT, @@ -29,7 +31,7 @@ enum class ScSheetEventId { class ScSheetEvents { - OUString** mpScriptNames; + std::unique_ptr<boost::optional<OUString>[]> mpScriptNames; void Clear(); diff --git a/sc/source/core/data/sheetevents.cxx b/sc/source/core/data/sheetevents.cxx index 0cf3be3de55d..b8f0430e2101 100644 --- a/sc/source/core/data/sheetevents.cxx +++ b/sc/source/core/data/sheetevents.cxx @@ -73,13 +73,7 @@ ScSheetEvents::~ScSheetEvents() void ScSheetEvents::Clear() { - if (mpScriptNames) - { - for (sal_Int32 nEvent=0; nEvent<COUNT; ++nEvent) - delete mpScriptNames[nEvent]; - delete[] mpScriptNames; - mpScriptNames = nullptr; - } + mpScriptNames.reset(); } ScSheetEvents::ScSheetEvents(const ScSheetEvents& rOther) : @@ -93,12 +87,9 @@ ScSheetEvents& ScSheetEvents::operator=(const ScSheetEvents& rOther) Clear(); if (rOther.mpScriptNames) { - mpScriptNames = new OUString*[COUNT]; + mpScriptNames.reset( new boost::optional<OUString>[COUNT] ); for (sal_Int32 nEvent=0; nEvent<COUNT; ++nEvent) - if (rOther.mpScriptNames[nEvent]) - mpScriptNames[nEvent] = new OUString(*rOther.mpScriptNames[nEvent]); - else - mpScriptNames[nEvent] = nullptr; + mpScriptNames[nEvent] = *rOther.mpScriptNames[nEvent]; } return *this; } @@ -106,7 +97,11 @@ ScSheetEvents& ScSheetEvents::operator=(const ScSheetEvents& rOther) const OUString* ScSheetEvents::GetScript(ScSheetEventId nEvent) const { if (mpScriptNames) - return mpScriptNames[static_cast<int>(nEvent)]; + { + boost::optional<OUString> const & r = mpScriptNames[static_cast<int>(nEvent)]; + if (r) + return &*r; + } return nullptr; } @@ -115,15 +110,12 @@ void ScSheetEvents::SetScript(ScSheetEventId eEvent, const OUString* pNew) int nEvent = static_cast<int>(eEvent); if (!mpScriptNames) { - mpScriptNames = new OUString*[COUNT]; - for (sal_Int32 nEventIdx=0; nEventIdx<COUNT; ++nEventIdx) - mpScriptNames[nEventIdx] = nullptr; + mpScriptNames.reset( new boost::optional<OUString>[COUNT] ); } - delete mpScriptNames[nEvent]; if (pNew) - mpScriptNames[nEvent] = new OUString(*pNew); + mpScriptNames[nEvent] = *pNew; else - mpScriptNames[nEvent] = nullptr; + mpScriptNames[nEvent].reset(); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |