diff options
-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: */ |