From: mental Date: Sat, 29 Apr 2006 21:35:09 +0000 (+0000) Subject: switch everyone to simpler debug event API X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=b8ec5550e6e59ed4c0486d2b6da7c02f31e7c51a;p=inkscape.git switch everyone to simpler debug event API --- diff --git a/ChangeLog b/ChangeLog index 87accbf59..972cae8dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-04-29 MenTaLguY + + * src/gc-anchored.cpp, src/xml/simple-node.cpp, src/sp-object.cpp: + + switch everyone to simpler debug event API + 2006-04-29 MenTaLguY * src/Makefile_insert, src/gc-finalized.cpp, src/gc-finalized.h: diff --git a/src/gc-anchored.cpp b/src/gc-anchored.cpp index 3829e54dd..baf36c0c9 100644 --- a/src/gc-anchored.cpp +++ b/src/gc-anchored.cpp @@ -12,7 +12,7 @@ #include #include "gc-anchored.h" #include "debug/event-tracker.h" -#include "debug/event.h" +#include "debug/simple-event.h" #include "util/share.h" #include "util/format.h" @@ -20,51 +20,39 @@ namespace Inkscape { namespace GC { -class AnchorEvent : public Debug::Event { -public: - enum Type { ANCHOR, RELEASE }; - - AnchorEvent(Anchored const *object, Type type) - : _base(Util::format("%p", Core::base(const_cast(object)))), - _object(Util::format("%p", object)), - _class_name(Util::share_static_string(typeid(*object).name())), - _refcount(Util::format("%d", ( type == ANCHOR ? object->_anchored_refcount() + 1 : object->_anchored_refcount() - 1 ))), - _type(type) - {} +namespace { - static Category category() { return REFCOUNT; } +typedef Debug::SimpleEvent RefCountEvent; - Util::ptr_shared name() const { - if ( _type == ANCHOR ) { - return Util::share_static_string("gc-anchor"); - } else { - return Util::share_static_string("gc-release"); - } - } - unsigned propertyCount() const { return 4; } - PropertyPair property(unsigned index) const { - switch (index) { - case 0: - return PropertyPair("base", _base); - case 1: - return PropertyPair("pointer", _object); - case 2: - return PropertyPair("class", _class_name); - case 3: - return PropertyPair("new-refcount", _refcount); - default: - return PropertyPair(); - } +class BaseAnchorEvent : public RefCountEvent { +public: + BaseAnchorEvent(Anchored const *object, int bias, + Util::ptr_shared name) + : RefCountEvent(name) + { + _addProperty("base", Util::format("%p", Core::base(const_cast(object)))); + _addProperty("pointer", Util::format("%p", object)); + _addProperty("class", Util::share_static_string(typeid(*object).name())); + _addProperty("new-refcount", Util::format("%d", object->_anchored_refcount() + bias)); } +}; -private: - Util::ptr_shared _base; - Util::ptr_shared _object; - Util::ptr_shared _class_name; - Util::ptr_shared _refcount; - Type _type; +class AnchorEvent : public BaseAnchorEvent { +public: + AnchorEvent(Anchored const *object) + : BaseAnchorEvent(object, 1, Util::share_static_string("gc-anchor")) + {} }; +class ReleaseEvent : public BaseAnchorEvent { +public: + ReleaseEvent(Anchored const *object) + : BaseAnchorEvent(object, -1, Util::share_static_string("gc-release")) + {} +}; + +} + Anchored::Anchor *Anchored::_new_anchor() const { return new Anchor(this); } @@ -74,7 +62,7 @@ void Anchored::_free_anchor(Anchored::Anchor *anchor) const { } void Anchored::anchor() const { - Debug::EventTracker tracker(this, AnchorEvent::ANCHOR); + Debug::EventTracker tracker(this); if (!_anchor) { _anchor = _new_anchor(); } @@ -82,7 +70,7 @@ void Anchored::anchor() const { } void Anchored::release() const { - Debug::EventTracker tracker(this, AnchorEvent::RELEASE); + Debug::EventTracker tracker(this); if (!--_anchor->refcount) { _free_anchor(_anchor); _anchor = NULL; diff --git a/src/sp-object.cpp b/src/sp-object.cpp index e7778dd08..fbe16e957 100644 --- a/src/sp-object.cpp +++ b/src/sp-object.cpp @@ -44,6 +44,9 @@ #include "xml/repr.h" #include "xml/node-fns.h" #include "debug/event-tracker.h" +#include "debug/simple-event.h" +#include "util/share.h" +#include "util/format.h" #include "algorithms/longest-common-suffix.h" using std::memcpy; @@ -227,59 +230,34 @@ sp_object_finalize(GObject *object) namespace { -Inkscape::Util::ptr_shared stringify(SPObject *obj) { - char *temp=g_strdup_printf("%p", obj); - Inkscape::Util::ptr_shared result=Inkscape::Util::share_string(temp); - g_free(temp); - return result; -} +namespace Debug = Inkscape::Debug; +namespace Util = Inkscape::Util; -Inkscape::Util::ptr_shared stringify(unsigned n) { - char *temp=g_strdup_printf("%u", n); - Inkscape::Util::ptr_shared result=Inkscape::Util::share_string(temp); - g_free(temp); - return result; -} +typedef Debug::SimpleEvent BaseRefCountEvent; -class RefEvent : public Inkscape::Debug::Event { +class RefCountEvent : public BaseRefCountEvent { public: - enum Type { REF, UNREF }; + RefCountEvent(SPObject *object, int bias, Util::ptr_shared name) + : BaseRefCountEvent(name) + { + _addProperty("object", Util::format("%p", object)); + _addProperty("class", Util::share_static_string(g_type_name(G_TYPE_FROM_INSTANCE(object)))); + _addProperty("new-refcount", Util::format("%d", G_OBJECT(object)->ref_count + bias)); + } +}; - RefEvent(SPObject *object, Type type) - : _object(stringify(object)), - _class_name(Inkscape::Util::share_static_string(g_type_name(G_TYPE_FROM_INSTANCE(object)))), - _refcount(G_OBJECT(object)->ref_count), - _type(type) +class RefEvent : public RefCountEvent { +public: + RefEvent(SPObject *object) + : RefCountEvent(object, 1, Util::share_static_string("sp-object-ref")) {} +}; - static Category category() { return REFCOUNT; } - - Inkscape::Util::ptr_shared name() const { - if ( _type == REF) { - return Inkscape::Util::share_static_string("sp-object-ref"); - } else { - return Inkscape::Util::share_static_string("sp-object-unref"); - } - } - unsigned propertyCount() const { return 3; } - PropertyPair property(unsigned index) const { - switch (index) { - case 0: - return PropertyPair("object", _object); - case 1: - return PropertyPair("class", _class_name); - case 2: - return PropertyPair("new-refcount", stringify( _type == REF ? _refcount + 1 : _refcount - 1 )); - default: - return PropertyPair(); - } - } - -private: - Inkscape::Util::ptr_shared _object; - Inkscape::Util::ptr_shared _class_name; - unsigned _refcount; - Type _type; +class UnrefEvent : public RefCountEvent { +public: + UnrefEvent(SPObject *object) + : RefCountEvent(object, -1, Util::share_static_string("sp-object-unref")) + {} }; } @@ -298,7 +276,7 @@ sp_object_ref(SPObject *object, SPObject *owner) g_return_val_if_fail(SP_IS_OBJECT(object), NULL); g_return_val_if_fail(!owner || SP_IS_OBJECT(owner), NULL); - Inkscape::Debug::EventTracker tracker(object, RefEvent::REF); + Inkscape::Debug::EventTracker tracker(object); g_object_ref(G_OBJECT(object)); return object; } @@ -318,7 +296,7 @@ sp_object_unref(SPObject *object, SPObject *owner) g_return_val_if_fail(SP_IS_OBJECT(object), NULL); g_return_val_if_fail(!owner || SP_IS_OBJECT(owner), NULL); - Inkscape::Debug::EventTracker tracker(object, RefEvent::UNREF); + Inkscape::Debug::EventTracker tracker(object); g_object_unref(G_OBJECT(object)); return NULL; } 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) {