1 // SPDX-License-Identifier: GPL-2.0-or-later 2 /* 3 * Inkscape::Debug::Logger - debug logging facility 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_LOGGER_H 14 #define SEEN_INKSCAPE_DEBUG_LOGGER_H 15 16 #include "debug/event.h" 17 18 namespace Inkscape { 19 20 namespace Debug { 21 22 class Logger { 23 public: 24 static void init(); 25 26 template <typename EventType> start()27 inline static void start() { 28 if (_enabled) { 29 if (_category_mask[EventType::category()]) { 30 _start(EventType()); 31 } else { 32 _skip(); 33 } 34 } 35 } 36 37 template <typename EventType, typename A> start(A const & a)38 inline static void start(A const &a) { 39 if (_enabled) { 40 if (_category_mask[EventType::category()]) { 41 _start(EventType(a)); 42 } else { 43 _skip(); 44 } 45 } 46 } 47 48 template <typename EventType, typename A, typename B> start(A const & a,B const & b)49 inline static void start(A const &a, B const &b) { 50 if (_enabled) { 51 if (_category_mask[EventType::category()]) { 52 _start(EventType(a, b)); 53 } else { 54 _skip(); 55 } 56 } 57 } 58 59 template <typename EventType, typename A, typename B, typename C> start(A const & a,B const & b,C const & c)60 inline static void start(A const &a, B const &b, C const &c) { 61 if (_enabled) { 62 if (_category_mask[EventType::category()]) { 63 _start(EventType(a, b, c)); 64 } else { 65 _skip(); 66 } 67 } 68 } 69 70 template <typename EventType, typename A, typename B, 71 typename C, typename D> start(A const & a,B const & b,C const & c,D const & d)72 inline static void start(A const &a, B const &b, C const &c, D const &d) { 73 if (_enabled) { 74 if (_category_mask[EventType::category()]) { 75 _start(EventType(a, b, c, d)); 76 } else { 77 _skip(); 78 } 79 } 80 } 81 82 template <typename EventType, typename A, typename B, typename C, 83 typename D, typename E> start(A const & a,B const & b,C const & c,D const & d,E const & e)84 inline static void start(A const &a, B const &b, C const &c, 85 D const &d, E const &e) 86 { 87 if (_enabled) { 88 if (_category_mask[EventType::category()]) { 89 _start(EventType(a, b, c, d, e)); 90 } else { 91 _skip(); 92 } 93 } 94 } 95 96 template <typename EventType, typename A, typename B, typename C, 97 typename D, typename E, typename F> start(A const & a,B const & b,C const & c,D const & d,E const & e,F const & f)98 inline static void start(A const &a, B const &b, C const &c, 99 D const &d, E const &e, F const &f) 100 { 101 if (_enabled) { 102 if (_category_mask[EventType::category()]) { 103 _start(EventType(a, b, c, d, e, f)); 104 } else { 105 _skip(); 106 } 107 } 108 } 109 110 template <typename EventType, typename A, typename B, typename C, 111 typename D, typename E, typename F, 112 typename G> start(A const & a,B const & b,C const & c,D const & d,E const & e,F const & f,G const & g)113 inline static void start(A const &a, B const &b, C const &c, D const &d, 114 E const &e, F const &f, G const &g) 115 { 116 if (_enabled) { 117 if (_category_mask[EventType::category()]) { 118 _start(EventType(a, b, c, d, e, f, g)); 119 } else { 120 _skip(); 121 } 122 } 123 } 124 125 template <typename EventType, typename A, typename B, typename C, 126 typename D, typename E, typename F, 127 typename G, typename H> start(A const & a,B const & b,C const & c,D const & d,E const & e,F const & f,G const & g,H const & h)128 inline static void start(A const &a, B const &b, C const &c, D const &d, 129 E const &e, F const &f, G const &g, H const &h) 130 { 131 if (_enabled) { 132 if (_category_mask[EventType::category()]) { 133 _start(EventType(a, b, c, d, e, f, g, h)); 134 } else { 135 _skip(); 136 } 137 } 138 } 139 finish()140 inline static void finish() { 141 if (_enabled) { 142 _finish(); 143 } 144 } 145 146 template <typename EventType> write()147 inline static void write() { 148 start<EventType>(); 149 finish(); 150 } 151 152 template <typename EventType, typename A> write(A const & a)153 inline static void write(A const &a) { 154 start<EventType, A>(a); 155 finish(); 156 } 157 158 template <typename EventType, typename A, typename B> write(A const & a,B const & b)159 inline static void write(A const &a, B const &b) { 160 start<EventType, A, B>(a, b); 161 finish(); 162 } 163 164 template <typename EventType, typename A, typename B, typename C> write(A const & a,B const & b,C const & c)165 inline static void write(A const &a, B const &b, C const &c) { 166 start<EventType, A, B, C>(a, b, c); 167 finish(); 168 } 169 170 template <typename EventType, typename A, typename B, 171 typename C, typename D> write(A const & a,B const & b,C const & c,D const & d)172 inline static void write(A const &a, B const &b, C const &c, D const &d) { 173 start<EventType, A, B, C, D>(a, b, c, d); 174 finish(); 175 } 176 177 template <typename EventType, typename A, typename B, 178 typename C, typename D, 179 typename E> write(A const & a,B const & b,C const & c,D const & d,E const & e)180 inline static void write(A const &a, B const &b, C const &c, 181 D const &d, E const &e) 182 { 183 start<EventType, A, B, C, D, E>(a, b, c, d, e); 184 finish(); 185 } 186 187 template <typename EventType, typename A, typename B, 188 typename C, typename D, 189 typename E, typename F> write(A const & a,B const & b,C const & c,D const & d,E const & e,F const & f)190 inline static void write(A const &a, B const &b, C const &c, 191 D const &d, E const &e, F const &f) 192 { 193 start<EventType, A, B, C, D, E, F>(a, b, c, d, e, f); 194 finish(); 195 } 196 197 template <typename EventType, typename A, typename B, 198 typename C, typename D, 199 typename E, typename F, 200 typename G> write(A const & a,B const & b,C const & c,D const & d,E const & e,F const & f,G const & g)201 inline static void write(A const &a, B const &b, C const &c, 202 D const &d, E const &e, F const &f, 203 G const &g) 204 { 205 start<EventType, A, B, C, D, E, F, G>(a, b, c, d, e, f, g); 206 finish(); 207 } 208 209 template <typename EventType, typename A, typename B, 210 typename C, typename D, 211 typename E, typename F, 212 typename G, typename H> write(A const & a,B const & b,C const & c,D const & d,E const & e,F const & f,G const & g,H const & h)213 inline static void write(A const &a, B const &b, C const &c, 214 D const &d, E const &e, F const &f, 215 G const &g, H const &h) 216 { 217 start<EventType, A, B, C, D, E, F, G, H>(a, b, c, d, e, f, g, h); 218 finish(); 219 } 220 221 static void shutdown(); 222 223 private: 224 static bool _enabled; 225 226 static void _start(Event const &event); 227 static void _skip(); 228 static void _finish(); 229 230 static bool _category_mask[Event::N_CATEGORIES]; 231 }; 232 233 } 234 235 } 236 237 #endif 238 /* 239 Local Variables: 240 mode:c++ 241 c-file-style:"stroustrup" 242 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) 243 indent-tabs-mode:nil 244 fill-column:99 245 End: 246 */ 247 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : 248