~centralelyon2010/inkscape/imagelinks2

1 by mental
moving trunk for module inkscape
1
/*
2
 * Inkscape::GC::Anchored - base class for anchored GC-managed objects
3
 *
4
 * Authors:
5
 *   MenTaLguY <mental@rydia.net>
6
 *
7
 * Copyright (C) 2004 MenTaLguY
8
 *
9
 * Released under GNU GPL, read the file 'COPYING' for more information
10
 */
11
614 by mental
added refcount logging to GC::Anchored and shared string printf in util
12
#include <typeinfo>
1 by mental
moving trunk for module inkscape
13
#include "gc-anchored.h"
614 by mental
added refcount logging to GC::Anchored and shared string printf in util
14
#include "debug/event-tracker.h"
697 by gouldtj
r11667@tres: ted | 2006-05-01 22:48:49 -0700
15
#include "debug/simple-event.h"
778 by mental
use c++filt for symbol demangling if available
16
#include "debug/demangle.h"
614 by mental
added refcount logging to GC::Anchored and shared string printf in util
17
#include "util/share.h"
18
#include "util/format.h"
1 by mental
moving trunk for module inkscape
19
20
namespace Inkscape {
21
22
namespace GC {
23
697 by gouldtj
r11667@tres: ted | 2006-05-01 22:48:49 -0700
24
namespace {
25
26
typedef Debug::SimpleEvent<Debug::Event::REFCOUNT> RefCountEvent;
27
28
class BaseAnchorEvent : public RefCountEvent {
29
public:
30
    BaseAnchorEvent(Anchored const *object, int bias,
31
                    Util::ptr_shared<char> name)
32
    : RefCountEvent(name)
33
    {
34
        _addProperty("base", Util::format("%p", Core::base(const_cast<Anchored *>(object))));
35
        _addProperty("pointer", Util::format("%p", object));
778 by mental
use c++filt for symbol demangling if available
36
        _addProperty("class", Debug::demangle(typeid(*object).name()));
697 by gouldtj
r11667@tres: ted | 2006-05-01 22:48:49 -0700
37
        _addProperty("new-refcount", Util::format("%d", object->_anchored_refcount() + bias));
38
    }
39
};
40
41
class AnchorEvent : public BaseAnchorEvent {
42
public:
43
    AnchorEvent(Anchored const *object)
44
    : BaseAnchorEvent(object, 1, Util::share_static_string("gc-anchor"))
45
    {}
46
};
47
48
class ReleaseEvent : public BaseAnchorEvent {
49
public:
50
    ReleaseEvent(Anchored const *object)
51
    : BaseAnchorEvent(object, -1, Util::share_static_string("gc-release"))
52
    {}
53
};
54
55
}
614 by mental
added refcount logging to GC::Anchored and shared string printf in util
56
1 by mental
moving trunk for module inkscape
57
Anchored::Anchor *Anchored::_new_anchor() const {
58
    return new Anchor(this);
59
}
60
61
void Anchored::_free_anchor(Anchored::Anchor *anchor) const {
62
    delete anchor;
63
}
64
614 by mental
added refcount logging to GC::Anchored and shared string printf in util
65
void Anchored::anchor() const {
697 by gouldtj
r11667@tres: ted | 2006-05-01 22:48:49 -0700
66
    Debug::EventTracker<AnchorEvent> tracker(this);
614 by mental
added refcount logging to GC::Anchored and shared string printf in util
67
    if (!_anchor) {
68
        _anchor = _new_anchor();
69
    }
70
    _anchor->refcount++;
71
}
72
73
void Anchored::release() const {
697 by gouldtj
r11667@tres: ted | 2006-05-01 22:48:49 -0700
74
    Debug::EventTracker<ReleaseEvent> tracker(this);
4224 by cilix42
Fundamentally reworked version of the 3D box tool (among many other things, this fixes bugs #168900 and #168868). See mailing list for details. Sorry for this single large commit but it was unfeasible to keep the history.
75
    g_return_if_fail(_anchor);
614 by mental
added refcount logging to GC::Anchored and shared string printf in util
76
    if (!--_anchor->refcount) {
77
        _free_anchor(_anchor);
78
        _anchor = NULL;
79
    }
80
}
81
1 by mental
moving trunk for module inkscape
82
}
83
84
}
85
86
/*
87
  Local Variables:
88
  mode:c++
89
  c-file-style:"stroustrup"
90
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
91
  indent-tabs-mode:nil
92
  fill-column:99
93
  End:
94
*/
9020 by JazzyNico
Code refactoring and merging with trunk (revision 10599).
95
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :