Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
gc-anchored.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Inkscape::GC::Anchored - base class for anchored GC-managed objects
4 *
5 * Authors:
6 * MenTaLguY <mental@rydia.net>
7 *
8 * Copyright (C) 2004 MenTaLguY
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#include <typeinfo>
14#include "gc-anchored.h"
15#include "debug/event-tracker.h"
16#include "debug/simple-event.h"
17#include "debug/demangle.h"
18#include "util/format.h"
19
20namespace Inkscape {
21
22namespace GC {
23
24namespace {
25
27
28class BaseAnchorEvent : public RefCountEvent {
29public:
30 BaseAnchorEvent(Anchored const *object, int bias,
31 char const *name)
32 : RefCountEvent(name)
33 {
34 _addProperty("base", Util::format("%p", Core::base(const_cast<Anchored *>(object))).pointer());
35 _addProperty("pointer", Util::format("%p", object).pointer());
36 _addProperty("class", Debug::demangle(typeid(*object).name()));
37 _addProperty("new-refcount", object->_anchored_refcount() + bias);
38 }
39};
40
41class AnchorEvent : public BaseAnchorEvent {
42public:
43 AnchorEvent(Anchored const *object)
44 : BaseAnchorEvent(object, 1, "gc-anchor")
45 {}
46};
47
48class ReleaseEvent : public BaseAnchorEvent {
49public:
50 ReleaseEvent(Anchored const *object)
51 : BaseAnchorEvent(object, -1, "gc-release")
52 {}
53};
54
55}
56
58 return new Anchor(this);
59}
60
64
65void Anchored::anchor() const {
67 if (!_anchor) {
69 }
71}
72
73void Anchored::release() const {
75 g_return_if_fail(_anchor);
76 if (!--_anchor->refcount) {
78 _anchor = nullptr;
79 }
80}
81
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*/
95// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
Anchor * _new_anchor() const
void _free_anchor(Anchor *anchor) const
std::shared_ptr< std::string > demangle(char const *name)
Definition demangle.cpp:37
static R & anchor(R &r)
Increments the reference count of a anchored object.
Definition gc-anchored.h:92
ptr_shared format(char const *format,...) G_GNUC_PRINTF(1
Definition format.h:33
Helper class to stream background task notifications as a series of messages.
static void * base(void *ptr)
Definition gc-core.h:77
Glib::ustring name
Definition toolbars.cpp:55