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/gstrfuncs.h"
18 #include "glib/gmessages.h"
19 #include "gc-alloc.h"
20 #include "debug/event.h"
22 namespace Inkscape {
24 namespace Debug {
26 template <Event::Category C=Event::OTHER>
27 class SimpleEvent : public Event {
28 public:
29 explicit SimpleEvent(Util::ptr_shared<char> name) : _name(name) {}
30 explicit SimpleEvent(char const *name) : _name(Util::share_string(name)) {}
32 // default copy
33 // default assign
35 static Category category() { return C; }
37 Util::ptr_shared<char> name() const { return _name; }
38 unsigned propertyCount() const { return _properties.size(); }
39 PropertyPair property(unsigned property) const {
40 return _properties[property];
41 }
43 void generateChildEvents() const {}
45 protected:
46 void _addProperty(Util::ptr_shared<char> name,
47 Util::ptr_shared<char> value)
48 {
49 _properties.push_back(PropertyPair(name, value));
50 }
51 void _addProperty(Util::ptr_shared<char> name, char const *value) {
52 _addProperty(name, Util::share_string(value));
53 }
54 void _addProperty(char const *name, Util::ptr_shared<char> value) {
55 _addProperty(Util::share_string(name), value);
56 }
57 void _addProperty(char const *name, char const *value) {
58 _addProperty(Util::share_string(name), Util::share_string(value));
59 }
60 void _addProperty(Util::ptr_shared<char> name, long value) {
61 _addFormattedProperty(name, "%ld", value);
62 }
63 void _addProperty(char const *name, long value) {
64 _addProperty(Util::share_string(name), value);
65 }
67 private:
68 Util::ptr_shared<char> _name;
69 std::vector<PropertyPair, GC::Alloc<PropertyPair, GC::AUTO> > _properties;
71 void _addFormattedProperty(Util::ptr_shared<char> name, char const *format, ...)
72 {
73 va_list args;
74 va_start(args, format);
75 gchar *value=g_strdup_vprintf(format, args);
76 g_assert(value != NULL);
77 va_end(args);
78 _addProperty(name, value);
79 g_free(value);
80 }
81 };
83 }
85 }
87 #endif
88 /*
89 Local Variables:
90 mode:c++
91 c-file-style:"stroustrup"
92 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
93 indent-tabs-mode:nil
94 fill-column:99
95 End:
96 */
97 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :