1 /*
2 * Inkscape::Debug::EventTracker - semi-automatically track event lifetimes
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_EVENT_TRACKER_H
13 #define SEEN_INKSCAPE_DEBUG_EVENT_TRACKER_H
15 #include "debug/logger.h"
17 namespace Inkscape {
19 namespace Debug {
21 struct NoInitialEvent {};
23 template <typename Event=NoInitialEvent> class EventTracker;
25 class EventTrackerBase {
26 public:
27 virtual ~EventTrackerBase() {
28 if (_active) {
29 Logger::finish();
30 }
31 }
33 template <typename EventType>
34 inline void set() {
35 if (_active) {
36 Logger::finish();
37 }
38 Logger::start<EventType>();
39 _active = true;
40 }
42 template <typename EventType, typename A>
43 inline void set(A const &a) {
44 if (_active) {
45 Logger::finish();
46 }
47 Logger::start<EventType>(a);
48 _active = true;
49 }
51 template <typename EventType, typename A, typename B>
52 inline void set(A const &a, B const &b) {
53 if (_active) {
54 Logger::finish();
55 }
56 Logger::start<EventType>(a, b);
57 _active = true;
58 }
60 template <typename EventType, typename A, typename B, typename C>
61 inline void set(A const &a, B const &b, C const &c) {
62 if (_active) {
63 Logger::finish();
64 }
65 Logger::start<EventType>(a, b, c);
66 _active = true;
67 }
69 template <typename EventType, typename A, typename B,
70 typename C, typename D>
71 inline void set(A const &a, B const &b, C const &c, D const &d) {
72 if (_active) {
73 Logger::finish();
74 }
75 Logger::start<EventType>(a, b, c, d);
76 _active = true;
77 }
79 template <typename EventType, typename A, typename B, typename C,
80 typename D, typename E>
81 inline void set(A const &a, B const &b, C const &c, D const &d, E const &e)
82 {
83 if (_active) {
84 Logger::finish();
85 }
86 Logger::start<EventType>(a, b, c, d, e);
87 _active = true;
88 }
90 template <typename EventType, typename A, typename B, typename C,
91 typename D, typename E, typename F>
92 inline void set(A const &a, B const &b, C const &c,
93 D const &d, E const &e, F const &f)
94 {
95 if (_active) {
96 Logger::finish();
97 }
98 Logger::start<EventType>(a, b, c, d, e, f);
99 _active = true;
100 }
102 template <typename EventType, typename A, typename B, typename C,
103 typename D, typename E, typename F,
104 typename G>
105 inline void set(A const &a, B const &b, C const &c, D const &d,
106 E const &e, F const &f, G const &g)
107 {
108 if (_active) {
109 Logger::finish();
110 }
111 Logger::start<EventType>(a, b, c, d, e, f, g);
112 _active = true;
113 }
115 template <typename EventType, typename A, typename B, typename C,
116 typename D, typename E, typename F,
117 typename G, typename H>
118 inline void set(A const &a, B const &b, C const &c, D const &d,
119 E const &e, F const &f, G const &g, H const &h)
120 {
121 if (_active) {
122 Logger::finish();
123 }
124 Logger::start<EventType>(a, b, c, d, e, f, g, h);
125 _active = true;
126 }
128 void clear() {
129 if (_active) {
130 Logger::finish();
131 _active = false;
132 }
133 }
135 protected:
136 EventTrackerBase(bool active) : _active(active) {}
138 private:
139 EventTrackerBase(EventTrackerBase const &); // no copy
140 void operator=(EventTrackerBase const &); // no assign
141 bool _active;
142 };
144 template <typename EventType> class EventTracker : public EventTrackerBase {
145 public:
146 EventTracker() : EventTrackerBase(true) { Logger::start<EventType>(); }
148 template <typename A>
149 EventTracker(A const &a) : EventTrackerBase(true) {
150 Logger::start<EventType>(a);
151 }
153 template <typename A, typename B>
154 EventTracker(A const &a, B const &b) : EventTrackerBase(true) {
155 Logger::start<EventType>(a, b);
156 }
158 template <typename A, typename B, typename C>
159 EventTracker(A const &a, B const &b, C const &c) : EventTrackerBase(true) {
160 Logger::start<EventType>(a, b, c);
161 }
163 template <typename A, typename B, typename C, typename D>
164 EventTracker(A const &a, B const &b, C const &c, D const &d)
165 : EventTrackerBase(true)
166 {
167 Logger::start<EventType>(a, b, c, d);
168 }
170 template <typename A, typename B, typename C, typename D, typename E>
171 EventTracker(A const &a, B const &b, C const &c, D const &d, E const &e)
172 : EventTrackerBase(true)
173 {
174 Logger::start<EventType>(a, b, c, d, e);
175 }
177 template <typename A, typename B, typename C, typename D,
178 typename E, typename F>
179 EventTracker(A const &a, B const &b, C const &c, D const &d,
180 E const &e, F const &f)
181 : EventTrackerBase(true)
182 {
183 Logger::start<EventType>(a, b, c, d, e, f);
184 }
186 template <typename A, typename B, typename C, typename D,
187 typename E, typename F, typename G>
188 EventTracker(A const &a, B const &b, C const &c, D const &d,
189 E const &e, F const &f, G const &g)
190 : EventTrackerBase(true)
191 {
192 Logger::start<EventType>(a, b, c, d, e, f, g);
193 }
195 template <typename A, typename B, typename C, typename D,
196 typename E, typename F, typename G, typename H>
197 EventTracker(A const &a, B const &b, C const &c, D const &d,
198 E const &e, F const &f, G const &g, H const &h)
199 : EventTrackerBase(true)
200 {
201 Logger::start<EventType>(a, b, c, d, e, f, g, h);
202 }
203 };
205 template <> class EventTracker<NoInitialEvent> : public EventTrackerBase {
206 public:
207 EventTracker() : EventTrackerBase(false) {}
208 };
210 }
212 }
214 #endif
215 /*
216 Local Variables:
217 mode:c++
218 c-file-style:"stroustrup"
219 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
220 indent-tabs-mode:nil
221 fill-column:99
222 End:
223 */
224 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :