Reference documentation for deal.II version 9.1.1
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
logstream.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2019 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/subscriptor.h>
24 #include <deal.II/base/thread_local_storage.h>
25 
26 #include <cmath>
27 #include <map>
28 #include <memory>
29 #include <sstream>
30 #include <stack>
31 #include <string>
32 
33 
34 DEAL_II_NAMESPACE_OPEN
35 
83 class LogStream : public Subscriptor
84 {
85 public:
103  class Prefix
104  {
105  public:
110  Prefix(const std::string &text);
111 
116  Prefix(const std::string &text, LogStream &stream);
117 
121  ~Prefix();
122 
123  private:
129  };
130 
131 
136  LogStream();
137 
138 
142  ~LogStream() override;
143 
144 
155  void
156  attach(std::ostream & o,
157  const bool print_job_id = true,
158  const std::ios_base::fmtflags flags = std::ios::showpoint |
159  std::ios::left);
160 
161 
166  void
167  detach();
168 
169 
173  std::ostream &
174  get_console();
175 
176 
180  std::ostream &
181  get_file_stream();
182 
183 
188  bool
189  has_file() const;
190 
191 
195  const std::string &
196  get_prefix() const;
197 
198 
211  void
212  push(const std::string &text);
213 
214 
218  void
219  pop();
220 
221 
232  unsigned int
233  depth_console(const unsigned int n);
234 
235 
243  unsigned int
244  depth_file(const unsigned int n);
245 
246 
250  bool
251  log_thread_id(const bool flag);
252 
253 
259  std::streamsize
260  precision(const std::streamsize prec);
261 
262 
268  std::streamsize
269  width(const std::streamsize wide);
270 
271 
277  std::ios::fmtflags
278  flags(const std::ios::fmtflags f);
279 
280 
295  LogStream &
296  operator<<(std::ostream &(*p)(std::ostream &));
297 
298 
304  std::size_t
305  memory_consumption() const;
306 
307 private:
315  std::stack<std::string> &
316  get_prefixes() const;
317 
323 
329  std::ostream *std_out;
330 
337  std::ostream *file;
338 
345  unsigned int std_depth;
346 
350  unsigned int file_depth;
351 
356 
361 
365  void
366  print_line_head();
367 
372  std::ostringstream &
373  get_stream();
374 
380 
381  template <typename T>
382  friend LogStream &
383  operator<<(LogStream &log, const T &t);
384 };
385 
386 
387 /* ----------------------------- Inline functions and templates ----------------
388  */
389 
390 
398 template <typename T>
399 inline LogStream &
400 operator<<(LogStream &log, const T &t)
401 {
402  // print to the internal stringstream
403  log.get_stream() << t;
404  return log;
405 }
406 
407 
408 
414 extern LogStream deallog;
415 
416 
417 
418 DEAL_II_NAMESPACE_CLOSE
419 
420 #endif
void pop()
Definition: logstream.cc:316
std::streamsize precision(const std::streamsize prec)
Definition: logstream.cc:333
VectorizedArray< Number > log(const ::VectorizedArray< Number > &x)
A class that provides a separate storage location on each thread that accesses the object...
std::ostream * std_out
Definition: logstream.h:329
Threads::ThreadLocalStorage< std::stack< std::string > > prefixes
Definition: logstream.h:322
const std::string & get_prefix() const
Definition: logstream.cc:289
void attach(std::ostream &o, const bool print_job_id=true, const std::ios_base::fmtflags flags=std::ios::showpoint|std::ios::left)
Definition: logstream.cc:218
bool print_thread_id
Definition: logstream.h:355
~LogStream() override
Definition: logstream.cc:88
unsigned int depth_file(const unsigned int n)
Definition: logstream.cc:360
unsigned int std_depth
Definition: logstream.h:345
std::streamsize width(const std::streamsize wide)
Definition: logstream.cc:341
bool log_thread_id(const bool flag)
Definition: logstream.cc:371
std::ostream & get_file_stream()
Definition: logstream.cc:270
std::ios::fmtflags flags(const std::ios::fmtflags f)
Definition: logstream.cc:325
bool has_file() const
Definition: logstream.cc:281
std::stack< std::string > & get_prefixes() const
Definition: logstream.cc:382
unsigned int depth_console(const unsigned int n)
Definition: logstream.cc:349
void print_line_head()
Definition: logstream.cc:416
std::ostream * file
Definition: logstream.h:337
SmartPointer< LogStream, LogStream::Prefix > stream
Definition: logstream.h:128
Prefix(const std::string &text)
Definition: logstream.cc:41
OutputOperator< VectorType > & operator<<(OutputOperator< VectorType > &out, unsigned int step)
Definition: operator.h:170
std::ostream & get_console()
Definition: logstream.cc:239
bool at_newline
Definition: logstream.h:360
Threads::ThreadLocalStorage< std::shared_ptr< std::ostringstream > > outstreams
Definition: logstream.h:379
void push(const std::string &text)
Definition: logstream.cc:302
LogStream & operator<<(std::ostream &(*p)(std::ostream &))
Definition: logstream.cc:125
void detach()
Definition: logstream.cc:231
std::ostringstream & get_stream()
Definition: logstream.cc:247
unsigned int file_depth
Definition: logstream.h:350
std::size_t memory_consumption() const