Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
simple-event.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Inkscape::Debug::SimpleEvent - trivial implementation of Debug::Event
4 *
5 * Authors:
6 * MenTaLguY <mental@rydia.net>
7 *
8 * Copyright (C) 2005 MenTaLguY
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#ifndef SEEN_INKSCAPE_DEBUG_SIMPLE_EVENT_H
14#define SEEN_INKSCAPE_DEBUG_SIMPLE_EVENT_H
15
16#include <cstdarg>
17#include <memory>
18#include <string>
19#include <vector>
20#include <glib.h> // g_assert()
21
22#include "debug/event.h"
23
24namespace Inkscape {
25
26namespace Debug {
27
28template <Event::Category C=Event::OTHER>
29class SimpleEvent : public Event {
30public:
31 explicit SimpleEvent(char const *name) : _name(name) {}
32
33 // default copy
34 // default assign
35
36 static Category category() { return C; }
37
38 char const *name() const override { return _name; }
39 unsigned propertyCount() const override { return _properties.size(); }
40 PropertyPair property(unsigned property) const override {
41 return _properties[property];
42 }
43
44 void generateChildEvents() const override {}
45
46protected:
47 void _addProperty(char const *name, std::shared_ptr<std::string>&& value) {
48 _properties.emplace_back(name, std::move(value));
49 }
50 void _addProperty(char const *name, char const *value) {
51 _addProperty(name, std::make_shared<std::string>(value));
52 }
53 void _addProperty(char const *name, long value) {
54 _addFormattedProperty(name, "%ld", value);
55 }
56
57private:
58 char const *_name;
59 std::vector<PropertyPair> _properties;
60
61 void _addFormattedProperty(char const *name, char const *format, ...)
62 {
63 va_list args;
64 va_start(args, format);
65 gchar *value=g_strdup_vprintf(format, args);
66 g_assert(value != nullptr);
67 va_end(args);
68 _addProperty(name, value);
69 g_free(value);
70 }
71};
72
73}
74
75}
76
77#endif
78/*
79 Local Variables:
80 mode:c++
81 c-file-style:"stroustrup"
82 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
83 indent-tabs-mode:nil
84 fill-column:99
85 End:
86*/
87// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
void generateChildEvents() const override
std::vector< PropertyPair > _properties
void _addProperty(char const *name, char const *value)
PropertyPair property(unsigned property) const override
char const * name() const override
void _addFormattedProperty(char const *name, char const *format,...)
unsigned propertyCount() const override
void _addProperty(char const *name, long value)
void _addProperty(char const *name, std::shared_ptr< std::string > &&value)
static Category category()
SimpleEvent(char const *name)
Debugging utilities.
Definition demangle.cpp:22
Helper class to stream background task notifications as a series of messages.
va_end(args)
int const char va_start(args, fmt)