1 #ifndef YTRACE_H 2 #define YTRACE_H 3 4 class YTrace { 5 public: 6 YTrace(const char* kind, const char* inst = nullptr, bool busy = true) : kind(kind)7 kind(kind), inst(inst), busy(busy), 8 have(kind && traces(kind)) { } ~YTrace()9 virtual ~YTrace() { } 10 done()11 void done() { 12 if (busy && inst && have) { 13 busy = false; 14 show(); 15 } 16 } 17 18 void init(const char* inst, bool busy = true) { 19 done(); 20 this->inst = inst; 21 this->busy = busy; 22 if (busy && inst && have) { 23 show(); 24 } 25 } 26 tracing(const char * conf)27 static void tracing(const char* conf) { 28 YTrace::conf = conf; 29 } tracingConf()30 static const char* tracingConf() { 31 return conf; 32 } 33 tracing()34 bool tracing() const { 35 return have; 36 } 37 traces(const char * kind)38 static bool traces(const char* kind) { 39 return conf && strstr(conf, kind); 40 } 41 42 protected: show()43 virtual void show() { if (have && inst) show(busy, kind, inst); } 44 virtual void show(bool busy, const char* kind, const char* inst); getKind()45 const char* getKind() const { return kind; } getInst()46 const char* getInst() const { return inst; } 47 48 private: 49 const char* kind; 50 const char* inst; 51 bool busy, have; 52 static const char* conf; 53 }; 54 55 class YTraceIcon : public YTrace { 56 public: 57 YTraceIcon(const char* inst = nullptr, bool busy = true) : 58 YTrace("icon", inst, busy) { show(); } ~YTraceIcon()59 ~YTraceIcon() { } 60 }; 61 62 class YTraceConfig : public YTrace { 63 public: 64 YTraceConfig(const char* inst = nullptr, bool busy = true) : 65 YTrace("conf", inst, busy) { show(); } ~YTraceConfig()66 ~YTraceConfig() { done(); } 67 }; 68 69 class YTraceProg : public YTrace { 70 public: 71 YTraceProg(const char* inst = nullptr, bool busy = true) : 72 YTrace("prog", inst, busy) { show(); } ~YTraceProg()73 ~YTraceProg() { } 74 }; 75 76 class YTraceFont : public YTrace { 77 class YFontBase* base; 78 public: 79 YTraceFont(const char* inst = nullptr, YFontBase* base = nullptr) : 80 YTrace("font", inst), base(base) { YTrace::show(); } ~YTraceFont()81 ~YTraceFont() { } 82 void show(bool busy, const char* kind, const char* inst) override; 83 }; 84 85 #endif 86