-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathchill_io.hh
70 lines (54 loc) · 2.13 KB
/
chill_io.hh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifndef CHILL_IO_HH
#define CHILL_IO_HH
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <set>
#include <type_traits>
// ----------------------------------------- //
// Stream output (for debugging, and stdout) //
// ----------------------------------------- //
// Normal chill output
#define chill_fprintf(f, ...) do { fprintf(f, __VA_ARGS__); fflush(f); } while (false)
#define chill_printf(...) do { printf(__VA_ARGS__); fflush(stdout); } while (false)
// User error messages
#define chill_error_fprintf(f, ...) chill_fprintf(f, __VA_ARGS__)
#define chill_error_printf(...) chill_fprintf(stderr, __VA_ARGS__)
#ifdef DEBUGCHILL
void debug_enable(bool enable = true);
void debug_define(char* symbol);
bool debug_isenabled();
bool debug_isdefined(char* symbol);
#define debug_fprintf(f, ...) do { if(debug_isenabled()) { chill_fprintf(f, __VA_ARGS__); } } while(false)
#define debug_printf(...) do { if(debug_isenabled()) { chill_printf(__VA_ARGS__); } } while (false)
#define debug_cond_fprintf(s, f, ...) do { if(debug_isdefined(s)) { debug_fprintf(f, __VA_ARGS__); } } while (false)
#define debug_cond_printf(s, ...) do { if(debug_isdefined(s)) { debug_printf(__VA_ARGS__); } } while (false)
template<class T>
static inline
typename std::enable_if<
std::is_integral<T>::value,
void>::type
printvec(const std::vector<T>& v) {
printf("{");
for(int i = 0; i < v.size()-1; i++) {
printf("%d, ", v[i]);
}
if(v.size() > 0) {
printf("%d", v[v.size() - 1]);
}
printf("}\n");
}
#define debug_begin if(debug_isenabled()) {
#define debug_end }
#else
#define debug_enable(...) do {} while (false)
#define debug_define(...) do {} while (false)
#define debug_fprintf(...) do {} while (false)
#define debug_printf(...) do {} while (false)
#define debug_begin if (false){
#define debug_end }
#endif
#endif