aboutsummaryrefslogtreecommitdiff
path: root/src/stable/trace.h
diff options
context:
space:
mode:
authorMike Buland <eichlan@xagasoft.com>2012-03-25 20:00:08 +0000
committerMike Buland <eichlan@xagasoft.com>2012-03-25 20:00:08 +0000
commit469bbcf0701e1eb8a6670c23145b0da87357e178 (patch)
treeb5b062a16e46a6c5d3410b4e574cd0cc09057211 /src/stable/trace.h
parentee1b79396076edc4e30aefb285fada03bb45e80d (diff)
downloadlibbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.gz
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.bz2
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.tar.xz
libbu++-469bbcf0701e1eb8a6670c23145b0da87357e178.zip
Code is all reorganized. We're about ready to release. I should write up a
little explenation of the arrangement.
Diffstat (limited to 'src/stable/trace.h')
-rw-r--r--src/stable/trace.h187
1 files changed, 187 insertions, 0 deletions
diff --git a/src/stable/trace.h b/src/stable/trace.h
new file mode 100644
index 0000000..51dfb8e
--- /dev/null
+++ b/src/stable/trace.h
@@ -0,0 +1,187 @@
1/*
2 * Copyright (C) 2007-2011 Xagasoft, All rights reserved.
3 *
4 * This file is part of the libbu++ library and is released under the
5 * terms of the license contained in the file LICENSE.
6 */
7
8#ifndef BU_TRACE_H
9#define BU_TRACE_H
10
11#include <stdio.h>
12#include <stdint.h>
13#include <stddef.h>
14#include <string.h>
15
16#include <bu/sio.h>
17
18namespace Bu
19{
20/* template<typename t> void __tracer_format( t &v )
21 {
22 __tracer_format( *const_cast<const t *>(&v) );
23 }
24*/
25 template<typename t> void __tracer_format( const t &v )
26 {
27 Bu::sio << v;
28 }
29
30 void __tracer( const char *pf );
31
32 #define looper( vv ) \
33 for( ; *n; n++ ) \
34 { \
35 if( bInBracket == true ) \
36 { \
37 if( *n == '>' ) \
38 bInBracket = false; \
39 } \
40 else if( *n == ',' || *n == ')' ) \
41 { \
42 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, 1, stdout ); \
43 fwrite("=", 1, 1, stdout); \
44 __tracer_format( vv ); \
45 s = n; \
46 n++; \
47 break; \
48 } \
49 else if( *n == '<' ) \
50 { \
51 bInBracket = true; \
52 } \
53 } (void)0
54
55 template<typename t1> void __tracer( const char *pf, t1 &v1 )
56 {
57 printf("trace: ");
58 const char *s = pf;
59 const char *n = pf;
60 bool bInBracket = false;
61 looper( v1 );
62 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, strlen(s), stdout );
63 fwrite( "\n", 1, 1, stdout );
64 fflush( stdout );
65 }
66
67 template<typename t1, typename t2> void __tracer( const char *pf,
68 t1 &v1, t2 &v2 )
69 {
70 printf("trace: ");
71 const char *s = pf;
72 const char *n = pf;
73 bool bInBracket = false;
74 looper( v1 );
75 looper( v2 );
76 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, strlen(s), stdout );
77 fwrite( "\n", 1, 1, stdout );
78 fflush( stdout );
79 }
80
81 template<typename t1, typename t2, typename t3>
82 void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3 )
83 {
84 printf("trace: ");
85 const char *s = pf;
86 const char *n = pf;
87 bool bInBracket = false;
88 looper( v1 );
89 looper( v2 );
90 looper( v3 );
91 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, strlen(s), stdout );
92 fwrite( "\n", 1, 1, stdout );
93 fflush( stdout );
94 }
95
96 template<typename t1, typename t2, typename t3, typename t4>
97 void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4 )
98 {
99 printf("trace: ");
100 const char *s = pf;
101 const char *n = pf;
102 bool bInBracket = false;
103 looper( v1 );
104 looper( v2 );
105 looper( v3 );
106 looper( v4 );
107 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, strlen(s), stdout );
108 fwrite( "\n", 1, 1, stdout );
109 fflush( stdout );
110 }
111
112 template<typename t1, typename t2, typename t3, typename t4, typename t5>
113 void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5 )
114 {
115 printf("trace: ");
116 const char *s = pf;
117 const char *n = pf;
118 bool bInBracket = false;
119 looper( v1 );
120 looper( v2 );
121 looper( v3 );
122 looper( v4 );
123 looper( v5 );
124 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, strlen(s), stdout );
125 fwrite( "\n", 1, 1, stdout );
126 fflush( stdout );
127 }
128
129 template<typename t1, typename t2, typename t3, typename t4, typename t5,
130 typename t6>
131 void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5,
132 t6 &v6)
133 {
134 printf("trace: ");
135 const char *s = pf;
136 const char *n = pf;
137 bool bInBracket = false;
138 looper( v1 );
139 looper( v2 );
140 looper( v3 );
141 looper( v4 );
142 looper( v5 );
143 looper( v6 );
144 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, strlen(s), stdout );
145 fwrite( "\n", 1, 1, stdout );
146 fflush( stdout );
147 }
148
149 template<typename t1, typename t2, typename t3, typename t4, typename t5,
150 typename t6, typename t7>
151 void __tracer( const char *pf, t1 &v1, t2 &v2, t3 &v3, t4 &v4, t5 &v5,
152 t6 &v6, t7 &v7 )
153 {
154 printf("trace: ");
155 const char *s = pf;
156 const char *n = pf;
157 bool bInBracket = false;
158 looper( v1 );
159 looper( v2 );
160 looper( v3 );
161 looper( v4 );
162 looper( v5 );
163 looper( v6 );
164 looper( v7 );
165 fwrite( s, (ptrdiff_t)n-(ptrdiff_t)s, strlen(s), stdout );
166 fwrite( "\n", 1, 1, stdout );
167 fflush( stdout );
168 }
169#undef looper
170
171 template<> void __tracer_format<float>( const float &v );
172 template<> void __tracer_format<double>( const double &v );
173 template<> void __tracer_format<void *>( void * const &v );
174 template<> void __tracer_format<char *>( char * const &v );
175 template<> void __tracer_format<char **>( char ** const &v );
176 template<> void __tracer_format<void const *>( void const * const &v );
177 template<> void __tracer_format<char const *>( char const * const &v );
178 template<> void __tracer_format<char const **>( char const ** const &v );
179}
180
181#ifdef BU_TRACE
182# define TRACE(args...) Bu::__tracer( __PRETTY_FUNCTION__, ##args )
183#else
184# define TRACE(args...) (void)0
185#endif
186
187#endif