Sierra Toolkit  Version of the Day
Writer.cpp
1 /*------------------------------------------------------------------------*/
2 /* Copyright 2010 Sandia Corporation. */
3 /* Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive */
4 /* license for use of this work by or on behalf of the U.S. Government. */
5 /* Export of this program may require a license from the */
6 /* United States Government. */
7 /*------------------------------------------------------------------------*/
8 
9 #include <cstdlib>
10 #include <cstring>
11 #include <string>
12 #include <iomanip>
13 #include <list>
14 
15 #include <stk_util/util/IndentStreambuf.hpp>
16 #include <stk_util/diag/Writer.hpp>
17 
18 namespace stk_classic {
19 namespace diag {
20 
21 WriterThrowSafe::WriterThrowSafe(
22  Writer & writer)
23  : m_writer(writer),
24  m_depth(writer.getDepth())
25 {}
26 
27 
28 WriterThrowSafe::~WriterThrowSafe()
29 {
30  m_writer.restoreDepth(m_depth);
31 }
32 
33 
34 Writer::Writer(
35  std::streambuf * writer_streambuf,
36  PrintMask print_mask,
37  Flags flags)
38  : m_flags(flags),
39  m_printMask(print_mask),
40  m_lineMaskStack(),
41  m_traceDepth(0),
42  m_writerStream(writer_streambuf)
43 {}
44 
45 
47 {}
48 
49 
55 Writer &
57  getStream() << std::flush;
58  return *this;
59 }
60 
69 Writer &
71  if (shouldPrint())
72  getStream() << std::endl;
73 
74  m_lineMaskStack.resetDepth();
75 
76  return *this;
77 }
78 
85 Writer &
87  if (shouldPrint()) {
88  m_lineMaskStack.pushDepth();
89  getStream() << stk_classic::push;
90  }
91 
92  return *this;
93 }
94 
101 Writer &
103  if (shouldPrint()) {
104  getStream() << stk_classic::pop;
105  m_lineMaskStack.resetDepth().pop();
106  }
107 
108  return *this;
109 }
110 
117 Writer &
119  m_lineMaskStack.popLineMask();
120 
121  return *this;
122 }
123 
130 Writer &
132  f(*this);
133  return *this;
134 }
135 
136 Writer &
138  std::ios_base & (*f)(std::ios_base&))
139 {
140  if (shouldPrint())
141  f(getStream());
142  return *this;
143 }
144 
145 
146 Writer &
148  std::ostream & (*f)(std::ostream&))
149 {
150  if (shouldPrint())
151  f(getStream());
152 
153  return *this;
154 }
155 
156 
157 Writer &
158 operator<<(
159  Writer & dout,
160  const void * ptr)
161 {
162  if (dout.shouldPrint())
163  dout.getStream() << ptr;
164 
165  return dout;
166 }
167 
168 
169 Writer &
170 operator<<(
171  Writer & dout,
172  const char * c_str)
173 {
174  if (dout.shouldPrint()) {
175  std::ostream &os = dout.getStream();
176  if (!c_str)
177  os << "(null)";
178  else
179  os << c_str;
180  }
181 
182  return dout;
183 }
184 
185 
186 Writer &
187 operator<<(
188  Writer & dout,
189  const std::string & s)
190 {
191  dout << s.c_str();
192  return dout;
193 }
194 
195 
196 Writer &
197 operator<<(
198  Writer & dout,
199  const float & x)
200 {
201  if (dout.shouldPrint())
202  dout.getStream() << x;
203 
204  return dout;
205 }
206 
207 
208 Writer &
209 operator<<(
210  Writer & dout,
211  const double & x)
212 {
213  if (dout.shouldPrint())
214  dout.getStream() << x;
215 
216  return dout;
217 }
218 
219 
220 Writer &
221 operator<<(
222  Writer & dout,
223  const long double & x)
224 {
225  if (dout.shouldPrint())
226  dout.getStream() << x;
227 
228  return dout;
229 }
230 
231 
232 Writer &
233 operator<<(
234  Writer & dout,
235  const int & x)
236 {
237  if (dout.shouldPrint())
238  dout.getStream() << x;
239 
240  return dout;
241 }
242 
243 
244 Writer &
245 operator<<(
246  Writer & dout,
247  const unsigned int & x)
248 {
249  if (dout.shouldPrint())
250  dout.getStream() << x;
251 
252  return dout;
253 }
254 
255 
256 Writer &
257 operator<<(
258  Writer & dout,
259  const long & x)
260 {
261  if (dout.shouldPrint())
262  dout.getStream() << x;
263 
264  return dout;
265 }
266 
267 
268 Writer &
269 operator<<(
270  Writer & dout,
271  const unsigned long & x)
272 {
273  if (dout.shouldPrint())
274  dout.getStream() << x;
275 
276  return dout;
277 }
278 
279 Writer &
280 operator<<(
281  Writer & dout,
282  const long long & x)
283 {
284  if (dout.shouldPrint())
285  dout.getStream() << x;
286 
287  return dout;
288 }
289 
290 Writer &
291 operator<<(
292  Writer & dout,
293  const unsigned long long & x)
294 {
295  if (dout.shouldPrint())
296  dout.getStream() << x;
297 
298  return dout;
299 }
300 
301 Writer &
302 operator<<(
303  Writer & dout,
304  const short & x)
305 {
306  if (dout.shouldPrint())
307  dout.getStream() << x;
308 
309  return dout;
310 }
311 
312 
313 Writer &
314 operator<<(
315  Writer & dout,
316  const unsigned short & x)
317 {
318  if (dout.shouldPrint())
319  dout.getStream() << x;
320 
321  return dout;
322 }
323 
324 
325 } // namespace diag
326 } // namespace stk_classic
327 
328 namespace sierra {
329 namespace Diag {
330 
331 Writer &
332 operator<<(
333  Writer & dout,
334  const String & str)
335 {
336  if (dout.shouldPrint())
337  dout.getStream() << str;
338 
339  return dout;
340 }
341 
342 
343 Writer &
344 operator<<(
345  Writer & dout,
346  const sierra::Identifier & s)
347 {
348  if (dout.shouldPrint())
349  dout.getStream() << '\'' << s << '\'';
350 
351  return dout;
352 }
353 
354 } // namespace Diag
355 } // namespace sierra
356 
Writer & resetLineMask()
Member function pop is a manipulator which decreases the line mask depth by one, but not less than ze...
Definition: Writer.cpp:118
std::ostream & dout()
Diagnostic output stream.
Definition: OutputLog.cpp:674
Writer & dflush()
Member function dflush flushes the output stream.
Definition: Writer.cpp:56
Writer & operator<<(Writer &(*f)(Writer &))
Member function operator<< is the manipulator instantiation function.
Definition: Writer.cpp:131
Definition: Env.cpp:53
Writer & dendl()
Member function dendl is a manipulator which sets the output stream to a new line.
Definition: Writer.cpp:70
Writer & push()
Member function push is a manipulator which increases the line mask depth by one. ...
Definition: Writer.cpp:86
~Writer()
Destroys a Writer instance.
Definition: Writer.cpp:46
std::ostream & getStream()
Member function getStream returns the output stream.
Definition: Writer.hpp:210
std::ostream & operator<<(std::ostream &s, const Bucket &k)
Print the part names for which this bucket is a subset.
Definition: Bucket.cpp:239
bool shouldPrint()
Member function shouldPrint returns true if the line should print.
Definition: Writer.hpp:369
Sierra Toolkit.
Class Writer implements a runtime selectable diagnostic output writer to aid in the development and d...
Definition: Writer.hpp:49
Writer & pop()
Member function pop is a manipulator which decreases the line mask depth by one, but not less than ze...
Definition: Writer.cpp:102
Flags
Enumeration Flags.
Definition: Writer.hpp:60