summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: a2759d9)
raw | patch | inline | side by side (parent: a2759d9)
author | mental <mental@users.sourceforge.net> | |
Mon, 6 Feb 2006 04:15:05 +0000 (04:15 +0000) | ||
committer | mental <mental@users.sourceforge.net> | |
Mon, 6 Feb 2006 04:15:05 +0000 (04:15 +0000) |
36 files changed:
diff --git a/ChangeLog b/ChangeLog
index 5e8c4a8377fd442fb813f8cc9885bf14eea60d99..4f83279310b88fae57fa0fcae7a8fb5644b81256 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
+2006-02-05 MenTaLguY <mental@rydia.net>
+
+ * 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 <jon@rejon.org>
* src/verbs.cpp: Added "..." to "Trace Bitmap" text. Yes, what a
diff --git a/src/debug/event.h b/src/debug/event.h
index c3b3a83fb312b268df523d73c5a90c9ca4229138..8232f890df9250b6414cf94a7406d03e8410ab91 100644 (file)
--- a/src/debug/event.h
+++ b/src/debug/event.h
#define SEEN_INKSCAPE_DEBUG_EVENT_H
#include <utility>
-#include "util/shared-c-string-ptr.h"
+#include "util/share.h"
namespace Inkscape {
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 b3042432ea196816b9544a08b4d360c3cdfee311..0a9534701deb01272f99b72eb7098feb5b5d2169 100644 (file)
--- a/src/debug/gc-heap.h
+++ b/src/debug/gc-heap.h
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 d07cf74a13f8b6bae8822f1720edcd2de94b07a8..ef563030fe150699e0da86f0c7ac0009eed9442b 100644 (file)
--- a/src/debug/heap.h
+++ b/src/debug/heap.h
#define SEEN_INKSCAPE_DEBUG_HEAP_H
#include <cstddef>
-#include "util/shared-c-string-ptr.h"
+#include "util/share.h"
namespace Inkscape {
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 a3c7b0430074b471593e3d658f927a5fcd9cce77..6fb1aee05e685bb661b590e29acf26c25be4eff5 100644 (file)
--- a/src/debug/logger.cpp
+++ b/src/debug/logger.cpp
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 '&':
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;
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);
}
}
}
void Logger::_start(Event const &event) {
- Util::SharedCStringPtr name=event.name();
+ Util::shared_ptr<char> name=event.name();
if (empty_tag) {
log_stream << ">\n";
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 << "\"";
}
}
void Logger::_skip() {
- tag_stack().push_back(Util::SharedCStringPtr());
+ tag_stack().push_back(Util::shared_ptr<char>());
}
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();
index 3a3adae3c36818a62eaee96a84623aecbe08312f..90eed3a0ef04241220caaf00dea48262a0f376b2 100644 (file)
--- a/src/debug/simple-event.h
+++ b/src/debug/simple-event.h
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 2ba24b2b5ae41b38d07940c40c87a29305687d25..9a07a3261ea452d22bf83cc7c2cd8ad1c112a134 100644 (file)
--- a/src/debug/sysv-heap.h
+++ b/src/debug/sysv-heap.h
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() {}
index 40047051e250f5e63b4e6c8bd3818671ea2bc7e7..8a6a464b4820350b72012c902fc45e8003b4684f 100644 (file)
#include "xml/node.h"
#include "xml/repr.h"
-#include "util/shared-c-string-ptr.h"
+#include "util/share.h"
#include "gc-anchored.h"
{
// 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;
// 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.
// 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 431545ac01140570291e4cfbe9a542162676608e..8843b6f459a94574f8b7a9a2eae4437fdf274dbd 100644 (file)
#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>
index 11acb1a95d0d4cd5c7092f73b7215a35bb39406f..5595f435c08a64455ba24eb105f47708578b0f4c 100644 (file)
namespace Util {
-class SharedCStringPtr;
+class shared_ptr<char>;
}
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 600500c70458ed63e7b41da1352b7b6a0f61eafd..a3260d8a0240800a91597217eeecfa37fb826bb1 100644 (file)
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
index 35b2772a158b37732d046046392e6890dbde6794..f0cbacddc4b54772279b4e2777ffacefec9ece17 100644 (file)
* 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"
index ddba47299cf836e47988a3086a70c6755ead145d..aae3e13787fbdaf087c387d515d8a85a15cd3404 100644 (file)
#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"
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.
index cc0aa97b6b14a6f5353c4b2930f970f52c600965..16889c571f15119352b6feec2c1d378cec0ee62b 100644 (file)
#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"
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 d23a4d640cb9a8319e54d56853f92ea36b70f1cb..d8fe26b8746759c19580fac244cdbe94f38bae39 100644 (file)
--- a/src/sp-object.cpp
+++ b/src/sp-object.cpp
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;
}
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; }
}
private:
- Inkscape::Util::SharedCStringPtr _object;
+ Inkscape::Util::shared_ptr<char> _object;
unsigned _refcount;
Type _type;
};
index 1b7119180948e4d5830bb7345b83ffa728bbed7b..bdd613385401dc9aad51dd772dd309401b2f6e26 100644 (file)
--- a/src/util/Makefile_insert
+++ b/src/util/Makefile_insert
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
--- /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
--- /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
+++ /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
+++ /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 :
index dbad0f34010e8bb4dd6b4cfad9b551c5f88083a6..30d8576d07dbad764a9505bc24fe7a60bb5dc5c0 100644 (file)
#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)
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 dccc5e8644eabb83b4e9f7966c0070b8ecfe02fb..e41a36b59da2983f6c41df1fb29ff4be6103709c 100644 (file)
--- a/src/xml/comment-node.h
+++ b/src/xml/comment-node.h
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);
index 97bce93609f758c25962a257860ff072154a1c04..b564da78da431d16e0e7e1489690745a40f9a3a6 100644 (file)
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() ;
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() ;
}
}
- 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);
}
index 6568a10992304f668e363180dabd104d341246e9..4acde0b4ce08e1c18c455f3c3bed97fe9addcdee 100644 (file)
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 c9f0b50a76efcd8b3f31f88b29712a5d7e63e048..dd71678743749b5c6572a9bfc17e7a4bbb16e0a0 100644 (file)
--- a/src/xml/event.cpp
+++ b/src/xml/event.cpp
}
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);
}
}
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 e4ce8b26a1f621473319d51416fb0857c04423f4..56fdb8bb60d43e6c7b507ce0597e51553b83c63a 100644 (file)
--- a/src/xml/event.h
+++ b/src/xml/event.h
#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"
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();
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();
index b3d8db59f1b97da9c6620cc9c9da594889c23e99..97451075ae00f91d92e7a7bf48813ed8048ddfa6 100644 (file)
--- a/src/xml/log-builder.cpp
+++ b/src/xml/log-builder.cpp
}
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 1f1ea1959423d39d6f78da1e6e0a03b0be67b617..dc68a4f4a7f4f0bef140b93b081a39d11afbd483 100644 (file)
--- a/src/xml/log-builder.h
+++ b/src/xml/log-builder.h
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;
index 4a884b8a930c81df908249db5034f26a94baa8f3..e50a41dd83caa78ba72c74530dc252487ca578e8 100644 (file)
--- a/src/xml/node-observer.h
+++ b/src/xml/node-observer.h
#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 {
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 bb62393fc541981002e120d4e03b1db8d14e89e4..884bb3360847a0a54eb91d0302fc4cd3f2ecf446 100644 (file)
--- a/src/xml/repr-io.cpp
+++ b/src/xml/repr-io.cpp
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;
}
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");
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>()));
}
}
}
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 2cd770a5298796913b8dd8e7bfc5643727250113..9612bb8587526cf326bf7ede5210ed3940610df8 100644 (file)
--- a/src/xml/repr.cpp
+++ b/src/xml/repr.cpp
#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 *
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.
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.
index d3e04743141b0fc5f678f5eac63445b623aaf6df..5e21f941ee9ec40270ae561587b23dabc5a41bf6 100644 (file)
--- a/src/xml/simple-node.cpp
+++ b/src/xml/simple-node.cpp
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: {
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;
}
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 {
}
}
private:
- Util::SharedCStringPtr _parent;
- Util::SharedCStringPtr _child;
+ Util::shared_ptr<char> _parent;
+ Util::shared_ptr<char> _child;
unsigned _position;
};
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 {
}
}
private:
- Util::SharedCStringPtr _parent;
- Util::SharedCStringPtr _child;
+ Util::shared_ptr<char> _parent;
+ Util::shared_ptr<char> _child;
};
class DebugSetChildPosition : public Debug::Event {
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 {
}
}
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 {
}
}
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 {
}
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;
}
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) {
}
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 75fe1db07ac413dba2b489ef9b4d1fef986a9018..f1cf786805cda2ec9d6538e45e85595f4b3f0c17 100644 (file)
--- a/src/xml/simple-node.h
+++ b/src/xml/simple-node.h
Inkscape::Util::MutableList<AttributeRecord> _attributes;
- Inkscape::Util::SharedCStringPtr _content;
+ Inkscape::Util::shared_ptr<char> _content;
unsigned _child_count;
mutable bool _cached_positions_valid;
index 76caf1e54e9628f289c25e2842baf26d922e4ef1..c8d873fd262c5dbdfb9a460032076a71b7b38ca6 100644 (file)
}
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,
}
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);
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);
index 5e9e3a7c14216232f79de36d44b59fcd7d25e313..9e3693d9a4b1be3a149d7151eeb06d7d7c359f78 100644 (file)
--- a/src/xml/simple-session.h
+++ b/src/xml/simple-session.h
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 c07d70f651cef224185baeae83227453801ecf39..bcd1c3e4f0d3727a7deaa75098956a1a403b4cf1 100644 (file)
--- a/src/xml/text-node.h
+++ b/src/xml/text-node.h
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);