Adding listeners to Options.
[cvc5.git] / src / base / output.cpp
1 /********************* */
2 /*! \file output.cpp
3 ** \verbatim
4 ** Original author: Morgan Deters
5 ** Major contributors: none
6 ** Minor contributors (to current version): none
7 ** This file is part of the CVC4 project.
8 ** Copyright (c) 2009-2014 New York University and The University of Iowa
9 ** See the file COPYING in the top-level source directory for licensing
10 ** information.\endverbatim
11 **
12 ** \brief Output utility classes and functions
13 **
14 ** Output utility classes and functions.
15 **/
16
17 #include "base/output.h"
18
19 #include <iostream>
20
21 using namespace std;
22
23 namespace CVC4 {
24
25 /* Definitions of the declared globals from output.h... */
26
27 null_streambuf null_sb;
28 ostream null_os(&null_sb);
29
30 NullC nullCvc4Stream CVC4_PUBLIC;
31
32 const std::string CVC4ostream::s_tab = " ";
33 const int CVC4ostream::s_indentIosIndex = ios_base::xalloc();
34
35 DebugC DebugChannel CVC4_PUBLIC (&cout);
36 WarningC WarningChannel CVC4_PUBLIC (&cerr);
37 MessageC MessageChannel CVC4_PUBLIC (&cout);
38 NoticeC NoticeChannel CVC4_PUBLIC (&null_os);
39 ChatC ChatChannel CVC4_PUBLIC (&null_os);
40 TraceC TraceChannel CVC4_PUBLIC (&cout);
41 std::ostream DumpOutC::dump_cout(cout.rdbuf());// copy cout stream buffer
42 DumpOutC DumpOutChannel CVC4_PUBLIC (&DumpOutC::dump_cout);
43
44 #ifndef CVC4_MUZZLE
45
46 # if defined(CVC4_DEBUG) && defined(CVC4_TRACING)
47
48 int DebugC::printf(const char* tag, const char* fmt, ...) {
49 if(d_tags.find(string(tag)) == d_tags.end()) {
50 return 0;
51 }
52
53 // chop off output after 1024 bytes
54 char buf[1024];
55 va_list vl;
56 va_start(vl, fmt);
57 int retval = vsnprintf(buf, sizeof(buf), fmt, vl);
58 va_end(vl);
59 *d_os << buf;
60 return retval;
61 }
62
63 int DebugC::printf(std::string tag, const char* fmt, ...) {
64 if(d_tags.find(tag) == d_tags.end()) {
65 return 0;
66 }
67
68 // chop off output after 1024 bytes
69 char buf[1024];
70 va_list vl;
71 va_start(vl, fmt);
72 int retval = vsnprintf(buf, sizeof(buf), fmt, vl);
73 va_end(vl);
74 *d_os << buf;
75 return retval;
76 }
77
78 # endif /* CVC4_DEBUG && CVC4_TRACING */
79
80 int WarningC::printf(const char* fmt, ...) {
81 // chop off output after 1024 bytes
82 char buf[1024];
83 va_list vl;
84 va_start(vl, fmt);
85 int retval = vsnprintf(buf, sizeof(buf), fmt, vl);
86 va_end(vl);
87 *d_os << buf;
88 return retval;
89 }
90
91 int MessageC::printf(const char* fmt, ...) {
92 // chop off output after 1024 bytes
93 char buf[1024];
94 va_list vl;
95 va_start(vl, fmt);
96 int retval = vsnprintf(buf, sizeof(buf), fmt, vl);
97 va_end(vl);
98 *d_os << buf;
99 return retval;
100 }
101
102 int NoticeC::printf(const char* fmt, ...) {
103 // chop off output after 1024 bytes
104 char buf[1024];
105 va_list vl;
106 va_start(vl, fmt);
107 int retval = vsnprintf(buf, sizeof(buf), fmt, vl);
108 va_end(vl);
109 *d_os << buf;
110 return retval;
111 }
112
113 int ChatC::printf(const char* fmt, ...) {
114 // chop off output after 1024 bytes
115 char buf[1024];
116 va_list vl;
117 va_start(vl, fmt);
118 int retval = vsnprintf(buf, sizeof(buf), fmt, vl);
119 va_end(vl);
120 *d_os << buf;
121 return retval;
122 }
123
124 # ifdef CVC4_TRACING
125
126 int TraceC::printf(const char* tag, const char* fmt, ...) {
127 if(d_tags.find(string(tag)) == d_tags.end()) {
128 return 0;
129 }
130
131 // chop off output after 1024 bytes
132 char buf[1024];
133 va_list vl;
134 va_start(vl, fmt);
135 int retval = vsnprintf(buf, sizeof(buf), fmt, vl);
136 va_end(vl);
137 *d_os << buf;
138 return retval;
139 }
140
141 int TraceC::printf(std::string tag, const char* fmt, ...) {
142 if(d_tags.find(tag) == d_tags.end()) {
143 return 0;
144 }
145
146 // chop off output after 1024 bytes
147 char buf[1024];
148 va_list vl;
149 va_start(vl, fmt);
150 int retval = vsnprintf(buf, sizeof(buf), fmt, vl);
151 va_end(vl);
152 *d_os << buf;
153 return retval;
154 }
155
156 # endif /* CVC4_TRACING */
157
158 # ifdef CVC4_DUMPING
159
160 int DumpOutC::printf(const char* tag, const char* fmt, ...) {
161 if(d_tags.find(string(tag)) == d_tags.end()) {
162 return 0;
163 }
164
165 // chop off output after 1024 bytes
166 char buf[1024];
167 va_list vl;
168 va_start(vl, fmt);
169 int retval = vsnprintf(buf, sizeof(buf), fmt, vl);
170 va_end(vl);
171 *d_os << buf;
172 return retval;
173 }
174
175 int DumpOutC::printf(std::string tag, const char* fmt, ...) {
176 if(d_tags.find(tag) == d_tags.end()) {
177 return 0;
178 }
179
180 // chop off output after 1024 bytes
181 char buf[1024];
182 va_list vl;
183 va_start(vl, fmt);
184 int retval = vsnprintf(buf, sizeof(buf), fmt, vl);
185 va_end(vl);
186 *d_os << buf;
187 return retval;
188 }
189
190 # endif /* CVC4_DUMPING */
191
192 #endif /* ! CVC4_MUZZLE */
193
194 }/* CVC4 namespace */