summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2006-02-06 04:15:05 +0000
committermental <mental@users.sourceforge.net>2006-02-06 04:15:05 +0000
commit4f46bb0e09ddfa540b60bd4d152385729127aceb (patch)
tree7b30dc6f0d64d847c422352d23ef1187ec04802a /src
parentsilence warnings (diff)
downloadinkscape-4f46bb0e09ddfa540b60bd4d152385729127aceb.tar.gz
inkscape-4f46bb0e09ddfa540b60bd4d152385729127aceb.zip
replace Util::SharedCStringPtr with the more general Util::shared_ptr<>
(bzr r87)
Diffstat (limited to 'src')
-rw-r--r--src/debug/event.h22
-rw-r--r--src/debug/gc-heap.h4
-rw-r--r--src/debug/heap.h4
-rw-r--r--src/debug/logger.cpp16
-rw-r--r--src/debug/simple-event.h8
-rw-r--r--src/debug/sysv-heap.h4
-rw-r--r--src/jabber_whiteboard/deserializer.cpp24
-rw-r--r--src/jabber_whiteboard/message-utilities.cpp4
-rw-r--r--src/jabber_whiteboard/message-utilities.h4
-rw-r--r--src/jabber_whiteboard/node-tracker-observer.h8
-rw-r--r--src/jabber_whiteboard/node-utilities.cpp2
-rw-r--r--src/jabber_whiteboard/serializer.cpp10
-rw-r--r--src/jabber_whiteboard/serializer.h10
-rw-r--r--src/sp-object.cpp16
-rw-r--r--src/util/Makefile_insert4
-rw-r--r--src/util/share.cpp43
-rw-r--r--src/util/share.h149
-rw-r--r--src/util/shared-c-string-ptr.cpp50
-rw-r--r--src/util/shared-c-string-ptr.h77
-rw-r--r--src/xml/attribute-record.h6
-rw-r--r--src/xml/comment-node.h2
-rw-r--r--src/xml/composite-node-observer.cpp8
-rw-r--r--src/xml/composite-node-observer.h8
-rw-r--r--src/xml/event.cpp20
-rw-r--r--src/xml/event.h18
-rw-r--r--src/xml/log-builder.cpp8
-rw-r--r--src/xml/log-builder.h8
-rw-r--r--src/xml/node-observer.h10
-rw-r--r--src/xml/repr-io.cpp13
-rw-r--r--src/xml/repr.cpp6
-rw-r--r--src/xml/simple-node.cpp83
-rw-r--r--src/xml/simple-node.h2
-rw-r--r--src/xml/simple-session.cpp12
-rw-r--r--src/xml/simple-session.h8
-rw-r--r--src/xml/text-node.h2
35 files changed, 371 insertions, 302 deletions
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 <utility>
-#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<char> n, Util::shared_ptr<char> 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<char> v)
+ : name(Util::share_string(n)), value(v) {}
+ PropertyPair(Util::shared_ptr<char> 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<char> name;
+ Util::shared_ptr<char> value;
};
static Category category() { return OTHER; }
- virtual Util::SharedCStringPtr name() const=0;
+ virtual Util::shared_ptr<char> 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<char> 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 <cstddef>
-#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<char> 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<char> 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<Util::SharedCStringPtr, GC::Alloc<Util::SharedCStringPtr, GC::MANUAL> > TagStack;
+typedef std::vector<Util::shared_ptr<char>, GC::Alloc<Util::shared_ptr<char>, GC::MANUAL> > TagStack;
static TagStack &tag_stack() {
static TagStack stack;
return stack;
@@ -128,7 +128,7 @@ void Logger::init() {
log_stream << "<?xml version=\"1.0\"?>\n";
log_stream.flush();
_enabled = true;
- start<SimpleEvent<Event::CORE> >(Util::SharedCStringPtr::coerce("session"));
+ start<SimpleEvent<Event::CORE> >(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<char> 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<char>());
}
void Logger::_finish() {
@@ -170,7 +170,7 @@ void Logger::_finish() {
log_stream << "/>\n";
} else {
write_indent(log_stream, tag_stack().size() - 1);
- log_stream << "</" << tag_stack().back().cString() << ">\n";
+ log_stream << "</" << tag_stack().back().pointer() << ">\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 <Event::Category C=Event::OTHER>
class SimpleEvent : public Event {
public:
- SimpleEvent(Util::SharedCStringPtr name) : _name(name) {}
- SimpleEvent(char const *name) : _name(Util::SharedCStringPtr::copy(name)) {}
+ SimpleEvent(Util::shared_ptr<char> 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<char> name() const { return _name; }
unsigned propertyCount() const { return 0; }
PropertyPair property(unsigned property) const { return PropertyPair(); }
private:
- Util::SharedCStringPtr _name;
+ Util::shared_ptr<char> _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<char> 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<char> 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<char> 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<char> 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 <glibmm/i18n.h>
-#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<char> old_value, Util::shared_ptr<char> new_value)
{
if (!nodeid.empty()) {
// <MESSAGE_NODECONTENT>
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<char>;
}
@@ -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<char> old_value, Util::shared_ptr<char> 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<char> old_content,
+ Util::shared_ptr<char> new_content)=0;
virtual void notifyAttributeChanged(XML::Node &node, GQuark name,
- Util::SharedCStringPtr old_value,
- Util::SharedCStringPtr new_value)=0;
+ Util::shared_ptr<char> old_value,
+ Util::shared_ptr<char> 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<Inkscape::XML::AttributeRecord const> attrlist = child.attributeList();
for(; attrlist; attrlist++) {
- this->notifyAttributeChanged(child, attrlist->key, Util::SharedCStringPtr(), attrlist->value);
+ this->notifyAttributeChanged(child, attrlist->key, Util::shared_ptr<char>(), attrlist->value);
}
if (child.content()) {
- this->notifyContentChanged(child, Util::SharedCStringPtr(), Util::SharedCStringPtr::copy(child.content()));
+ this->notifyContentChanged(child, Util::shared_ptr<char>(), 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<char> old_content, Util::shared_ptr<char> 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<char> old_value, Util::shared_ptr<char> 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<char> old_content,
+ Util::shared_ptr<char> new_content);
void notifyAttributeChanged(XML::Node &node, GQuark name,
- Util::SharedCStringPtr old_value,
- Util::SharedCStringPtr new_value);
+ Util::shared_ptr<char> old_value,
+ Util::shared_ptr<char> 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<char> stringify(SPObject *obj) {
char *temp=g_strdup_printf("%p", obj);
- Inkscape::Util::SharedCStringPtr result=Inkscape::Util::SharedCStringPtr::copy(temp);
+ Inkscape::Util::shared_ptr<char> result=Inkscape::Util::share_string(temp);
g_free(temp);
return result;
}
-Inkscape::Util::SharedCStringPtr stringify(unsigned n) {
+Inkscape::Util::shared_ptr<char> stringify(unsigned n) {
char *temp=g_strdup_printf("%u", n);
- Inkscape::Util::SharedCStringPtr result=Inkscape::Util::SharedCStringPtr::copy(temp);
+ Inkscape::Util::shared_ptr<char> 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<char> 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<char> _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<T> - like T const *, but stronger
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * Copyright (C) 2006 MenTaLguY
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#include "util/share.h"
+#include <glib/gmessages.h>
+
+namespace Inkscape {
+namespace Util {
+
+shared_ptr<char> share_string(char const *string) {
+ g_return_val_if_fail(string != NULL, share_unsafe<char>(NULL));
+ return share_string(string, std::strlen(string));
+}
+
+shared_ptr<char> share_string(char const *string, std::size_t length) {
+ g_return_val_if_fail(string != NULL, share_unsafe<char>(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<T> - like T const *, but stronger
+ *
+ * Authors:
+ * MenTaLguY <mental@rydia.net>
+ *
+ * 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 <cstring>
+
+namespace Inkscape {
+namespace Util {
+
+template <typename T>
+class shared_ptr {
+public:
+ shared_ptr() : _obj(NULL) {}
+
+ template <typename T1>
+ shared_ptr(shared_ptr<T1> const &other) : _obj(other._obj) {}
+
+ T const *pointer() const { return _obj; }
+
+ template <typename T1>
+ 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<T> operator+(int i) const {
+ return share_unsafe(_obj+i);
+ }
+ shared_ptr<T> operator-(int i) const {
+ return share_unsafe(_obj-i);
+ }
+
+ shared_ptr<T> &operator+=(int i) const {
+ _obj += i;
+ return *this;
+ }
+ shared_ptr<T> &operator-=(int i) const {
+ _obj -= i;
+ return *this;
+ }
+
+ template <typename T1>
+ std::ptrdiff_t operator-(shared_ptr<T1> const &other) {
+ return _obj - other._obj;
+ }
+
+ template <typename T1>
+ shared_ptr<T> &operator=(shared_ptr<T1> const &other) {
+ _obj = other._obj;
+ return *this;
+ }
+
+ template <typename T1>
+ bool operator==(shared_ptr<T1> const &other) const {
+ return _obj == other._obj;
+ }
+
+ template <typename T1>
+ bool operator!=(shared_ptr<T1> const &other) const {
+ return _obj != other._obj;
+ }
+
+ template <typename T1>
+ bool operator>(shared_ptr<T1> const &other) const {
+ return _obj > other._obj;
+ }
+
+ template <typename T1>
+ bool operator<(shared_ptr<T1> const &other) const {
+ return _obj < other._obj;
+ }
+
+ static shared_ptr<T> share_unsafe(T const *obj) {
+ return shared_ptr<T>(obj);
+ }
+
+protected:
+ explicit shared_ptr(T const *obj) : _obj(obj) {}
+
+private:
+ T const *_obj;
+};
+
+template <typename T>
+inline shared_ptr<T> share(T const *obj) {
+ return share_unsafe(obj ? new T(*obj) : NULL);
+}
+
+shared_ptr<char> share_string(char const *string);
+shared_ptr<char> share_string(char const *string, std::size_t length);
+
+template <typename T>
+inline shared_ptr<T> reshare(T const *obj) {
+ return shared_ptr<T>::share_unsafe(obj);
+}
+
+template <typename T>
+inline shared_ptr<T> share_unsafe(T const *obj) {
+ return shared_ptr<T>::share_unsafe(obj);
+}
+
+template <typename T>
+inline shared_ptr<T> share_static(T const *obj) {
+ return shared_ptr<T>::share_unsafe(obj);
+}
+
+template <typename T1, typename T2>
+inline shared_ptr<T1> static_cast_shared(shared_ptr<T2> const &ref) {
+ return reshare(static_cast<T1 const *>(ref.pointer()));
+}
+
+template <typename T1, typename T2>
+inline shared_ptr<T1> dynamic_cast_shared(shared_ptr<T2> const &ref) {
+ return reshare(dynamic_cast<T1 const *>(ref.pointer()));
+}
+
+template <typename T1, typename T2>
+inline shared_ptr<T1> reinterpret_cast_shared(shared_ptr<T2> const &ref) {
+ return reshare(reinterpret_cast<T1 const *>(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 <mental@rydia.net>
- *
- * Copyright (C) 2004 MenTaLguY
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#include <cstring>
-#include <glib/gmessages.h>
-#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 <mental@rydia.net>
- *
- * 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 <sys/types.h>
-#include <glib/gtypes.h>
-
-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 <glib/gquark.h>
#include <glib/gtypes.h>
#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<char> v)
: key(k), value(v) {}
GQuark key;
- Inkscape::Util::SharedCStringPtr value;
+ Inkscape::Util::shared_ptr<char> 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<char> 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<char> old_content, Util::shared_ptr<char> 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<char> old_value, Util::shared_ptr<char> 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<char> old_content, Util::shared_ptr<char> 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<char> old_value, Util::shared_ptr<char> 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<char> old_content,
+ Util::shared_ptr<char> new_content);
void notifyAttributeChanged(Node &node, GQuark name,
- Util::SharedCStringPtr old_value,
- Util::SharedCStringPtr new_value);
+ Util::shared_ptr<char> old_value,
+ Util::shared_ptr<char> 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<char> old_value,
+ Inkscape::Util::shared_ptr<char> 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<char> old_value,
+ Inkscape::Util::shared_ptr<char> 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<char> old_value,
+ Inkscape::Util::shared_ptr<char> 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<char> old_value,
+ Inkscape::Util::shared_ptr<char> 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 <glibmm/ustring.h>
#include <iterator>
-#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<char> ov,
+ Inkscape::Util::shared_ptr<char> 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<char> oldval;
+ Inkscape::Util::shared_ptr<char> 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<char> ov,
+ Inkscape::Util::shared_ptr<char> nv,
Event *next)
: Event(repr, next), oldval(ov), newval(nv) {}
- Inkscape::Util::SharedCStringPtr oldval;
- Inkscape::Util::SharedCStringPtr newval;
+ Inkscape::Util::shared_ptr<char> oldval;
+ Inkscape::Util::shared_ptr<char> 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<char> old_content,
+ Util::shared_ptr<char> 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<char> old_value,
+ Util::shared_ptr<char> 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<char> old_content,
+ Util::shared_ptr<char> new_content);
void setAttribute(Node &node, GQuark name,
- Util::SharedCStringPtr old_value,
- Util::SharedCStringPtr new_value);
+ Util::shared_ptr<char> old_value,
+ Util::shared_ptr<char> 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 <glib/gquark.h>
-#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<char> old_content,
+ Util::shared_ptr<char> new_content)=0;
virtual void notifyAttributeChanged(Node &node, GQuark name,
- Util::SharedCStringPtr old_value,
- Util::SharedCStringPtr new_value)=0;
+ Util::shared_ptr<char> old_value,
+ Util::shared_ptr<char> 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<Glib::QueryQuark, gchar const *, Inkscape::compare_quark_ids> LocalNameMap;
-typedef std::map<Glib::QueryQuark, Inkscape::Util::SharedCStringPtr, Inkscape::compare_quark_ids> NSMap;
+typedef std::map<Glib::QueryQuark, Inkscape::Util::shared_ptr<char>, 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<char>()));
}
}
}
@@ -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<char> 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<char> 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<char> result=Util::share_string(string);
g_free(string);
return result;
}
-Util::SharedCStringPtr stringify_unsigned(unsigned n) {
+Util::shared_ptr<char> stringify_unsigned(unsigned n) {
gchar *string = g_strdup_printf("%u", n);
- Util::SharedCStringPtr result=Util::SharedCStringPtr::copy(string);
+ Util::shared_ptr<char> 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<char> 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<char> _parent;
+ Util::shared_ptr<char> _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<char> 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<char> _parent;
+ Util::shared_ptr<char> _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<char> 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<char> _parent;
+ Util::shared_ptr<char> _child;
unsigned _position;
};
class DebugSetContent : public Debug::Event {
public:
DebugSetContent(Node const &node,
- Util::SharedCStringPtr old_content,
- Util::SharedCStringPtr new_content)
+ Util::shared_ptr<char> old_content,
+ Util::shared_ptr<char> new_content)
: _node(stringify_node(node)), _content(new_content) {}
static Category category() { return XML; }
- Util::SharedCStringPtr name() const {
+ Util::shared_ptr<char> 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<char> _node;
+ Util::shared_ptr<char> _content;
};
class DebugSetAttribute : public Debug::Event {
public:
DebugSetAttribute(Node const &node, GQuark name,
- Util::SharedCStringPtr old_value,
- Util::SharedCStringPtr new_value)
+ Util::shared_ptr<char> old_value,
+ Util::shared_ptr<char> 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<char> 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<char> _node;
+ Util::shared_ptr<char> _name;
+ Util::shared_ptr<char> _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<char> old_content=_content;
+ shared_ptr<char> new_content = ( content ? share_string(content) : shared_ptr<char>() );
Debug::EventTracker<DebugSetContent> 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<char> old_value=( existing ? existing->value : shared_ptr<char>() );
- SharedCStringPtr new_value=SharedCStringPtr();
+ shared_ptr<char> new_value=shared_ptr<char>();
if (value) {
- new_value = SharedCStringPtr::copy(value);
+ new_value = share_string(value);
tracker.set<DebugSetAttribute>(*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<NodeObserver *>(data)->notifyContentChanged(*node, Util::SharedCStringPtr::coerce((const char *)old_content), Util::SharedCStringPtr::coerce((const char *)new_content));
+ reinterpret_cast<NodeObserver *>(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<NodeObserver *>(data)->notifyAttributeChanged(*node, g_quark_from_string(name), Util::SharedCStringPtr::coerce((const char *)old_value), Util::SharedCStringPtr::coerce((const char *)new_value));
+ reinterpret_cast<NodeObserver *>(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<AttributeRecord> _attributes;
- Inkscape::Util::SharedCStringPtr _content;
+ Inkscape::Util::shared_ptr<char> _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<char> old_content,
+ Util::shared_ptr<char> 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<char> old_value,
+ Util::shared_ptr<char> 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<char> old_content,
+ Util::shared_ptr<char> new_content);
void notifyAttributeChanged(Inkscape::XML::Node &node, GQuark name,
- Util::SharedCStringPtr old_value,
- Util::SharedCStringPtr new_value);
+ Util::shared_ptr<char> old_value,
+ Util::shared_ptr<char> 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<char> content)
: SimpleNode(g_quark_from_static_string("string"))
{
setContent(content);