Code

Fix rare crash when trying to drag after undo in the node tool
[inkscape.git] / src / debug / simple-event.h
1 /*
2  * Inkscape::Debug::SimpleEvent - trivial implementation of Debug::Event
3  *
4  * Authors:
5  *   MenTaLguY <mental@rydia.net>
6  *
7  * Copyright (C) 2005 MenTaLguY
8  *
9  * Released under GNU GPL, read the file 'COPYING' for more information
10  */
12 #ifndef SEEN_INKSCAPE_DEBUG_SIMPLE_EVENT_H
13 #define SEEN_INKSCAPE_DEBUG_SIMPLE_EVENT_H
15 #include <stdarg.h>
16 #include <vector>
17 #include <glib.h> // g_assert()
18 #include <glib/gstrfuncs.h>
19 #include <glib/gmessages.h>
21 #include "gc-alloc.h"
22 #include "debug/event.h"
24 namespace Inkscape {
26 namespace Debug {
28 template <Event::Category C=Event::OTHER>
29 class SimpleEvent : public Event {
30 public:
31     explicit SimpleEvent(Util::ptr_shared<char> name) : _name(name) {}
32     explicit SimpleEvent(char const *name) : _name(Util::share_string(name)) {}
34     // default copy
35     // default assign
37     static Category category() { return C; }
39     Util::ptr_shared<char> name() const { return _name; }
40     unsigned propertyCount() const { return _properties.size(); }
41     PropertyPair property(unsigned property) const {
42         return _properties[property];
43     }
45     void generateChildEvents() const {}
47 protected:
48     void _addProperty(Util::ptr_shared<char> name,
49                       Util::ptr_shared<char> value)
50     {
51         _properties.push_back(PropertyPair(name, value));
52     }
53     void _addProperty(Util::ptr_shared<char> name, char const *value) {
54         _addProperty(name, Util::share_string(value));
55     }
56     void _addProperty(char const *name, Util::ptr_shared<char> value) {
57         _addProperty(Util::share_string(name), value);
58     }
59     void _addProperty(char const *name, char const *value) {
60         _addProperty(Util::share_string(name), Util::share_string(value));
61     }
62     void _addProperty(Util::ptr_shared<char> name, long value) {
63         _addFormattedProperty(name, "%ld", value);
64     }
65     void _addProperty(char const *name, long value) {
66         _addProperty(Util::share_string(name), value);
67     }
69 private:
70     Util::ptr_shared<char> _name;
71     std::vector<PropertyPair, GC::Alloc<PropertyPair, GC::AUTO> > _properties;
73     void _addFormattedProperty(Util::ptr_shared<char> name, char const *format, ...)
74     {
75         va_list args;
76         va_start(args, format);
77         gchar *value=g_strdup_vprintf(format, args);
78         g_assert(value != NULL);
79         va_end(args);
80         _addProperty(name, value);
81         g_free(value);
82     }
83 };
85 }
87 }
89 #endif
90 /*
91   Local Variables:
92   mode:c++
93   c-file-style:"stroustrup"
94   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
95   indent-tabs-mode:nil
96   fill-column:99
97   End:
98 */
99 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :