Kaydet (Commit) ea2d767d authored tarafından Michael Stahl's avatar Michael Stahl

tools: change INetURLObject::getData to return std::unique_ptr

Life-cycle becomes a lot more obvious this way.

Change-Id: I1ca99607f609a2223011c40447ad1cd9ca5ccaa5
üst 325ce86b
...@@ -26,6 +26,8 @@ ...@@ -26,6 +26,8 @@
#include <rtl/textenc.h> #include <rtl/textenc.h>
#include <sal/types.h> #include <sal/types.h>
#include <memory>
class SvMemoryStream; class SvMemoryStream;
namespace com { namespace sun { namespace star { namespace util { namespace com { namespace sun { namespace star { namespace util {
...@@ -854,7 +856,7 @@ public: ...@@ -854,7 +856,7 @@ public:
const; const;
// Data URLs: // Data URLs:
SvMemoryStream* getData(); std::unique_ptr<SvMemoryStream> getData();
// POP3 and URLs: // POP3 and URLs:
......
...@@ -698,12 +698,11 @@ IMAGE_SETEVENT: ...@@ -698,12 +698,11 @@ IMAGE_SETEVENT:
INetURLObject aGraphicURL( sGrfNm ); INetURLObject aGraphicURL( sGrfNm );
if( aGraphicURL.GetProtocol() == INET_PROT_DATA ) if( aGraphicURL.GetProtocol() == INET_PROT_DATA )
{ {
SvMemoryStream* pStream = aGraphicURL.getData(); std::unique_ptr<SvMemoryStream> const pStream(aGraphicURL.getData());
if (pStream) if (pStream)
{ {
if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, "", *pStream)) if (GRFILTER_OK == GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, "", *pStream))
sGrfNm = ""; sGrfNm = "";
delete pStream;
} }
} }
// sBaseURL is empty if the source is clipboard // sBaseURL is empty if the source is clipboard
......
...@@ -246,7 +246,7 @@ namespace tools_urlobj ...@@ -246,7 +246,7 @@ namespace tools_urlobj
void urlobjTest_data() { void urlobjTest_data() {
INetURLObject url; INetURLObject url;
SvMemoryStream * strm; std::unique_ptr<SvMemoryStream> strm;
unsigned char const * buf; unsigned char const * buf;
url = INetURLObject("data:"); url = INetURLObject("data:");
...@@ -259,7 +259,7 @@ namespace tools_urlobj ...@@ -259,7 +259,7 @@ namespace tools_urlobj
strm = url.getData(); strm = url.getData();
CPPUNIT_ASSERT(strm != 0); CPPUNIT_ASSERT(strm != 0);
CPPUNIT_ASSERT_EQUAL(sal_uIntPtr(0), strm->GetSize()); CPPUNIT_ASSERT_EQUAL(sal_uIntPtr(0), strm->GetSize());
delete strm; strm.reset();
url = INetURLObject("data:,,%C3%A4%90"); url = INetURLObject("data:,,%C3%A4%90");
CPPUNIT_ASSERT(!url.HasError()); CPPUNIT_ASSERT(!url.HasError());
...@@ -271,7 +271,7 @@ namespace tools_urlobj ...@@ -271,7 +271,7 @@ namespace tools_urlobj
CPPUNIT_ASSERT_EQUAL(0xC3, int(buf[1])); CPPUNIT_ASSERT_EQUAL(0xC3, int(buf[1]));
CPPUNIT_ASSERT_EQUAL(0xA4, int(buf[2])); CPPUNIT_ASSERT_EQUAL(0xA4, int(buf[2]));
CPPUNIT_ASSERT_EQUAL(0x90, int(buf[3])); CPPUNIT_ASSERT_EQUAL(0x90, int(buf[3]));
delete strm; strm.reset();
url = INetURLObject("data:base64,"); url = INetURLObject("data:base64,");
//TODO: CPPUNIT_ASSERT(url.HasError()); //TODO: CPPUNIT_ASSERT(url.HasError());
...@@ -283,14 +283,14 @@ namespace tools_urlobj ...@@ -283,14 +283,14 @@ namespace tools_urlobj
strm = url.getData(); strm = url.getData();
CPPUNIT_ASSERT(strm != 0); CPPUNIT_ASSERT(strm != 0);
CPPUNIT_ASSERT_EQUAL(sal_uIntPtr(0), strm->GetSize()); CPPUNIT_ASSERT_EQUAL(sal_uIntPtr(0), strm->GetSize());
delete strm; strm.reset();
url = INetURLObject("data:;bAsE64,"); url = INetURLObject("data:;bAsE64,");
CPPUNIT_ASSERT(!url.HasError()); CPPUNIT_ASSERT(!url.HasError());
strm = url.getData(); strm = url.getData();
CPPUNIT_ASSERT(strm != 0); CPPUNIT_ASSERT(strm != 0);
CPPUNIT_ASSERT_EQUAL(sal_uIntPtr(0), strm->GetSize()); CPPUNIT_ASSERT_EQUAL(sal_uIntPtr(0), strm->GetSize());
delete strm; strm.reset();
url = INetURLObject("data:;base64,YWJjCg=="); url = INetURLObject("data:;base64,YWJjCg==");
CPPUNIT_ASSERT(!url.HasError()); CPPUNIT_ASSERT(!url.HasError());
...@@ -302,7 +302,7 @@ namespace tools_urlobj ...@@ -302,7 +302,7 @@ namespace tools_urlobj
CPPUNIT_ASSERT_EQUAL(0x62, int(buf[1])); CPPUNIT_ASSERT_EQUAL(0x62, int(buf[1]));
CPPUNIT_ASSERT_EQUAL(0x63, int(buf[2])); CPPUNIT_ASSERT_EQUAL(0x63, int(buf[2]));
CPPUNIT_ASSERT_EQUAL(0x0A, int(buf[3])); CPPUNIT_ASSERT_EQUAL(0x0A, int(buf[3]));
delete strm; strm.reset();
url = INetURLObject("data:;base64,YWJjCg="); url = INetURLObject("data:;base64,YWJjCg=");
CPPUNIT_ASSERT(!url.HasError()); CPPUNIT_ASSERT(!url.HasError());
...@@ -324,7 +324,7 @@ namespace tools_urlobj ...@@ -324,7 +324,7 @@ namespace tools_urlobj
CPPUNIT_ASSERT_EQUAL(0x51, int(buf[1])); CPPUNIT_ASSERT_EQUAL(0x51, int(buf[1]));
CPPUNIT_ASSERT_EQUAL(0x3D, int(buf[2])); CPPUNIT_ASSERT_EQUAL(0x3D, int(buf[2]));
CPPUNIT_ASSERT_EQUAL(0x3D, int(buf[3])); CPPUNIT_ASSERT_EQUAL(0x3D, int(buf[3]));
delete strm; strm.reset();
url = INetURLObject("http://example.com"); url = INetURLObject("http://example.com");
CPPUNIT_ASSERT(!url.HasError()); CPPUNIT_ASSERT(!url.HasError());
......
...@@ -585,7 +585,9 @@ void INetURLObject::setInvalid() ...@@ -585,7 +585,9 @@ void INetURLObject::setInvalid()
namespace { namespace {
SvMemoryStream * memoryStream(void const * data, sal_Int32 length) { std::unique_ptr<SvMemoryStream> memoryStream(
void const * data, sal_Int32 length)
{
std::unique_ptr<char, boost::checked_array_deleter<char> > b( std::unique_ptr<char, boost::checked_array_deleter<char> > b(
new char[length]); new char[length]);
memcpy(b.get(), data, length); memcpy(b.get(), data, length);
...@@ -593,12 +595,12 @@ SvMemoryStream * memoryStream(void const * data, sal_Int32 length) { ...@@ -593,12 +595,12 @@ SvMemoryStream * memoryStream(void const * data, sal_Int32 length) {
new SvMemoryStream(b.get(), length, STREAM_READ)); new SvMemoryStream(b.get(), length, STREAM_READ));
s->ObjectOwnsMemory(true); s->ObjectOwnsMemory(true);
b.release(); b.release();
return s.release(); return s;
} }
} }
SvMemoryStream* INetURLObject::getData() std::unique_ptr<SvMemoryStream> INetURLObject::getData()
{ {
if( GetProtocol() != INET_PROT_DATA ) if( GetProtocol() != INET_PROT_DATA )
{ {
......
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