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

loplugin:useuniqueptr in ScSheetEvents

Change-Id: I7dce11ddf85fc92d6ac69ea307c4c1c181521460
Reviewed-on: https://gerrit.libreoffice.org/56492
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst ecdca6ee
......@@ -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();
......
......@@ -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: */
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