Reference documentation for deal.II version 9.1.0-pre
logstream.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2017 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_logstream_h
17 #define dealii_logstream_h
18 
19 #include <deal.II/base/config.h>
20 
21 #include <deal.II/base/exceptions.h>
22 #include <deal.II/base/smartpointer.h>
23 #include <deal.II/base/thread_local_storage.h>
24 
25 #include <cmath>
26 #include <map>
27 #include <memory>
28 #include <sstream>
29 #include <stack>
30 #include <string>
31 
32 
33 DEAL_II_NAMESPACE_OPEN
34 
82 class LogStream : public Subscriptor
83 {
84 public:
102  class Prefix
103  {
104  public:
109  Prefix(const std::string &text);
110 
115  Prefix(const std::string &text, LogStream &stream);
116 
120  ~Prefix();
121 
122  private:
128  };
129 
130 
135  LogStream();
136 
137 
141  ~LogStream() override;
142 
143 
149  void
150  attach(std::ostream &o, const bool print_job_id = true);
151 
152 
157  void
158  detach();
159 
160 
164  std::ostream &
165  get_console();
166 
167 
171  std::ostream &
172  get_file_stream();
173 
174 
179  bool
180  has_file() const;
181 
182 
186  const std::string &
187  get_prefix() const;
188 
189 
202  void
203  push(const std::string &text);
204 
205 
209  void
210  pop();
211 
212 
223  unsigned int
224  depth_console(const unsigned int n);
225 
226 
234  unsigned int
235  depth_file(const unsigned int n);
236 
237 
241  bool
242  log_thread_id(const bool flag);
243 
244 
250  std::streamsize
251  precision(const std::streamsize prec);
252 
253 
259  std::streamsize
260  width(const std::streamsize wide);
261 
262 
268  std::ios::fmtflags
269  flags(const std::ios::fmtflags f);
270 
271 
286  LogStream &
287  operator<<(std::ostream &(*p)(std::ostream &));
288 
289 
295  std::size_t
296  memory_consumption() const;
297 
298 private:
306  std::stack<std::string> &
307  get_prefixes() const;
308 
314 
320  std::ostream *std_out;
321 
328  std::ostream *file;
329 
336  unsigned int std_depth;
337 
341  unsigned int file_depth;
342 
347 
352 
356  void
357  print_line_head();
358 
363  std::ostringstream &
364  get_stream();
365 
371 
372  template <typename T>
373  friend LogStream &
374  operator<<(LogStream &log, const T &t);
375 };
376 
377 
378 /* ----------------------------- Inline functions and templates ----------------
379  */
380 
381 
389 template <typename T>
390 inline LogStream &
391 operator<<(LogStream &log, const T &t)
392 {
393  // print to the internal stringstream
394  log.get_stream() << t;
395  return log;
396 }
397 
398 
399 
405 extern LogStream deallog;
406 
407 
408 
409 DEAL_II_NAMESPACE_CLOSE
410 
411 #endif
void pop()
Definition: logstream.cc:313
std::streamsize precision(const std::streamsize prec)
Definition: logstream.cc:330
A class that provides a separate storage location on each thread that accesses the object...
const std::string & get_prefix() const
Definition: logstream.cc:286
std::ostream * std_out
Definition: logstream.h:320
Threads::ThreadLocalStorage< std::stack< std::string > > prefixes
Definition: logstream.h:313
std::size_t memory_consumption() const
bool print_thread_id
Definition: logstream.h:346
~LogStream() override
Definition: logstream.cc:87
unsigned int depth_file(const unsigned int n)
Definition: logstream.cc:357
unsigned int std_depth
Definition: logstream.h:336
bool has_file() const
Definition: logstream.cc:278
std::streamsize width(const std::streamsize wide)
Definition: logstream.cc:338
bool log_thread_id(const bool flag)
Definition: logstream.cc:368
std::ostream & get_file_stream()
Definition: logstream.cc:267
std::stack< std::string > & get_prefixes() const
Definition: logstream.cc:379
std::ios::fmtflags flags(const std::ios::fmtflags f)
Definition: logstream.cc:322
unsigned int depth_console(const unsigned int n)
Definition: logstream.cc:346
void print_line_head()
Definition: logstream.cc:413
std::ostream * file
Definition: logstream.h:328
SmartPointer< LogStream, LogStream::Prefix > stream
Definition: logstream.h:127
void attach(std::ostream &o, const bool print_job_id=true)
Definition: logstream.cc:217
Prefix(const std::string &text)
Definition: logstream.cc:40
std::ostream & get_console()
Definition: logstream.cc:236
bool at_newline
Definition: logstream.h:351
Threads::ThreadLocalStorage< std::shared_ptr< std::ostringstream > > outstreams
Definition: logstream.h:370
void push(const std::string &text)
Definition: logstream.cc:299
LogStream & operator<<(std::ostream &(*p)(std::ostream &))
Definition: logstream.cc:124
void detach()
Definition: logstream.cc:228
std::ostringstream & get_stream()
Definition: logstream.cc:244
unsigned int file_depth
Definition: logstream.h:341