From: mental Date: Mon, 6 Feb 2006 04:15:05 +0000 (+0000) Subject: replace Util::SharedCStringPtr with the more general Util::shared_ptr<> X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=e7cd2ec3e1687a262ebe95e5ac7a47f8ab147ce2;p=inkscape.git replace Util::SharedCStringPtr with the more general Util::shared_ptr<> --- diff --git a/ChangeLog b/ChangeLog index 5e8c4a837..4f8327931 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2006-02-05 MenTaLguY + + * src/debug/event.h, src/debug/gc-heap.h, src/debug/heap.h, + src/debug/logger.cpp, src/debug/simple-event.h, src/debug/sysv-heap.h, + src/jabber_whiteboard/deserializer.cpp, + src/jabber_whiteboard/message-utilities.cpp, + src/jabber_whiteboard/message-utilities.h, + src/jabber_whiteboard/node-tracker-observer.h, + src/jabber_whiteboard/node-utilities.cpp, + src/jabber_whiteboard/serializer.cpp, + src/jabber_whiteboard/serializer.h, + src/sp-object.cpp, src/util/Makefile_insert, src/util/share.cpp, + src/util/shared-c-string-ptr.cpp, src/util/shared-c-string-ptr.h, + src/util/share.h, src/xml/attribute-record.h, src/xml/comment-node.h, + src/xml/composite-node-observer.cpp, src/xml/composite-node-observer.h, + src/xml/event.cpp, src/xml/event.h, src/xml/log-builder.cpp, + src/xml/log-builder.h, src/xml/node-observer.h, src/xml/repr.cpp, + src/xml/repr-io.cpp, src/xml/simple-node.cpp, src/xml/simple-node.h, + src/xml/simple-session.cpp, src/xml/simple-session.h, + src/xml/text-node.h: + + replace Util::SharedCStringPtr with the nicer and more general + Util::shared_ptr<> + 2006-02-03 Jon Phillips * src/verbs.cpp: Added "..." to "Trace Bitmap" text. Yes, what a diff --git a/src/debug/event.h b/src/debug/event.h index c3b3a83fb..8232f890d 100644 --- a/src/debug/event.h +++ b/src/debug/event.h @@ -13,7 +13,7 @@ #define SEEN_INKSCAPE_DEBUG_EVENT_H #include -#include "util/shared-c-string-ptr.h" +#include "util/share.h" namespace Inkscape { @@ -37,23 +37,23 @@ public: struct PropertyPair { public: PropertyPair() {} - PropertyPair(Util::SharedCStringPtr n, Util::SharedCStringPtr v) + PropertyPair(Util::shared_ptr n, Util::shared_ptr v) : name(n), value(v) {} - PropertyPair(char const *n, Util::SharedCStringPtr v) - : name(Util::SharedCStringPtr::copy(n)), value(v) {} - PropertyPair(Util::SharedCStringPtr n, char const *v) - : name(n), value(Util::SharedCStringPtr::copy(v)) {} + PropertyPair(char const *n, Util::shared_ptr v) + : name(Util::share_string(n)), value(v) {} + PropertyPair(Util::shared_ptr n, char const *v) + : name(n), value(Util::share_string(v)) {} PropertyPair(char const *n, char const *v) - : name(Util::SharedCStringPtr::copy(n)), - value(Util::SharedCStringPtr::copy(v)) {} + : name(Util::share_string(n)), + value(Util::share_string(v)) {} - Util::SharedCStringPtr name; - Util::SharedCStringPtr value; + Util::shared_ptr name; + Util::shared_ptr value; }; static Category category() { return OTHER; } - virtual Util::SharedCStringPtr name() const=0; + virtual Util::shared_ptr name() const=0; virtual unsigned propertyCount() const=0; virtual PropertyPair property(unsigned property) const=0; }; diff --git a/src/debug/gc-heap.h b/src/debug/gc-heap.h index b3042432e..0a9534701 100644 --- a/src/debug/gc-heap.h +++ b/src/debug/gc-heap.h @@ -23,8 +23,8 @@ public: int features() const { return SIZE_AVAILABLE | USED_AVAILABLE | GARBAGE_COLLECTED; } - Util::SharedCStringPtr name() const { - return Util::SharedCStringPtr::coerce("libgc"); + Util::shared_ptr name() const { + return Util::share_static("libgc"); } Heap::Stats stats() const { Stats stats; diff --git a/src/debug/heap.h b/src/debug/heap.h index d07cf74a1..ef563030f 100644 --- a/src/debug/heap.h +++ b/src/debug/heap.h @@ -13,7 +13,7 @@ #define SEEN_INKSCAPE_DEBUG_HEAP_H #include -#include "util/shared-c-string-ptr.h" +#include "util/share.h" namespace Inkscape { @@ -36,7 +36,7 @@ public: virtual int features() const=0; - virtual Util::SharedCStringPtr name() const=0; + virtual Util::shared_ptr name() const=0; virtual Stats stats() const=0; virtual void force_collect()=0; }; diff --git a/src/debug/logger.cpp b/src/debug/logger.cpp index a3c7b0430..6fb1aee05 100644 --- a/src/debug/logger.cpp +++ b/src/debug/logger.cpp @@ -25,7 +25,7 @@ bool Logger::_category_mask[Event::N_CATEGORIES]; namespace { -static void write_escaped_value(std::ostream &os, Util::SharedCStringPtr value) { +static void write_escaped_value(std::ostream &os, Util::shared_ptr value) { for ( char const *current=value ; *current ; ++current ) { switch (*current) { case '&': @@ -57,7 +57,7 @@ static void write_indent(std::ostream &os, unsigned depth) { static std::ofstream log_stream; static bool empty_tag=false; -typedef std::vector > TagStack; +typedef std::vector, GC::Alloc, GC::MANUAL> > TagStack; static TagStack &tag_stack() { static TagStack stack; return stack; @@ -128,7 +128,7 @@ void Logger::init() { log_stream << "\n"; log_stream.flush(); _enabled = true; - start >(Util::SharedCStringPtr::coerce("session")); + start >(Util::share_static("session")); std::atexit(&do_shutdown); } } @@ -136,7 +136,7 @@ void Logger::init() { } void Logger::_start(Event const &event) { - Util::SharedCStringPtr name=event.name(); + Util::shared_ptr name=event.name(); if (empty_tag) { log_stream << ">\n"; @@ -144,12 +144,12 @@ void Logger::_start(Event const &event) { write_indent(log_stream, tag_stack().size()); - log_stream << "<" << name.cString(); + log_stream << "<" << name.pointer(); unsigned property_count=event.propertyCount(); for ( unsigned i = 0 ; i < property_count ; i++ ) { Event::PropertyPair property=event.property(i); - log_stream << " " << property.name.cString() << "=\""; + log_stream << " " << property.name.pointer() << "=\""; write_escaped_value(log_stream, property.value); log_stream << "\""; } @@ -161,7 +161,7 @@ void Logger::_start(Event const &event) { } void Logger::_skip() { - tag_stack().push_back(Util::SharedCStringPtr()); + tag_stack().push_back(Util::shared_ptr()); } void Logger::_finish() { @@ -170,7 +170,7 @@ void Logger::_finish() { log_stream << "/>\n"; } else { write_indent(log_stream, tag_stack().size() - 1); - log_stream << "\n"; + log_stream << "\n"; } log_stream.flush(); diff --git a/src/debug/simple-event.h b/src/debug/simple-event.h index 3a3adae3c..90eed3a0e 100644 --- a/src/debug/simple-event.h +++ b/src/debug/simple-event.h @@ -21,17 +21,17 @@ namespace Debug { template class SimpleEvent : public Event { public: - SimpleEvent(Util::SharedCStringPtr name) : _name(name) {} - SimpleEvent(char const *name) : _name(Util::SharedCStringPtr::copy(name)) {} + SimpleEvent(Util::shared_ptr name) : _name(name) {} + SimpleEvent(char const *name) : _name(Util::share_string(name)) {} static Category category() { return C; } - Util::SharedCStringPtr name() const { return _name; } + Util::shared_ptr name() const { return _name; } unsigned propertyCount() const { return 0; } PropertyPair property(unsigned property) const { return PropertyPair(); } private: - Util::SharedCStringPtr _name; + Util::shared_ptr _name; }; } diff --git a/src/debug/sysv-heap.h b/src/debug/sysv-heap.h index 2ba24b2b5..9a07a3261 100644 --- a/src/debug/sysv-heap.h +++ b/src/debug/sysv-heap.h @@ -23,8 +23,8 @@ public: int features() const; - Util::SharedCStringPtr name() const { - return Util::SharedCStringPtr::coerce("standard malloc()"); + Util::shared_ptr name() const { + return Util::share_static("standard malloc()"); } Stats stats() const; void force_collect() {} diff --git a/src/jabber_whiteboard/deserializer.cpp b/src/jabber_whiteboard/deserializer.cpp index 40047051e..8a6a464b4 100644 --- a/src/jabber_whiteboard/deserializer.cpp +++ b/src/jabber_whiteboard/deserializer.cpp @@ -14,7 +14,7 @@ #include "xml/node.h" #include "xml/repr.h" -#include "util/shared-c-string-ptr.h" +#include "util/share.h" #include "gc-anchored.h" @@ -284,7 +284,7 @@ Deserializer::deserializeEventChgContent(Glib::ustring const& msg) { // 1. Extract required attributes: node ID. If we do not know these, return. std::string id; - Util::SharedCStringPtr oldval, newval; + Util::shared_ptr oldval, newval; Node buf; buf.tag = MESSAGE_ID; @@ -297,16 +297,16 @@ Deserializer::deserializeEventChgContent(Glib::ustring const& msg) // 2. Extract optional attributes: old value, new value. buf.tag = MESSAGE_OLDVAL; if (MessageUtilities::findTag(buf, msg)) { - oldval = Util::SharedCStringPtr::copy(buf.data.c_str()); + oldval = Util::share_string(buf.data.c_str()); } else { - oldval = Util::SharedCStringPtr::copy(""); + oldval = Util::share_static(""); } buf.tag = MESSAGE_NEWVAL; if (MessageUtilities::findTag(buf, msg)) { - newval = Util::SharedCStringPtr::copy(buf.data.c_str()); + newval = Util::share_string(buf.data.c_str()); } else { - newval = Util::SharedCStringPtr::copy(""); + newval = Util::share_static(""); } // 3. Find the node identified by the ID. If we cannot find it, return. @@ -344,21 +344,21 @@ Deserializer::deserializeEventChgAttr(Glib::ustring const& msg) // 2. Extract optional attributes: new value. If we do not find it in the message, // assume there is no new value. buf.tag = MESSAGE_NEWVAL; - Util::SharedCStringPtr newval; + Util::shared_ptr newval; if (MessageUtilities::findTag(buf, msg)) { - newval = Util::SharedCStringPtr::copy(buf.data.c_str()); + newval = Util::share_string(buf.data.c_str()); } else { - newval = Util::SharedCStringPtr::copy(""); + newval = Util::share_static(""); } // 3. Extract optional attributes: old value. If we do not find it in the message, // assume that there is no old value. buf.tag = MESSAGE_OLDVAL; - Util::SharedCStringPtr oldval; + Util::shared_ptr oldval; if (MessageUtilities::findTag(buf, msg)) { - oldval = Util::SharedCStringPtr::copy(buf.data.c_str()); + oldval = Util::share_string(buf.data.c_str()); } else { - oldval = Util::SharedCStringPtr::copy(""); + oldval = Util::share_static(""); } // 4. Look up this node in the local node database and external tracker. diff --git a/src/jabber_whiteboard/message-utilities.cpp b/src/jabber_whiteboard/message-utilities.cpp index 431545ac0..8843b6f45 100644 --- a/src/jabber_whiteboard/message-utilities.cpp +++ b/src/jabber_whiteboard/message-utilities.cpp @@ -12,7 +12,7 @@ #include -#include "util/shared-c-string-ptr.h" +#include "util/share.h" #include "util/list.h" #include "xml/node.h" @@ -297,7 +297,7 @@ MessageUtilities::objectDeleteMessage(Glib::ustring* msgbuf, XMLNodeTracker* xmt } void -MessageUtilities::contentChangeMessage(Glib::ustring& msgbuf, std::string const nodeid, Util::SharedCStringPtr old_value, Util::SharedCStringPtr new_value) +MessageUtilities::contentChangeMessage(Glib::ustring& msgbuf, std::string const nodeid, Util::shared_ptr old_value, Util::shared_ptr new_value) { if (!nodeid.empty()) { // diff --git a/src/jabber_whiteboard/message-utilities.h b/src/jabber_whiteboard/message-utilities.h index 11acb1a95..5595f435c 100644 --- a/src/jabber_whiteboard/message-utilities.h +++ b/src/jabber_whiteboard/message-utilities.h @@ -26,7 +26,7 @@ namespace Inkscape { namespace Util { -class SharedCStringPtr; +class shared_ptr; } @@ -46,7 +46,7 @@ public: static void newObjectMessage(ustring* msgbuf, KeyToNodeMap& newidsbuf, NodeToKeyMap& newnodesbuf, NewChildObjectMessageList& childmsgbuf, XMLNodeTracker* xmt, Inkscape::XML::Node const* node, bool only_collect_nodes = false, bool collect_children = true); static void objectChangeMessage(ustring* msgbuf, XMLNodeTracker* xmt, std::string const id, gchar const* key, gchar const* oldval, gchar const* newval, bool is_interactive); static void objectDeleteMessage(ustring* msgbuf, XMLNodeTracker* xmt, Inkscape::XML::Node const& parent, Inkscape::XML::Node const& child, Inkscape::XML::Node const* prev); - static void contentChangeMessage(ustring& msgbuf, std::string const nodeid, Util::SharedCStringPtr old_value, Util::SharedCStringPtr new_value); + static void contentChangeMessage(ustring& msgbuf, std::string const nodeid, Util::shared_ptr old_value, Util::shared_ptr new_value); static void childOrderChangeMessage(ustring& msgbuf, std::string const childid, std::string const oldprevid, std::string const newprevid); // Message parsing utilities diff --git a/src/jabber_whiteboard/node-tracker-observer.h b/src/jabber_whiteboard/node-tracker-observer.h index 600500c70..a3260d8a0 100644 --- a/src/jabber_whiteboard/node-tracker-observer.h +++ b/src/jabber_whiteboard/node-tracker-observer.h @@ -45,12 +45,12 @@ public: XML::Node *old_prev, XML::Node *new_prev)=0; virtual void notifyContentChanged(XML::Node &node, - Util::SharedCStringPtr old_content, - Util::SharedCStringPtr new_content)=0; + Util::shared_ptr old_content, + Util::shared_ptr new_content)=0; virtual void notifyAttributeChanged(XML::Node &node, GQuark name, - Util::SharedCStringPtr old_value, - Util::SharedCStringPtr new_value)=0; + Util::shared_ptr old_value, + Util::shared_ptr new_value)=0; // ...but we do provide node tracking facilities diff --git a/src/jabber_whiteboard/node-utilities.cpp b/src/jabber_whiteboard/node-utilities.cpp index 35b2772a1..f0cbacddc 100644 --- a/src/jabber_whiteboard/node-utilities.cpp +++ b/src/jabber_whiteboard/node-utilities.cpp @@ -10,7 +10,7 @@ * Released under GNU GPL, read the file 'COPYING' for more information */ -#include "util/shared-c-string-ptr.h" +#include "util/share.h" #include "util/list.h" #include "xml/node-observer.h" diff --git a/src/jabber_whiteboard/serializer.cpp b/src/jabber_whiteboard/serializer.cpp index ddba47299..aae3e1378 100644 --- a/src/jabber_whiteboard/serializer.cpp +++ b/src/jabber_whiteboard/serializer.cpp @@ -14,7 +14,7 @@ #include "jabber_whiteboard/serializer.h" #include "util/list.h" -#include "util/shared-c-string-ptr.h" +#include "util/share.h" #include "jabber_whiteboard/message-utilities.h" #include "jabber_whiteboard/message-tags.h" @@ -91,11 +91,11 @@ Serializer::_newObjectEventHelper(XML::Node& node, XML::Node& child, XML::Node* Inkscape::Util::List attrlist = child.attributeList(); for(; attrlist; attrlist++) { - this->notifyAttributeChanged(child, attrlist->key, Util::SharedCStringPtr(), attrlist->value); + this->notifyAttributeChanged(child, attrlist->key, Util::shared_ptr(), attrlist->value); } if (child.content()) { - this->notifyContentChanged(child, Util::SharedCStringPtr(), Util::SharedCStringPtr::copy(child.content())); + this->notifyContentChanged(child, Util::shared_ptr(), Util::share_string(child.content())); } this->_attributes_scanned.insert(childid); @@ -188,7 +188,7 @@ Serializer::notifyChildOrderChanged(XML::Node& node, XML::Node& child, XML::Node } void -Serializer::notifyContentChanged(XML::Node& node, Util::SharedCStringPtr old_content, Util::SharedCStringPtr new_content) +Serializer::notifyContentChanged(XML::Node& node, Util::shared_ptr old_content, Util::shared_ptr new_content) { // 1. Find the ID of the node, or generate it if it does not exist. std::string nodeid = this->_findOrGenerateNodeID(node); @@ -221,7 +221,7 @@ Serializer::notifyContentChanged(XML::Node& node, Util::SharedCStringPtr old_con } void -Serializer::notifyAttributeChanged(XML::Node& node, GQuark name, Util::SharedCStringPtr old_value, Util::SharedCStringPtr new_value) +Serializer::notifyAttributeChanged(XML::Node& node, GQuark name, Util::shared_ptr old_value, Util::shared_ptr new_value) { // 1. Find the ID of the node that has had an attribute modified, or generate it if it // does not exist. diff --git a/src/jabber_whiteboard/serializer.h b/src/jabber_whiteboard/serializer.h index cc0aa97b6..16889c571 100644 --- a/src/jabber_whiteboard/serializer.h +++ b/src/jabber_whiteboard/serializer.h @@ -14,7 +14,7 @@ #include "xml/node-observer.h" -#include "util/shared-c-string-ptr.h" +#include "util/share.h" #include "jabber_whiteboard/node-tracker.h" #include "jabber_whiteboard/typedefs.h" @@ -39,12 +39,12 @@ public: XML::Node *old_prev, XML::Node *new_prev); void notifyContentChanged(XML::Node &node, - Util::SharedCStringPtr old_content, - Util::SharedCStringPtr new_content); + Util::shared_ptr old_content, + Util::shared_ptr new_content); void notifyAttributeChanged(XML::Node &node, GQuark name, - Util::SharedCStringPtr old_value, - Util::SharedCStringPtr new_value); + Util::shared_ptr old_value, + Util::shared_ptr new_value); void synthesizeChildNodeAddEvents(); diff --git a/src/sp-object.cpp b/src/sp-object.cpp index d23a4d640..d8fe26b87 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -225,16 +225,16 @@ sp_object_finalize(GObject *object) namespace { -Inkscape::Util::SharedCStringPtr stringify(SPObject *obj) { +Inkscape::Util::shared_ptr stringify(SPObject *obj) { char *temp=g_strdup_printf("%p", obj); - Inkscape::Util::SharedCStringPtr result=Inkscape::Util::SharedCStringPtr::copy(temp); + Inkscape::Util::shared_ptr result=Inkscape::Util::share_string(temp); g_free(temp); return result; } -Inkscape::Util::SharedCStringPtr stringify(unsigned n) { +Inkscape::Util::shared_ptr stringify(unsigned n) { char *temp=g_strdup_printf("%u", n); - Inkscape::Util::SharedCStringPtr result=Inkscape::Util::SharedCStringPtr::copy(temp); + Inkscape::Util::shared_ptr result=Inkscape::Util::share_string(temp); g_free(temp); return result; } @@ -250,11 +250,11 @@ public: static Category category() { return REFCOUNT; } - Inkscape::Util::SharedCStringPtr name() const { + Inkscape::Util::shared_ptr name() const { if ( _type == REF) { - return Inkscape::Util::SharedCStringPtr::coerce("sp-object-ref"); + return Inkscape::Util::share_static("sp-object-ref"); } else { - return Inkscape::Util::SharedCStringPtr::coerce("sp-object-unref"); + return Inkscape::Util::share_static("sp-object-unref"); } } unsigned propertyCount() const { return 2; } @@ -270,7 +270,7 @@ public: } private: - Inkscape::Util::SharedCStringPtr _object; + Inkscape::Util::shared_ptr _object; unsigned _refcount; Type _type; }; diff --git a/src/util/Makefile_insert b/src/util/Makefile_insert index 1b7119180..bdd613385 100644 --- a/src/util/Makefile_insert +++ b/src/util/Makefile_insert @@ -14,8 +14,8 @@ util_libinkutil_a_SOURCES = \ util/list-container.h \ util/map-list.h \ util/reverse-list.h \ - util/shared-c-string-ptr.h \ - util/shared-c-string-ptr.cpp \ + util/share.h \ + util/share.cpp \ util/tuple.h \ util/units.cpp \ util/units.h diff --git a/src/util/share.cpp b/src/util/share.cpp new file mode 100644 index 000000000..7f2d09bf6 --- /dev/null +++ b/src/util/share.cpp @@ -0,0 +1,43 @@ +/* + * Inkscape::Util::shared_ptr - like T const *, but stronger + * + * Authors: + * MenTaLguY + * + * Copyright (C) 2006 MenTaLguY + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#include "util/share.h" +#include + +namespace Inkscape { +namespace Util { + +shared_ptr share_string(char const *string) { + g_return_val_if_fail(string != NULL, share_unsafe(NULL)); + return share_string(string, std::strlen(string)); +} + +shared_ptr share_string(char const *string, std::size_t length) { + g_return_val_if_fail(string != NULL, share_unsafe(NULL)); + char *new_string=new (GC::ATOMIC) char[length+1]; + std::memcpy(new_string, string, length); + new_string[length] = 0; + return share_unsafe(new_string); +} + +} +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/util/share.h b/src/util/share.h new file mode 100644 index 000000000..e9e6c5eb0 --- /dev/null +++ b/src/util/share.h @@ -0,0 +1,149 @@ +/* + * Inkscape::Util::shared_ptr - like T const *, but stronger + * + * Authors: + * MenTaLguY + * + * Copyright (C) 2006 MenTaLguY + * + * Released under GNU GPL, read the file 'COPYING' for more information + */ + +#ifndef SEEN_INKSCAPE_UTIL_SHARE_H +#define SEEN_INKSCAPE_UTIL_SHARE_H + +#include "gc-core.h" +#include + +namespace Inkscape { +namespace Util { + +template +class shared_ptr { +public: + shared_ptr() : _obj(NULL) {} + + template + shared_ptr(shared_ptr const &other) : _obj(other._obj) {} + + T const *pointer() const { return _obj; } + + template + operator T1 const *() const { return _obj; } + + operator bool() const { return _obj; } + + T const &operator*() const { return *_obj; } + T const *operator->() const { return _obj; } + T const &operator[](int i) const { return _obj[i]; } + + shared_ptr operator+(int i) const { + return share_unsafe(_obj+i); + } + shared_ptr operator-(int i) const { + return share_unsafe(_obj-i); + } + + shared_ptr &operator+=(int i) const { + _obj += i; + return *this; + } + shared_ptr &operator-=(int i) const { + _obj -= i; + return *this; + } + + template + std::ptrdiff_t operator-(shared_ptr const &other) { + return _obj - other._obj; + } + + template + shared_ptr &operator=(shared_ptr const &other) { + _obj = other._obj; + return *this; + } + + template + bool operator==(shared_ptr const &other) const { + return _obj == other._obj; + } + + template + bool operator!=(shared_ptr const &other) const { + return _obj != other._obj; + } + + template + bool operator>(shared_ptr const &other) const { + return _obj > other._obj; + } + + template + bool operator<(shared_ptr const &other) const { + return _obj < other._obj; + } + + static shared_ptr share_unsafe(T const *obj) { + return shared_ptr(obj); + } + +protected: + explicit shared_ptr(T const *obj) : _obj(obj) {} + +private: + T const *_obj; +}; + +template +inline shared_ptr share(T const *obj) { + return share_unsafe(obj ? new T(*obj) : NULL); +} + +shared_ptr share_string(char const *string); +shared_ptr share_string(char const *string, std::size_t length); + +template +inline shared_ptr reshare(T const *obj) { + return shared_ptr::share_unsafe(obj); +} + +template +inline shared_ptr share_unsafe(T const *obj) { + return shared_ptr::share_unsafe(obj); +} + +template +inline shared_ptr share_static(T const *obj) { + return shared_ptr::share_unsafe(obj); +} + +template +inline shared_ptr static_cast_shared(shared_ptr const &ref) { + return reshare(static_cast(ref.pointer())); +} + +template +inline shared_ptr dynamic_cast_shared(shared_ptr const &ref) { + return reshare(dynamic_cast(ref.pointer())); +} + +template +inline shared_ptr reinterpret_cast_shared(shared_ptr const &ref) { + return reshare(reinterpret_cast(ref.pointer())); +} + +} +} + +#endif +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/util/shared-c-string-ptr.cpp b/src/util/shared-c-string-ptr.cpp deleted file mode 100644 index cedf18df4..000000000 --- a/src/util/shared-c-string-ptr.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Inkscape::Util::SharedCStringPtr - shared and immutable strings - * - * Authors: - * MenTaLguY - * - * Copyright (C) 2004 MenTaLguY - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#include -#include -#include "gc-core.h" -#include "util/shared-c-string-ptr.h" - -namespace Inkscape { - -namespace Util { - -SharedCStringPtr SharedCStringPtr::copy(char const *string) { - g_return_val_if_fail(string != NULL, SharedCStringPtr::coerce(NULL)); - - return SharedCStringPtr::copy(string, std::strlen(string)); -} - -SharedCStringPtr SharedCStringPtr::copy(char const *string, size_t len) { - g_return_val_if_fail(string != NULL, SharedCStringPtr::coerce(NULL)); - - char *dup=new (GC::ATOMIC) gchar[len+1]; - std::memcpy(dup, string, len); - dup[len] = '\000'; - - return SharedCStringPtr::coerce(dup); -} - -} - -} - -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/util/shared-c-string-ptr.h b/src/util/shared-c-string-ptr.h deleted file mode 100644 index b88f4cf99..000000000 --- a/src/util/shared-c-string-ptr.h +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Inkscape::Util::SharedCStringPtr - shared and immutable strings - * - * Authors: - * MenTaLguY - * - * Copyright (C) 2004 MenTaLguY - * - * Released under GNU GPL, read the file 'COPYING' for more information - */ - -#ifndef SEEN_INKSCAPE_UTIL_SHARED_C_STRING_PTR_H -#define SEEN_INKSCAPE_UTIL_SHARED_C_STRING_PTR_H - -#include -#include - -namespace Inkscape { - -namespace Util { - -class SharedCStringPtr { -public: - SharedCStringPtr() : _str(NULL) {} - - operator char const *() const { return cString(); } - - char operator[](size_t i) const { return cString()[i]; } - - char const *cString() const { return _str; } - - static SharedCStringPtr coerce(char const *s) { return SharedCStringPtr(s); } - static SharedCStringPtr copy(char const *s); - static SharedCStringPtr copy(char const *s, size_t len); - - operator bool() const { return _str; } - - bool operator==(SharedCStringPtr const &other) { return _str == other._str; } - bool operator!=(SharedCStringPtr const &other) { return _str != other._str; } - -private: - SharedCStringPtr(char const *s) : _str(s) {} - - char const *_str; -}; - -inline bool operator==(SharedCStringPtr const &ss, char const *s) { - return ss.cString() == s; -} - -inline bool operator==(char const *s, SharedCStringPtr const &ss) { - return operator==(ss, s); -} - -inline bool operator!=(SharedCStringPtr const &ss, char const *s) { - return !operator==(ss, s); -} - -inline bool operator!=(char const *s, SharedCStringPtr const &ss) { - return !operator==(s, ss); -} - -} - -} - -#endif -/* - Local Variables: - mode:c++ - c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) - indent-tabs-mode:nil - fill-column:99 - End: -*/ -// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 : diff --git a/src/xml/attribute-record.h b/src/xml/attribute-record.h index dbad0f340..30d8576d0 100644 --- a/src/xml/attribute-record.h +++ b/src/xml/attribute-record.h @@ -4,7 +4,7 @@ #include #include #include "gc-managed.h" -#include "util/shared-c-string-ptr.h" +#include "util/share.h" #define SP_REPR_ATTRIBUTE_KEY(a) g_quark_to_string((a)->key) #define SP_REPR_ATTRIBUTE_VALUE(a) ((a)->value) @@ -13,11 +13,11 @@ namespace Inkscape { namespace XML { struct AttributeRecord : public Inkscape::GC::Managed<> { - AttributeRecord(GQuark k, Inkscape::Util::SharedCStringPtr v) + AttributeRecord(GQuark k, Inkscape::Util::shared_ptr v) : key(k), value(v) {} GQuark key; - Inkscape::Util::SharedCStringPtr value; + Inkscape::Util::shared_ptr value; // accept default copy constructor and assignment operator }; diff --git a/src/xml/comment-node.h b/src/xml/comment-node.h index dccc5e864..e41a36b59 100644 --- a/src/xml/comment-node.h +++ b/src/xml/comment-node.h @@ -23,7 +23,7 @@ namespace Inkscape { namespace XML { struct CommentNode : public SimpleNode { - explicit CommentNode(Util::SharedCStringPtr content) + explicit CommentNode(Util::shared_ptr content) : SimpleNode(g_quark_from_static_string("comment")) { setContent(content); diff --git a/src/xml/composite-node-observer.cpp b/src/xml/composite-node-observer.cpp index 97bce9360..b564da78d 100644 --- a/src/xml/composite-node-observer.cpp +++ b/src/xml/composite-node-observer.cpp @@ -66,7 +66,7 @@ void CompositeNodeObserver::notifyChildOrderChanged(Node &node, Node &child, void CompositeNodeObserver::notifyContentChanged( Node &node, - Util::SharedCStringPtr old_content, Util::SharedCStringPtr new_content + Util::shared_ptr old_content, Util::shared_ptr new_content ) { _startIteration(); for ( ObserverRecordList::iterator iter=_active.begin() ; @@ -81,7 +81,7 @@ void CompositeNodeObserver::notifyContentChanged( void CompositeNodeObserver::notifyAttributeChanged( Node &node, GQuark name, - Util::SharedCStringPtr old_value, Util::SharedCStringPtr new_value + Util::shared_ptr old_value, Util::shared_ptr new_value ) { _startIteration(); for ( ObserverRecordList::iterator iter=_active.begin() ; @@ -130,13 +130,13 @@ public: } } - void notifyContentChanged(Node &node, Util::SharedCStringPtr old_content, Util::SharedCStringPtr new_content) { + void notifyContentChanged(Node &node, Util::shared_ptr old_content, Util::shared_ptr new_content) { if (vector.content_changed) { vector.content_changed(&node, old_content, new_content, data); } } - void notifyAttributeChanged(Node &node, GQuark name, Util::SharedCStringPtr old_value, Util::SharedCStringPtr new_value) { + void notifyAttributeChanged(Node &node, GQuark name, Util::shared_ptr old_value, Util::shared_ptr new_value) { if (vector.attr_changed) { vector.attr_changed(&node, g_quark_to_string(name), old_value, new_value, false, data); } diff --git a/src/xml/composite-node-observer.h b/src/xml/composite-node-observer.h index 6568a1099..4acde0b4c 100644 --- a/src/xml/composite-node-observer.h +++ b/src/xml/composite-node-observer.h @@ -51,12 +51,12 @@ public: Node *old_prev, Node *new_prev); void notifyContentChanged(Node &node, - Util::SharedCStringPtr old_content, - Util::SharedCStringPtr new_content); + Util::shared_ptr old_content, + Util::shared_ptr new_content); void notifyAttributeChanged(Node &node, GQuark name, - Util::SharedCStringPtr old_value, - Util::SharedCStringPtr new_value); + Util::shared_ptr old_value, + Util::shared_ptr new_value); private: unsigned _iterating; diff --git a/src/xml/event.cpp b/src/xml/event.cpp index c9f0b50a7..dd7167874 100644 --- a/src/xml/event.cpp +++ b/src/xml/event.cpp @@ -114,15 +114,15 @@ public: } void notifyAttributeChanged(Node &node, GQuark name, - Inkscape::Util::SharedCStringPtr old_value, - Inkscape::Util::SharedCStringPtr new_value) + Inkscape::Util::shared_ptr old_value, + Inkscape::Util::shared_ptr new_value) { node.setAttribute(g_quark_to_string(name), new_value); } void notifyContentChanged(Node &node, - Inkscape::Util::SharedCStringPtr old_value, - Inkscape::Util::SharedCStringPtr new_value) + Inkscape::Util::shared_ptr old_value, + Inkscape::Util::shared_ptr new_value) { node.setContent(new_value); } @@ -458,22 +458,22 @@ public: } void notifyAttributeChanged(Node &node, GQuark name, - Inkscape::Util::SharedCStringPtr old_value, - Inkscape::Util::SharedCStringPtr new_value) + Inkscape::Util::shared_ptr old_value, + Inkscape::Util::shared_ptr new_value) { if (new_value) { - g_warning("Event: Set attribute %s to \"%s\" on %s", g_quark_to_string(name), new_value.cString(), node_to_string(node).c_str()); + g_warning("Event: Set attribute %s to \"%s\" on %s", g_quark_to_string(name), new_value.pointer(), node_to_string(node).c_str()); } else { g_warning("Event: Unset attribute %s on %s", g_quark_to_string(name), node_to_string(node).c_str()); } } void notifyContentChanged(Node &node, - Inkscape::Util::SharedCStringPtr old_value, - Inkscape::Util::SharedCStringPtr new_value) + Inkscape::Util::shared_ptr old_value, + Inkscape::Util::shared_ptr new_value) { if (new_value) { - g_warning("Event: Set content of %s to \"%s\"", node_to_string(node).c_str(), new_value.cString()); + g_warning("Event: Set content of %s to \"%s\"", node_to_string(node).c_str(), new_value.pointer()); } else { g_warning("Event: Unset content of %s", node_to_string(node).c_str()); } diff --git a/src/xml/event.h b/src/xml/event.h index e4ce8b26a..56fdb8bb6 100644 --- a/src/xml/event.h +++ b/src/xml/event.h @@ -6,7 +6,7 @@ #include #include -#include "util/shared-c-string-ptr.h" +#include "util/share.h" #include "util/forward-pointer-iterator.h" #include "gc-managed.h" #include "xml/node.h" @@ -96,15 +96,15 @@ private: class EventChgAttr : public Event { public: EventChgAttr(Node *repr, GQuark k, - Inkscape::Util::SharedCStringPtr ov, - Inkscape::Util::SharedCStringPtr nv, + Inkscape::Util::shared_ptr ov, + Inkscape::Util::shared_ptr nv, Event *next) : Event(repr, next), key(k), oldval(ov), newval(nv) {} GQuark key; - Inkscape::Util::SharedCStringPtr oldval; - Inkscape::Util::SharedCStringPtr newval; + Inkscape::Util::shared_ptr oldval; + Inkscape::Util::shared_ptr newval; private: Event *_optimizeOne(); @@ -115,13 +115,13 @@ private: class EventChgContent : public Event { public: EventChgContent(Node *repr, - Inkscape::Util::SharedCStringPtr ov, - Inkscape::Util::SharedCStringPtr nv, + Inkscape::Util::shared_ptr ov, + Inkscape::Util::shared_ptr nv, Event *next) : Event(repr, next), oldval(ov), newval(nv) {} - Inkscape::Util::SharedCStringPtr oldval; - Inkscape::Util::SharedCStringPtr newval; + Inkscape::Util::shared_ptr oldval; + Inkscape::Util::shared_ptr newval; private: Event *_optimizeOne(); diff --git a/src/xml/log-builder.cpp b/src/xml/log-builder.cpp index b3d8db59f..97451075a 100644 --- a/src/xml/log-builder.cpp +++ b/src/xml/log-builder.cpp @@ -48,16 +48,16 @@ void LogBuilder::setChildOrder(Node &node, Node &child, } void LogBuilder::setContent(Node &node, - Util::SharedCStringPtr old_content, - Util::SharedCStringPtr new_content) + Util::shared_ptr old_content, + Util::shared_ptr new_content) { _log = new Inkscape::XML::EventChgContent(&node, old_content, new_content, _log); _log = _log->optimizeOne(); } void LogBuilder::setAttribute(Node &node, GQuark name, - Util::SharedCStringPtr old_value, - Util::SharedCStringPtr new_value) + Util::shared_ptr old_value, + Util::shared_ptr new_value) { _log = new Inkscape::XML::EventChgAttr(&node, name, old_value, new_value, _log); _log = _log->optimizeOne(); diff --git a/src/xml/log-builder.h b/src/xml/log-builder.h index 1f1ea1959..dc68a4f4a 100644 --- a/src/xml/log-builder.h +++ b/src/xml/log-builder.h @@ -39,12 +39,12 @@ public: Node *old_prev, Node *new_prev); void setContent(Node &node, - Util::SharedCStringPtr old_content, - Util::SharedCStringPtr new_content); + Util::shared_ptr old_content, + Util::shared_ptr new_content); void setAttribute(Node &node, GQuark name, - Util::SharedCStringPtr old_value, - Util::SharedCStringPtr new_value); + Util::shared_ptr old_value, + Util::shared_ptr new_value); private: Event *_log; diff --git a/src/xml/node-observer.h b/src/xml/node-observer.h index 4a884b8a9..e50a41dd8 100644 --- a/src/xml/node-observer.h +++ b/src/xml/node-observer.h @@ -16,7 +16,7 @@ #define SEEN_INKSCAPE_XML_NODE_OBSERVER_H #include -#include "util/shared-c-string-ptr.h" +#include "util/share.h" namespace Inkscape { namespace XML { @@ -43,12 +43,12 @@ public: Node *old_prev, Node *new_prev)=0; virtual void notifyContentChanged(Node &node, - Util::SharedCStringPtr old_content, - Util::SharedCStringPtr new_content)=0; + Util::shared_ptr old_content, + Util::shared_ptr new_content)=0; virtual void notifyAttributeChanged(Node &node, GQuark name, - Util::SharedCStringPtr old_value, - Util::SharedCStringPtr new_value)=0; + Util::shared_ptr old_value, + Util::shared_ptr new_value)=0; }; } diff --git a/src/xml/repr-io.cpp b/src/xml/repr-io.cpp index bb62393fc..884bb3360 100644 --- a/src/xml/repr-io.cpp +++ b/src/xml/repr-io.cpp @@ -585,7 +585,7 @@ repr_quote_write (Writer &out, const gchar * val) namespace { typedef std::map LocalNameMap; -typedef std::map NSMap; +typedef std::map, Inkscape::compare_quark_ids> NSMap; gchar const *qname_local_name(Glib::QueryQuark qname) { static LocalNameMap local_name_map; @@ -604,7 +604,8 @@ gchar const *qname_local_name(Glib::QueryQuark qname) { } void add_ns_map_entry(NSMap &ns_map, Glib::QueryQuark prefix) { - using Inkscape::Util::SharedCStringPtr; + using Inkscape::Util::shared_ptr; + using Inkscape::Util::share_unsafe; static const Glib::QueryQuark xml_prefix("xml"); @@ -613,12 +614,12 @@ void add_ns_map_entry(NSMap &ns_map, Glib::QueryQuark prefix) { if (prefix.id()) { gchar const *uri=sp_xml_ns_prefix_uri(g_quark_to_string(prefix)); if (uri) { - ns_map.insert(NSMap::value_type(prefix, SharedCStringPtr::coerce(uri))); + ns_map.insert(NSMap::value_type(prefix, share_unsafe(uri))); } else if ( prefix != xml_prefix ) { g_warning("No namespace known for normalized prefix %s", g_quark_to_string(prefix)); } } else { - ns_map.insert(NSMap::value_type(prefix, SharedCStringPtr())); + ns_map.insert(NSMap::value_type(prefix, shared_ptr())); } } } @@ -647,7 +648,7 @@ void populate_ns_map(NSMap &ns_map, Node &repr) { void sp_repr_write_stream_root_element (Node *repr, Writer &out, gboolean add_whitespace, gchar const *default_ns) { - using Inkscape::Util::SharedCStringPtr; + using Inkscape::Util::shared_ptr; g_assert(repr != NULL); Glib::QueryQuark xml_prefix=g_quark_from_static_string("xml"); @@ -663,7 +664,7 @@ sp_repr_write_stream_root_element (Node *repr, Writer &out, gboolean add_whitesp for ( NSMap::iterator iter=ns_map.begin() ; iter != ns_map.end() ; ++iter ) { Glib::QueryQuark prefix=(*iter).first; - SharedCStringPtr ns_uri=(*iter).second; + shared_ptr ns_uri=(*iter).second; if (prefix.id()) { if ( prefix != xml_prefix ) { diff --git a/src/xml/repr.cpp b/src/xml/repr.cpp index 2cd770a52..9612bb858 100644 --- a/src/xml/repr.cpp +++ b/src/xml/repr.cpp @@ -28,7 +28,7 @@ #include "xml/comment-node.h" #include "xml/simple-document.h" -using Inkscape::Util::SharedCStringPtr; +using Inkscape::Util::share_string; /// Returns new node. Inkscape::XML::Node * @@ -45,7 +45,7 @@ Inkscape::XML::Node * sp_repr_new_text(gchar const *content) { g_return_val_if_fail(content != NULL, NULL); - return new Inkscape::XML::TextNode(SharedCStringPtr::copy(content)); + return new Inkscape::XML::TextNode(share_string(content)); } /// Returns new commentnode with comment. See Inkscape::XML::CommentNode. @@ -53,7 +53,7 @@ Inkscape::XML::Node * sp_repr_new_comment(gchar const *comment) { g_return_val_if_fail(comment != NULL, NULL); - return new Inkscape::XML::CommentNode(SharedCStringPtr::copy(comment)); + return new Inkscape::XML::CommentNode(share_string(comment)); } /// Returns new document having as first child a node named rootname. diff --git a/src/xml/simple-node.cpp b/src/xml/simple-node.cpp index d3e047431..5e21f941e 100644 --- a/src/xml/simple-node.cpp +++ b/src/xml/simple-node.cpp @@ -28,7 +28,7 @@ namespace XML { namespace { -Util::SharedCStringPtr stringify_node(Node const &node) { +Util::shared_ptr stringify_node(Node const &node) { gchar *string; switch (node.type()) { case ELEMENT_NODE: { @@ -51,14 +51,14 @@ Util::SharedCStringPtr stringify_node(Node const &node) { default: string = g_strdup_printf("unknown(%p)", &node); } - Util::SharedCStringPtr result=Util::SharedCStringPtr::copy(string); + Util::shared_ptr result=Util::share_string(string); g_free(string); return result; } -Util::SharedCStringPtr stringify_unsigned(unsigned n) { +Util::shared_ptr stringify_unsigned(unsigned n) { gchar *string = g_strdup_printf("%u", n); - Util::SharedCStringPtr result=Util::SharedCStringPtr::copy(string); + Util::shared_ptr result=Util::share_string(string); g_free(string); return result; } @@ -75,8 +75,8 @@ public: static Category category() { return XML; } - Util::SharedCStringPtr name() const { - return Util::SharedCStringPtr::coerce("add-child"); + Util::shared_ptr name() const { + return Util::share_static("add-child"); } unsigned propertyCount() const { return 3; } PropertyPair property(unsigned i) const { @@ -92,8 +92,8 @@ public: } } private: - Util::SharedCStringPtr _parent; - Util::SharedCStringPtr _child; + Util::shared_ptr _parent; + Util::shared_ptr _child; unsigned _position; }; @@ -106,8 +106,8 @@ public: static Category category() { return XML; } - Util::SharedCStringPtr name() const { - return Util::SharedCStringPtr::coerce("remove-child"); + Util::shared_ptr name() const { + return Util::share_static("remove-child"); } unsigned propertyCount() const { return 2; } PropertyPair property(unsigned i) const { @@ -121,8 +121,8 @@ public: } } private: - Util::SharedCStringPtr _parent; - Util::SharedCStringPtr _child; + Util::shared_ptr _parent; + Util::shared_ptr _child; }; class DebugSetChildPosition : public Debug::Event { @@ -140,8 +140,8 @@ public: static Category category() { return XML; } - Util::SharedCStringPtr name() const { - return Util::SharedCStringPtr::coerce("set-child-position"); + Util::shared_ptr name() const { + return Util::share_static("set-child-position"); } unsigned propertyCount() const { return 3; } PropertyPair property(unsigned i) const { @@ -157,25 +157,25 @@ public: } } private: - Util::SharedCStringPtr _parent; - Util::SharedCStringPtr _child; + Util::shared_ptr _parent; + Util::shared_ptr _child; unsigned _position; }; class DebugSetContent : public Debug::Event { public: DebugSetContent(Node const &node, - Util::SharedCStringPtr old_content, - Util::SharedCStringPtr new_content) + Util::shared_ptr old_content, + Util::shared_ptr new_content) : _node(stringify_node(node)), _content(new_content) {} static Category category() { return XML; } - Util::SharedCStringPtr name() const { + Util::shared_ptr name() const { if (_content) { - return Util::SharedCStringPtr::coerce("set-content"); + return Util::share_static("set-content"); } else { - return Util::SharedCStringPtr::coerce("clear-content"); + return Util::share_static("clear-content"); } } unsigned propertyCount() const { @@ -196,26 +196,26 @@ public: } } private: - Util::SharedCStringPtr _node; - Util::SharedCStringPtr _content; + Util::shared_ptr _node; + Util::shared_ptr _content; }; class DebugSetAttribute : public Debug::Event { public: DebugSetAttribute(Node const &node, GQuark name, - Util::SharedCStringPtr old_value, - Util::SharedCStringPtr new_value) + Util::shared_ptr old_value, + Util::shared_ptr new_value) : _node(stringify_node(node)), - _name(Util::SharedCStringPtr::coerce(g_quark_to_string(name))), + _name(Util::share_unsafe(g_quark_to_string(name))), _value(new_value) {} static Category category() { return XML; } - Util::SharedCStringPtr name() const { + Util::shared_ptr name() const { if (_value) { - return Util::SharedCStringPtr::coerce("set-attribute"); + return Util::share_static("set-attribute"); } else { - return Util::SharedCStringPtr::coerce("clear-attribute"); + return Util::share_static("clear-attribute"); } } unsigned propertyCount() const { @@ -239,12 +239,15 @@ public: } private: - Util::SharedCStringPtr _node; - Util::SharedCStringPtr _name; - Util::SharedCStringPtr _value; + Util::shared_ptr _node; + Util::shared_ptr _name; + Util::shared_ptr _value; }; -using Inkscape::Util::SharedCStringPtr; +using Inkscape::Util::shared_ptr; +using Inkscape::Util::share_string; +using Inkscape::Util::share_unsafe; +using Inkscape::Util::share_static; using Inkscape::Util::List; using Inkscape::Util::MutableList; using Inkscape::Util::cons; @@ -363,8 +366,8 @@ bool SimpleNode::matchAttributeName(gchar const *partial_name) const { } void SimpleNode::setContent(gchar const *content) { - SharedCStringPtr old_content=_content; - SharedCStringPtr new_content = ( content ? SharedCStringPtr::copy(content) : SharedCStringPtr() ); + shared_ptr old_content=_content; + shared_ptr new_content = ( content ? share_string(content) : shared_ptr() ); Debug::EventTracker tracker( *this, old_content, new_content @@ -399,11 +402,11 @@ SimpleNode::setAttribute(gchar const *name, gchar const *value, bool const is_in Debug::EventTracker<> tracker; - SharedCStringPtr old_value=( existing ? existing->value : SharedCStringPtr() ); + shared_ptr old_value=( existing ? existing->value : shared_ptr() ); - SharedCStringPtr new_value=SharedCStringPtr(); + shared_ptr new_value=shared_ptr(); if (value) { - new_value = SharedCStringPtr::copy(value); + new_value = share_string(value); tracker.set(*this, key, old_value, new_value); if (!existing) { if (ref) { @@ -613,11 +616,11 @@ void child_removed(Node *node, Node *child, Node *ref, void *data) { } void content_changed(Node *node, gchar const *old_content, gchar const *new_content, void *data) { - reinterpret_cast(data)->notifyContentChanged(*node, Util::SharedCStringPtr::coerce((const char *)old_content), Util::SharedCStringPtr::coerce((const char *)new_content)); + reinterpret_cast(data)->notifyContentChanged(*node, Util::share_unsafe((const char *)old_content), Util::share_unsafe((const char *)new_content)); } void attr_changed(Node *node, gchar const *name, gchar const *old_value, gchar const *new_value, bool is_interactive, void *data) { - reinterpret_cast(data)->notifyAttributeChanged(*node, g_quark_from_string(name), Util::SharedCStringPtr::coerce((const char *)old_value), Util::SharedCStringPtr::coerce((const char *)new_value)); + reinterpret_cast(data)->notifyAttributeChanged(*node, g_quark_from_string(name), Util::share_unsafe((const char *)old_value), Util::share_unsafe((const char *)new_value)); } void order_changed(Node *node, Node *child, Node *old_ref, Node *new_ref, void *data) { diff --git a/src/xml/simple-node.h b/src/xml/simple-node.h index 75fe1db07..f1cf78680 100644 --- a/src/xml/simple-node.h +++ b/src/xml/simple-node.h @@ -140,7 +140,7 @@ private: Inkscape::Util::MutableList _attributes; - Inkscape::Util::SharedCStringPtr _content; + Inkscape::Util::shared_ptr _content; unsigned _child_count; mutable bool _cached_positions_valid; diff --git a/src/xml/simple-session.cpp b/src/xml/simple-session.cpp index 76caf1e54..c8d873fd2 100644 --- a/src/xml/simple-session.cpp +++ b/src/xml/simple-session.cpp @@ -52,11 +52,11 @@ Node *SimpleSession::createElementNode(char const *name) { } Node *SimpleSession::createTextNode(char const *content) { - return new TextNode(Util::SharedCStringPtr::copy(content)); + return new TextNode(Util::share_string(content)); } Node *SimpleSession::createCommentNode(char const *content) { - return new CommentNode(Util::SharedCStringPtr::copy(content)); + return new CommentNode(Util::share_string(content)); } void SimpleSession::notifyChildAdded(Node &parent, @@ -88,8 +88,8 @@ void SimpleSession::notifyChildOrderChanged(Node &parent, } void SimpleSession::notifyContentChanged(Node &node, - Util::SharedCStringPtr old_content, - Util::SharedCStringPtr new_content) + Util::shared_ptr old_content, + Util::shared_ptr new_content) { if (_in_transaction) { _log_builder.setContent(node, old_content, new_content); @@ -98,8 +98,8 @@ void SimpleSession::notifyContentChanged(Node &node, void SimpleSession::notifyAttributeChanged(Node &node, GQuark name, - Util::SharedCStringPtr old_value, - Util::SharedCStringPtr new_value) + Util::shared_ptr old_value, + Util::shared_ptr new_value) { if (_in_transaction) { _log_builder.setAttribute(node, name, old_value, new_value); diff --git a/src/xml/simple-session.h b/src/xml/simple-session.h index 5e9e3a7c1..9e3693d9a 100644 --- a/src/xml/simple-session.h +++ b/src/xml/simple-session.h @@ -52,12 +52,12 @@ public: Inkscape::XML::Node *old_prev, Inkscape::XML::Node *new_prev); void notifyContentChanged(Inkscape::XML::Node &node, - Util::SharedCStringPtr old_content, - Util::SharedCStringPtr new_content); + Util::shared_ptr old_content, + Util::shared_ptr new_content); void notifyAttributeChanged(Inkscape::XML::Node &node, GQuark name, - Util::SharedCStringPtr old_value, - Util::SharedCStringPtr new_value); + Util::shared_ptr old_value, + Util::shared_ptr new_value); private: SimpleSession(SimpleSession const &); // no copy diff --git a/src/xml/text-node.h b/src/xml/text-node.h index c07d70f65..bcd1c3e4f 100644 --- a/src/xml/text-node.h +++ b/src/xml/text-node.h @@ -23,7 +23,7 @@ namespace Inkscape { namespace XML { struct TextNode : public SimpleNode { - TextNode(Util::SharedCStringPtr content) + TextNode(Util::shared_ptr content) : SimpleNode(g_quark_from_static_string("string")) { setContent(content);