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

loplugin:useuniqueptr in HWPFile

Change-Id: I0eb3f09b5ca82ce4810aafbb7d5d53f1faa00e3f
Reviewed-on: https://gerrit.libreoffice.org/60111
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst fda27303
...@@ -626,12 +626,12 @@ static HWPPara *LoadParaList() ...@@ -626,12 +626,12 @@ static HWPPara *LoadParaList()
return nullptr; return nullptr;
HWPFile *hwpf = GetCurrentDoc(); HWPFile *hwpf = GetCurrentDoc();
HIODev *hio = hwpf->SetIODevice(hmem); std::unique_ptr<HIODev> hio = hwpf->SetIODevice(std::unique_ptr<HIODev>(hmem));
std::vector< HWPPara* > plist; std::vector< HWPPara* > plist;
hwpf->ReadParaList(plist); hwpf->ReadParaList(plist);
hwpf->SetIODevice(hio); hwpf->SetIODevice(std::move(hio));
return plist.size()? plist.front() : nullptr; return plist.size()? plist.front() : nullptr;
} }
......
...@@ -94,17 +94,14 @@ int detect_hwp_version(const char *str) ...@@ -94,17 +94,14 @@ int detect_hwp_version(const char *str)
int HWPFile::Open(std::unique_ptr<HStream> stream) int HWPFile::Open(std::unique_ptr<HStream> stream)
{ {
HStreamIODev *hstreamio = new HStreamIODev(std::move(stream)); std::unique_ptr<HStreamIODev> hstreamio(new HStreamIODev(std::move(stream)));
if (!hstreamio->open()) if (!hstreamio->open())
{ {
delete hstreamio;
return SetState(HWP_EMPTY_FILE); return SetState(HWP_EMPTY_FILE);
} }
HIODev *pPrev = SetIODevice(hstreamio); SetIODevice(std::move(hstreamio));
delete pPrev;
char idstr[HWPIDLen]; char idstr[HWPIDLen];
...@@ -185,13 +182,10 @@ void HWPFile::SetCompressed(bool flag) ...@@ -185,13 +182,10 @@ void HWPFile::SetCompressed(bool flag)
} }
HIODev *HWPFile::SetIODevice(HIODev * new_hiodev) std::unique_ptr<HIODev> HWPFile::SetIODevice(std::unique_ptr<HIODev> new_hiodev)
{ {
HIODev *old_hiodev = hiodev.release(); std::swap(hiodev, new_hiodev);
return new_hiodev;
hiodev.reset( new_hiodev );
return old_hiodev;
} }
......
...@@ -165,7 +165,7 @@ class DLLEXPORT HWPFile ...@@ -165,7 +165,7 @@ class DLLEXPORT HWPFile
/** /**
* Sets current HIODev * Sets current HIODev
*/ */
HIODev *SetIODevice( HIODev *hiodev ); std::unique_ptr<HIODev> SetIODevice( std::unique_ptr<HIODev> hiodev );
/** /**
* Reads all information of hwp file from stream * Reads all information of hwp file from stream
......
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