From 14497e8d985e7d77cbfc33af53df0b086137440b Mon Sep 17 00:00:00 2001 From: MenTaLguY Date: Sat, 29 Apr 2006 21:35:09 +0000 Subject: switch everyone to simpler debug event API (bzr r634) --- src/xml/simple-node.cpp | 252 +++++++++++++++--------------------------------- 1 file changed, 79 insertions(+), 173 deletions(-) (limited to 'src/xml/simple-node.cpp') diff --git a/src/xml/simple-node.cpp b/src/xml/simple-node.cpp index 17339271f..7f8dd29b2 100644 --- a/src/xml/simple-node.cpp +++ b/src/xml/simple-node.cpp @@ -21,6 +21,9 @@ #include "xml/node-fns.h" #include "xml/repr.h" #include "debug/event-tracker.h" +#include "debug/simple-event.h" +#include "util/share.h" +#include "util/format.h" namespace Inkscape { @@ -56,203 +59,103 @@ Util::ptr_shared stringify_node(Node const &node) { return result; } -Util::ptr_shared stringify_unsigned(unsigned n) { - gchar *string = g_strdup_printf("%u", n); - Util::ptr_shared result=Util::share_string(string); - g_free(string); - return result; -} +typedef Debug::SimpleEvent DebugXML; -} +class DebugXMLNode : public DebugXML { +public: + DebugXMLNode(Node const &node, Util::ptr_shared name) + : DebugXML(name) + { + _addProperty("node", stringify_node(node)); + } +}; -class DebugAddChild : public Debug::Event { +class DebugAddChild : public DebugXMLNode { public: DebugAddChild(Node const &node, Node const &child, Node const *prev) - : _parent(stringify_node(node)), - _child(stringify_node(child)), - _position(prev ? prev->position() + 1 : 0) - {} - - static Category category() { return XML; } - - Util::ptr_shared name() const { - return Util::share_static_string("add-child"); - } - unsigned propertyCount() const { return 3; } - PropertyPair property(unsigned i) const { - switch (i) { - case 0: - return PropertyPair("parent", _parent); - case 1: - return PropertyPair("child", _child); - case 2: - return PropertyPair("position", stringify_unsigned(_position)); - default: - return PropertyPair(); - } + : DebugXMLNode(node, Util::share_static_string("add-child")) + { + _addProperty("child", stringify_node(child)); + _addProperty("position", Util::format("%d", ( prev ? prev->position() + 1 : 0 ))); } -private: - Util::ptr_shared _parent; - Util::ptr_shared _child; - unsigned _position; }; -class DebugRemoveChild : public Debug::Event { +class DebugRemoveChild : public DebugXMLNode { public: - DebugRemoveChild(Node const &node, Node const &child, Node const *prev) - : _parent(stringify_node(node)), - _child(stringify_node(child)) - {} - - static Category category() { return XML; } - - Util::ptr_shared name() const { - return Util::share_static_string("remove-child"); - } - unsigned propertyCount() const { return 2; } - PropertyPair property(unsigned i) const { - switch (i) { - case 0: - return PropertyPair("parent", _parent); - case 1: - return PropertyPair("child", _child); - default: - return PropertyPair(); - } + DebugRemoveChild(Node const &node, Node const &child) + : DebugXMLNode(node, Util::share_static_string("remove-child")) + { + _addProperty("child", stringify_node(child)); } -private: - Util::ptr_shared _parent; - Util::ptr_shared _child; }; -class DebugSetChildPosition : public Debug::Event { +class DebugSetChildPosition : public DebugXMLNode { public: - DebugSetChildPosition(Node const &node, Node const &child, Node const *old_prev, Node const *new_prev) - : _parent(stringify_node(node)), - _child(stringify_node(child)) + DebugSetChildPosition(Node const &node, Node const &child, + Node const *old_prev, Node const *new_prev) + : DebugXMLNode(node, Util::share_static_string("set-child-position")) { + _addProperty("child", stringify_node(child)); + unsigned old_position = ( old_prev ? old_prev->position() : 0 ); - _position = ( new_prev ? new_prev->position() : 0 ); - if ( _position > old_position ) { - --_position; + unsigned position = ( new_prev ? new_prev->position() : 0 ); + if ( position > old_position ) { + --position; } - } - static Category category() { return XML; } - - Util::ptr_shared name() const { - return Util::share_static_string("set-child-position"); - } - unsigned propertyCount() const { return 3; } - PropertyPair property(unsigned i) const { - switch (i) { - case 0: - return PropertyPair("parent", _parent); - case 1: - return PropertyPair("child", _child); - case 2: - return PropertyPair("position", stringify_unsigned(_position)); - default: - return PropertyPair(); - } + _addProperty("position", Util::format("%d", position)); } -private: - Util::ptr_shared _parent; - Util::ptr_shared _child; - unsigned _position; }; -class DebugSetContent : public Debug::Event { +class DebugSetContent : public DebugXMLNode { public: DebugSetContent(Node const &node, - Util::ptr_shared old_content, - Util::ptr_shared new_content) - : _node(stringify_node(node)), _content(new_content) {} + Util::ptr_shared content) + : DebugXMLNode(node, Util::share_static_string("set-content")) + { + _addProperty("content", content); + } +}; - static Category category() { return XML; } +class DebugClearContent : public DebugXMLNode { +public: + DebugClearContent(Node const &node) + : DebugXMLNode(node, Util::share_static_string("clear-content")) + {} +}; - Util::ptr_shared name() const { - if (_content) { - return Util::share_static_string("set-content"); - } else { - return Util::share_static_string("clear-content"); - } - } - unsigned propertyCount() const { - if (_content) { - return 2; - } else { - return 1; - } - } - PropertyPair property(unsigned i) const { - switch (i) { - case 0: - return PropertyPair("node", _node); - case 1: - return PropertyPair("content", _content); - default: - return PropertyPair(); - } +class DebugSetAttribute : public DebugXMLNode { +public: + DebugSetAttribute(Node const &node, + GQuark name, + Util::ptr_shared value) + : DebugXMLNode(node, Util::share_static_string("set-attribute")) + { + _addProperty("name", Util::share_static_string(g_quark_to_string(name))); + _addProperty("value", value); } -private: - Util::ptr_shared _node; - Util::ptr_shared _content; }; -class DebugSetAttribute : public Debug::Event { +class DebugClearAttribute : public DebugXMLNode { public: - DebugSetAttribute(Node const &node, GQuark name, - Util::ptr_shared old_value, - Util::ptr_shared new_value) - : _node(stringify_node(node)), - _name(Util::share_unsafe(g_quark_to_string(name))), - _value(new_value) {} - - static Category category() { return XML; } - - Util::ptr_shared name() const { - if (_value) { - return Util::share_static_string("set-attribute"); - } else { - return Util::share_static_string("clear-attribute"); - } - } - unsigned propertyCount() const { - if (_value) { - return 3; - } else { - return 2; - } - } - PropertyPair property(unsigned i) const { - switch (i) { - case 0: - return PropertyPair("node", _node); - case 1: - return PropertyPair("name", _name); - case 2: - return PropertyPair("value", _value); - default: - return PropertyPair(); - } + DebugClearAttribute(Node const &node, GQuark name) + : DebugXMLNode(node, Util::share_static_string("clear-attribute")) + { + _addProperty("name", Util::share_static_string(g_quark_to_string(name))); } - -private: - Util::ptr_shared _node; - Util::ptr_shared _name; - Util::ptr_shared _value; }; -using Inkscape::Util::ptr_shared; -using Inkscape::Util::share_string; -using Inkscape::Util::share_unsafe; -using Inkscape::Util::share_static_string; -using Inkscape::Util::List; -using Inkscape::Util::MutableList; -using Inkscape::Util::cons; -using Inkscape::Util::rest; -using Inkscape::Util::set_rest; +} + +using Util::ptr_shared; +using Util::share_string; +using Util::share_unsafe; +using Util::share_static_string; +using Util::List; +using Util::MutableList; +using Util::cons; +using Util::rest; +using Util::set_rest; SimpleNode::SimpleNode(int code) : Node(), _name(code), _attributes(), _child_count(0), @@ -369,9 +272,12 @@ void SimpleNode::setContent(gchar const *content) { ptr_shared old_content=_content; ptr_shared new_content = ( content ? share_string(content) : ptr_shared() ); - Debug::EventTracker tracker( - *this, old_content, new_content - ); + Debug::EventTracker<> tracker; + if (new_content) { + tracker.set(*this, new_content); + } else { + tracker.set(*this); + } _content = new_content; @@ -407,7 +313,7 @@ SimpleNode::setAttribute(gchar const *name, gchar const *value, bool const is_in ptr_shared new_value=ptr_shared(); if (value) { new_value = share_string(value); - tracker.set(*this, key, old_value, new_value); + tracker.set(*this, key, new_value); if (!existing) { if (ref) { set_rest(ref, MutableList(AttributeRecord(key, new_value))); @@ -418,7 +324,7 @@ SimpleNode::setAttribute(gchar const *name, gchar const *value, bool const is_in existing->value = new_value; } } else { - tracker.set(*this, key, old_value, new_value); + tracker.set(*this, key); if (existing) { if (ref) { set_rest(ref, rest(existing)); @@ -513,7 +419,7 @@ void SimpleNode::removeChild(Node *child) { Node *ref = ( child != _first_child ? previous_node(child) : NULL ); - Debug::EventTracker tracker(*this, *child, ref); + Debug::EventTracker tracker(*this, *child); Node *next = child->next(); if (ref) { -- cgit v1.2.3