From 44a3c91e7eafa402acfd551ee4bf41ed36dfa8f8 Mon Sep 17 00:00:00 2001 From: Thomas Holder Date: Sun, 16 Dec 2018 11:10:13 +0100 Subject: Inkscape::URI::Impl -> shared_ptr --- src/object/uri.cpp | 45 ++------------------------------------------- src/object/uri.h | 38 ++++++-------------------------------- 2 files changed, 8 insertions(+), 75 deletions(-) (limited to 'src/object') diff --git a/src/object/uri.cpp b/src/object/uri.cpp index 2604ee640..df55508da 100644 --- a/src/object/uri.cpp +++ b/src/object/uri.cpp @@ -43,12 +43,7 @@ static bool uri_needs_escaping(char const *uri) } URI::URI() { - _impl = Impl::create(xmlCreateURI()); -} - -URI::URI(const URI &uri) { - uri._impl->reference(); - _impl = uri._impl; + init(xmlCreateURI()); } URI::URI(gchar const *preformed, char const *baseuri) @@ -96,7 +91,7 @@ URI::URI(gchar const *preformed, char const *baseuri) if (!uri) { throw MalformedURIException(); } - _impl = Impl::create(uri); + init(uri); } URI::URI(char const *preformed, URI const &baseuri) @@ -104,42 +99,6 @@ URI::URI(char const *preformed, URI const &baseuri) { } -URI::~URI() { - _impl->unreference(); -} - -URI &URI::operator=(URI const &uri) { -// No check for self-assignment needed, as _impl refcounting increments first. - uri._impl->reference(); - _impl->unreference(); - _impl = uri._impl; - return *this; -} - -URI::Impl *URI::Impl::create(xmlURIPtr uri) { - return new Impl(uri); -} - -URI::Impl::Impl(xmlURIPtr uri) -: _refcount(1), _uri(uri) {} - -URI::Impl::~Impl() { - if (_uri) { - xmlFreeURI(_uri); - _uri = nullptr; - } -} - -void URI::Impl::reference() { - _refcount++; -} - -void URI::Impl::unreference() { - if (!--_refcount) { - delete this; - } -} - // From RFC 2396: // // URI-reference = [ absoluteURI | relativeURI ] [ "#" fragment ] diff --git a/src/object/uri.h b/src/object/uri.h index 4650be137..2e627cb59 100644 --- a/src/object/uri.h +++ b/src/object/uri.h @@ -12,8 +12,8 @@ #ifndef INKSCAPE_URI_H #define INKSCAPE_URI_H -#include #include +#include #include namespace Inkscape { @@ -38,11 +38,6 @@ public: /* Blank constructor */ URI(); - /** - * Copy constructor. - */ - URI(URI const &uri); - /** * Constructor from a C-style ASCII string. * @@ -54,11 +49,6 @@ public: explicit URI(char const *preformed, char const *baseuri = nullptr); explicit URI(char const *preformed, URI const &baseuri); - /** - * Destructor. - */ - ~URI(); - /** * Determines if the URI represented is an 'opaque' URI. * @@ -191,28 +181,12 @@ public: */ bool hasScheme(const char *scheme) const; - /** - * Assignment operator. - */ - URI &operator=(URI const &uri); - private: - class Impl { - public: - static Impl *create(xmlURIPtr uri); - void reference(); - void unreference(); - - private: - Impl(xmlURIPtr uri); - ~Impl(); - int _refcount; - public: - xmlURIPtr _uri; - }; - Impl *_impl; - - xmlURIPtr _xmlURIPtr() const { return _impl->_uri; } + std::shared_ptr m_shared; + + void init(xmlURI *ptr) { m_shared.reset(ptr, xmlFreeURI); } + + xmlURI *_xmlURIPtr() const { return m_shared.get(); } }; } /* namespace Inkscape */ -- cgit v1.2.3