Mercurial > ~dholland > hg > ag > index.cgi
comparison anagram/support/log.h @ 0:13d2b8934445
Import AnaGram (near-)release tree into Mercurial.
author | David A. Holland |
---|---|
date | Sat, 22 Dec 2007 17:52:45 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:13d2b8934445 |
---|---|
1 /* | |
2 * AnaGram, A System for Syntax Directed Programming | |
3 * Copyright 1993-2002 Parsifal Software. All Rights Reserved. | |
4 * Copyright 2006 David A. Holland. All Rights Reserved. | |
5 * See the file COPYING for license and usage terms. | |
6 * | |
7 * log.h - logging | |
8 */ | |
9 | |
10 #ifndef LOG_H | |
11 #define LOG_H | |
12 | |
13 #ifdef VACLGUI | |
14 #include <ipoint.hpp> | |
15 #include <irect.hpp> | |
16 #include <istring.hpp> | |
17 #include <iexcbase.hpp> | |
18 #endif | |
19 | |
20 class AgString; // from agstr.h | |
21 struct cint; // from cint.h | |
22 | |
23 #ifdef INCLUDE_LOGGING | |
24 | |
25 enum LogSwitch { | |
26 LOG_OFF, // logging is disabled | |
27 LOG_MAYBE, // logging switch inherits from context | |
28 LOG_ON, // logging is enabled | |
29 }; | |
30 | |
31 class LogSection { | |
32 protected: | |
33 LogSection *previous; | |
34 const char *name; | |
35 LogSwitch saved_switch; | |
36 public: | |
37 // the name passed in should be a string constant | |
38 LogSection(const char *name, LogSwitch requested_setting); | |
39 ~LogSection(); | |
40 | |
41 static void logstack(); | |
42 }; | |
43 | |
44 /* start a nested (sub)section, which lasts until end of scope */ | |
45 #define LOGSECTION(name) LogSection myLogSection(name, LOG_MAYBE) | |
46 #define LOGSECTION_OFF(name) LogSection myLogSection(name, LOG_OFF) | |
47 #define LOGSECTION_ON(name) LogSection myLogSection(name, LOG_ON) | |
48 | |
49 /* Logging macros. */ | |
50 | |
51 /* | |
52 * LOGV logs a variable, with its name and value. | |
53 * LOGS logs a literal string. | |
54 */ | |
55 | |
56 #define LOGV(v) (logeol(), dolog(#v " = "), dolog(v)) | |
57 #define LOGS(s) (logeol(), dolog(s)) | |
58 | |
59 /* The L... forms are for appending after a LOGV/LOGS in the same expression.*/ | |
60 #define LV(v) , (dolog(" " #v " = "), dolog(v)) | |
61 #define LS(s) , (dolog(" "), dolog(s)) | |
62 | |
63 /* The LC... forms are the same but insert a comma. */ | |
64 #define LCV(v) , (dolog(", " #v " = "), dolog(v)) | |
65 #define LCS(s) , (dolog(", "), dolog(s)) | |
66 | |
67 /* LOGX is for sticking in front of LV/LCV/whatnot to avoid the newline */ | |
68 #define LOGX() ((void)0) | |
69 | |
70 /* Misc. */ | |
71 #define LOGINIT() | |
72 #define LOGSTACK LogSection::logstack() | |
73 #define LOGEXCEPTION(e) logexception(e) | |
74 | |
75 /* This can be used to enclose bits of expression only used when logging. */ | |
76 #define IFLOG(x) x | |
77 | |
78 /* The underlying functions */ | |
79 void logeol(void); | |
80 void logtime(void); | |
81 | |
82 void dolog(const char *); | |
83 void dolog(const AgString &); | |
84 void dolog(void *); | |
85 void dolog(int); | |
86 void dolog(cint); | |
87 | |
88 #ifdef VACLGUI | |
89 void logexception(IException &); | |
90 void dolog(const IString &s); | |
91 void dolog(const IPair &p); | |
92 void dolog(const IRectangle &r); | |
93 #endif | |
94 | |
95 | |
96 #else | |
97 | |
98 /* With logging off, nothing exists */ | |
99 | |
100 #define LOGSECTION(name) | |
101 #define LOGSECTION_OFF(name) | |
102 #define LOGSECTION_ON(name) | |
103 #define LOGV(x) | |
104 #define LOGS(x) | |
105 #define LV(x) | |
106 #define LS(x) | |
107 #define LCV(x) | |
108 #define LCS(X) | |
109 #define LOGX() | |
110 #define LOGINIT() | |
111 #define LOGSTACK | |
112 #define LOGEXCEPTION(e) | |
113 | |
114 #define IFLOG(x) | |
115 | |
116 #endif /* INCLUDE_LOGGING */ | |
117 | |
118 #endif /* LOG_H */ |