diff options
| author | Thomas Holder <thomas@thomas-holder.de> | 2018-12-16 10:10:13 +0000 |
|---|---|---|
| committer | Thomas Holder <thomas@thomas-holder.de> | 2018-12-16 10:10:13 +0000 |
| commit | 44a3c91e7eafa402acfd551ee4bf41ed36dfa8f8 (patch) | |
| tree | 6e6b39ba25ea264787772458b6c1e2c7b7f84675 /src/object | |
| parent | add some Inkscape::URI tests (diff) | |
| download | inkscape-44a3c91e7eafa402acfd551ee4bf41ed36dfa8f8.tar.gz inkscape-44a3c91e7eafa402acfd551ee4bf41ed36dfa8f8.zip | |
Inkscape::URI::Impl -> shared_ptr
Diffstat (limited to 'src/object')
| -rw-r--r-- | src/object/uri.cpp | 45 | ||||
| -rw-r--r-- | src/object/uri.h | 38 |
2 files changed, 8 insertions, 75 deletions
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 <exception> #include <libxml/uri.h> +#include <memory> #include <string> namespace Inkscape { @@ -39,11 +39,6 @@ public: URI(); /** - * Copy constructor. - */ - URI(URI const &uri); - - /** * Constructor from a C-style ASCII string. * * @param preformed Properly quoted C-style string to be represented. @@ -55,11 +50,6 @@ public: explicit URI(char const *preformed, URI const &baseuri); /** - * Destructor. - */ - ~URI(); - - /** * Determines if the URI represented is an 'opaque' URI. * * @return \c true if the URI is opaque, \c false if hierarchial. @@ -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<xmlURI> m_shared; + + void init(xmlURI *ptr) { m_shared.reset(ptr, xmlFreeURI); } + + xmlURI *_xmlURIPtr() const { return m_shared.get(); } }; } /* namespace Inkscape */ |
