annotate gen/logger.c @ 38:27b2f40bdb58 trunk

[svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back. Fiddled a bit the the testing system. Added a very simple SDL graphics demo.
author lindquist
date Wed, 10 Oct 2007 06:16:48 +0200
parents e116aa1488e6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
1 #include <cassert>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
2 #include <cstdarg>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
3 #include <cstdio>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
4 #include <cstdlib>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
5 #include <iostream>
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
6 #include <fstream>
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
7 #include <string>
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
8
4
e116aa1488e6 [svn r8] changed backend includes to always use the gen/<foo>.h prefix
lindquist
parents: 1
diff changeset
9 #include "gen/logger.h"
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
10
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
11 namespace Logger
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
12 {
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
13 static std::string indent_str;
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
14 static std::ofstream null_out("/dev/null");
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
15
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
16 static bool enabled = false;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
17 void indent()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
18 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
19 if (enabled)
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
20 indent_str += " ";
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
21 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
22 void undent()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
23 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
24 if (enabled) {
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
25 assert(!indent_str.empty());
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
26 indent_str.resize(indent_str.size()-2);
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
27 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
28 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
29 std::ostream& cout()
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
30 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
31 if (enabled)
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
32 return std::cout << indent_str;
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
33 else
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
34 return null_out;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
35 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
36 void println(const char* fmt,...)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
37 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
38 if (enabled) {
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
39 printf(indent_str.c_str());
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
40 va_list va;
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
41 va_start(va,fmt);
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
42 vprintf(fmt,va);
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
43 va_end(va);
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
44 printf("\n");
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
45 }
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
46 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
47 void print(const char* fmt,...)
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
48 {
38
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
49 if (enabled) {
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
50 printf(indent_str.c_str());
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
51 va_list va;
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
52 va_start(va,fmt);
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
53 vprintf(fmt,va);
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
54 va_end(va);
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
55 }
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
56 }
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
57 void enable()
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
58 {
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
59 enabled = true;
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
60 }
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
61 void disable()
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
62 {
27b2f40bdb58 [svn r42] Disabled the extensive logging by default. Use the -vv flag to get it back.
lindquist
parents: 4
diff changeset
63 enabled = false;
1
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
64 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
65 }
c53b6e3fe49a [svn r5] Initial commit. Most things are very rough.
lindquist
parents:
diff changeset
66