summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 654a66c)
raw | patch | inline | side by side (parent: 654a66c)
author | mental <mental@users.sourceforge.net> | |
Sat, 29 Apr 2006 21:35:09 +0000 (21:35 +0000) | ||
committer | mental <mental@users.sourceforge.net> | |
Sat, 29 Apr 2006 21:35:09 +0000 (21:35 +0000) |
ChangeLog | patch | blob | history | |
src/gc-anchored.cpp | patch | blob | history | |
src/sp-object.cpp | patch | blob | history | |
src/xml/simple-node.cpp | patch | blob | history |
diff --git a/ChangeLog b/ChangeLog
index 87accbf59c3495f959b249292e43b13e78a8d027..972cae8ddfd0faaa4111cf38e9f9e39535f3c23d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
+2006-04-29 MenTaLguY <mental@rydia.net>
+
+ * src/gc-anchored.cpp, src/xml/simple-node.cpp, src/sp-object.cpp:
+
+ switch everyone to simpler debug event API
+
2006-04-29 MenTaLguY <mental@rydia.net>
* src/Makefile_insert, src/gc-finalized.cpp, src/gc-finalized.h:
diff --git a/src/gc-anchored.cpp b/src/gc-anchored.cpp
index 3829e54ddb08e3f0ae1405a0e72a2f431ee43014..baf36c0c95c51ffb4670565939b54c2620b36586 100644 (file)
--- a/src/gc-anchored.cpp
+++ b/src/gc-anchored.cpp
#include <typeinfo>
#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"
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<Anchored *>(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<Debug::Event::REFCOUNT> RefCountEvent;
- Util::ptr_shared<char> 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<char> name)
+ : RefCountEvent(name)
+ {
+ _addProperty("base", Util::format("%p", Core::base(const_cast<Anchored *>(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<char> _base;
- Util::ptr_shared<char> _object;
- Util::ptr_shared<char> _class_name;
- Util::ptr_shared<char> _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);
}
}
void Anchored::anchor() const {
- Debug::EventTracker<AnchorEvent> tracker(this, AnchorEvent::ANCHOR);
+ Debug::EventTracker<AnchorEvent> tracker(this);
if (!_anchor) {
_anchor = _new_anchor();
}
}
void Anchored::release() const {
- Debug::EventTracker<AnchorEvent> tracker(this, AnchorEvent::RELEASE);
+ Debug::EventTracker<ReleaseEvent> tracker(this);
if (!--_anchor->refcount) {
_free_anchor(_anchor);
_anchor = NULL;
diff --git a/src/sp-object.cpp b/src/sp-object.cpp
index e7778dd081fb46fb1fb8c1b5bb73d9839b967117..fbe16e957b826874d0657b99eb1b70eb532457d7 100644 (file)
--- a/src/sp-object.cpp
+++ b/src/sp-object.cpp
#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;
namespace {
-Inkscape::Util::ptr_shared<char> stringify(SPObject *obj) {
- char *temp=g_strdup_printf("%p", obj);
- Inkscape::Util::ptr_shared<char> result=Inkscape::Util::share_string(temp);
- g_free(temp);
- return result;
-}
+namespace Debug = Inkscape::Debug;
+namespace Util = Inkscape::Util;
-Inkscape::Util::ptr_shared<char> stringify(unsigned n) {
- char *temp=g_strdup_printf("%u", n);
- Inkscape::Util::ptr_shared<char> result=Inkscape::Util::share_string(temp);
- g_free(temp);
- return result;
-}
+typedef Debug::SimpleEvent<Debug::Event::REFCOUNT> BaseRefCountEvent;
-class RefEvent : public Inkscape::Debug::Event {
+class RefCountEvent : public BaseRefCountEvent {
public:
- enum Type { REF, UNREF };
+ RefCountEvent(SPObject *object, int bias, Util::ptr_shared<char> 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<char> 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<char> _object;
- Inkscape::Util::ptr_shared<char> _class_name;
- unsigned _refcount;
- Type _type;
+class UnrefEvent : public RefCountEvent {
+public:
+ UnrefEvent(SPObject *object)
+ : RefCountEvent(object, -1, Util::share_static_string("sp-object-unref"))
+ {}
};
}
g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
g_return_val_if_fail(!owner || SP_IS_OBJECT(owner), NULL);
- Inkscape::Debug::EventTracker<RefEvent> tracker(object, RefEvent::REF);
+ Inkscape::Debug::EventTracker<RefEvent> tracker(object);
g_object_ref(G_OBJECT(object));
return object;
}
g_return_val_if_fail(SP_IS_OBJECT(object), NULL);
g_return_val_if_fail(!owner || SP_IS_OBJECT(owner), NULL);
- Inkscape::Debug::EventTracker<RefEvent> tracker(object, RefEvent::UNREF);
+ Inkscape::Debug::EventTracker<UnrefEvent> tracker(object);
g_object_unref(G_OBJECT(object));
return NULL;
}
index 17339271fc0549135bbf3e97d70bc32332a4e108..7f8dd29b29136c791621323cc4f3604b7393de9a 100644 (file)
--- a/src/xml/simple-node.cpp
+++ b/src/xml/simple-node.cpp
#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 {
return result;
}
-Util::ptr_shared<char> stringify_unsigned(unsigned n) {
- gchar *string = g_strdup_printf("%u", n);
- Util::ptr_shared<char> result=Util::share_string(string);
- g_free(string);
- return result;
-}
+typedef Debug::SimpleEvent<Debug::Event::XML> DebugXML;
-}
+class DebugXMLNode : public DebugXML {
+public:
+ DebugXMLNode(Node const &node, Util::ptr_shared<char> 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<char> 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<char> _parent;
- Util::ptr_shared<char> _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<char> 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<char> _parent;
- Util::ptr_shared<char> _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<char> 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<char> _parent;
- Util::ptr_shared<char> _child;
- unsigned _position;
};
-class DebugSetContent : public Debug::Event {
+class DebugSetContent : public DebugXMLNode {
public:
DebugSetContent(Node const &node,
- Util::ptr_shared<char> old_content,
- Util::ptr_shared<char> new_content)
- : _node(stringify_node(node)), _content(new_content) {}
+ Util::ptr_shared<char> 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<char> 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<char> 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<char> _node;
- Util::ptr_shared<char> _content;
};
-class DebugSetAttribute : public Debug::Event {
+class DebugClearAttribute : public DebugXMLNode {
public:
- DebugSetAttribute(Node const &node, GQuark name,
- Util::ptr_shared<char> old_value,
- Util::ptr_shared<char> 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<char> 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<char> _node;
- Util::ptr_shared<char> _name;
- Util::ptr_shared<char> _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),
ptr_shared<char> old_content=_content;
ptr_shared<char> new_content = ( content ? share_string(content) : ptr_shared<char>() );
- Debug::EventTracker<DebugSetContent> tracker(
- *this, old_content, new_content
- );
+ Debug::EventTracker<> tracker;
+ if (new_content) {
+ tracker.set<DebugSetContent>(*this, new_content);
+ } else {
+ tracker.set<DebugClearContent>(*this);
+ }
_content = new_content;
@@ -407,7 +313,7 @@ SimpleNode::setAttribute(gchar const *name, gchar const *value, bool const is_in
ptr_shared<char> new_value=ptr_shared<char>();
if (value) {
new_value = share_string(value);
- tracker.set<DebugSetAttribute>(*this, key, old_value, new_value);
+ tracker.set<DebugSetAttribute>(*this, key, new_value);
if (!existing) {
if (ref) {
set_rest(ref, MutableList<AttributeRecord>(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<DebugSetAttribute>(*this, key, old_value, new_value);
+ tracker.set<DebugClearAttribute>(*this, key);
if (existing) {
if (ref) {
set_rest(ref, rest(existing));
Node *ref = ( child != _first_child ? previous_node(child) : NULL );
- Debug::EventTracker<DebugRemoveChild> tracker(*this, *child, ref);
+ Debug::EventTracker<DebugRemoveChild> tracker(*this, *child);
Node *next = child->next();
if (ref) {