diff --git a/src/sp-object.cpp b/src/sp-object.cpp
index fd368dd613a0164915c70f0797dec0bb09f10f08..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::shared_ptr<char> stringify(SPObject *obj) {
- char *temp=g_strdup_printf("%p", obj);
- Inkscape::Util::shared_ptr<char> result=Inkscape::Util::share_string(temp);
- g_free(temp);
- return result;
-}
+namespace Debug = Inkscape::Debug;
+namespace Util = Inkscape::Util;
-Inkscape::Util::shared_ptr<char> stringify(unsigned n) {
- char *temp=g_strdup_printf("%u", n);
- Inkscape::Util::shared_ptr<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)), _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::shared_ptr<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 2; }
- PropertyPair property(unsigned index) const {
- switch (index) {
- case 0:
- return PropertyPair("object", _object);
- case 1:
- return PropertyPair("refcount", stringify( _type == REF ? _refcount + 1 : _refcount - 1 ));
- default:
- return PropertyPair();
- }
- }
-
-private:
- Inkscape::Util::shared_ptr<char> _object;
- 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<> tracker;
- tracker.set<RefEvent>(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<> tracker;
- tracker.set<RefEvent>(object, RefEvent::UNREF);
-
+ Inkscape::Debug::EventTracker<UnrefEvent> tracker(object);
g_object_unref(G_OBJECT(object));
-
return NULL;
}
g_return_if_fail(SP_IS_OBJECT(object));
g_return_if_fail(object->parent == parent);
+ sp_object_invoke_release(object);
+
SPObject *prev=NULL;
for ( SPObject *child = parent->children ; child && child != object ;
child = child->next )
object->next = NULL;
object->parent = NULL;
- sp_object_invoke_release(object);
parent->_updateTotalHRefCount(-object->_total_hrefcount);
sp_object_unref(object, parent);
}
g_assert(object != NULL);
g_assert(SP_IS_OBJECT(object));
- // we need to remember our parent
- // g_assert(!object->parent);
- g_assert(!object->next);
g_assert(object->document);
g_assert(object->repr);