Reference documentation for deal.II version 9.0.0
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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii_logstream_h
17 #define dealii_logstream_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/base/exceptions.h>
21 #include <deal.II/base/smartpointer.h>
22 #include <deal.II/base/thread_local_storage.h>
23 
24 #include <string>
25 #include <stack>
26 #include <map>
27 #include <cmath>
28 #include <sstream>
29 #include <memory>
30 
31 
32 DEAL_II_NAMESPACE_OPEN
33 
81 class LogStream : public Subscriptor
82 {
83 public:
101  class Prefix
102  {
103  public:
108  Prefix(const std::string &text);
109 
114  Prefix(const std::string &text,
115  LogStream &stream);
116 
120  ~Prefix ();
121 
122  private:
128  };
129 
130 
135  LogStream ();
136 
137 
141  ~LogStream();
142 
143 
149  void attach (std::ostream &o,
150  const bool print_job_id = true);
151 
152 
157  void detach ();
158 
159 
163  std::ostream &get_console ();
164 
165 
169  std::ostream &get_file_stream ();
170 
171 
176  bool has_file () const;
177 
178 
182  const std::string &get_prefix () const;
183 
184 
197  void push (const std::string &text);
198 
199 
203  void pop ();
204 
205 
216  unsigned int depth_console (const unsigned int n);
217 
218 
226  unsigned int depth_file (const unsigned int n);
227 
228 
232  bool log_thread_id (const bool flag);
233 
234 
240  std::streamsize precision (const std::streamsize prec);
241 
242 
248  std::streamsize width (const std::streamsize wide);
249 
250 
256  std::ios::fmtflags flags(const std::ios::fmtflags f);
257 
258 
273  LogStream &operator<< (std::ostream& (*p) (std::ostream &));
274 
275 
281  std::size_t memory_consumption () const;
282 
283 private:
284 
285 
293  std::stack<std::string> &get_prefixes() const;
294 
300 
306  std::ostream *std_out;
307 
314  std::ostream *file;
315 
322  unsigned int std_depth;
323 
327  unsigned int file_depth;
328 
333 
338 
342  void print_line_head ();
343 
348  std::ostringstream &get_stream();
349 
355 
356  template <typename T> friend LogStream &operator << (LogStream &log, const T &t);
357 };
358 
359 
360 /* ----------------------------- Inline functions and templates ---------------- */
361 
362 
370 template <typename T>
371 inline
373 {
374  // print to the internal stringstream
375  log.get_stream() << t;
376  return log;
377 }
378 
379 
380 
381 
387 extern LogStream deallog;
388 
389 
390 
391 DEAL_II_NAMESPACE_CLOSE
392 
393 #endif
void pop()
Definition: logstream.cc:312
std::streamsize precision(const std::streamsize prec)
Definition: logstream.cc:329
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:306
Threads::ThreadLocalStorage< std::stack< std::string > > prefixes
Definition: logstream.h:299
const std::string & get_prefix() const
Definition: logstream.cc:286
bool print_thread_id
Definition: logstream.h:332
unsigned int depth_file(const unsigned int n)
Definition: logstream.cc:356
unsigned int std_depth
Definition: logstream.h:322
std::streamsize width(const std::streamsize wide)
Definition: logstream.cc:337
bool log_thread_id(const bool flag)
Definition: logstream.cc:367
std::ostream & get_file_stream()
Definition: logstream.cc:267
std::ios::fmtflags flags(const std::ios::fmtflags f)
Definition: logstream.cc:321
bool has_file() const
Definition: logstream.cc:278
~LogStream()
Definition: logstream.cc:91
std::stack< std::string > & get_prefixes() const
Definition: logstream.cc:378
unsigned int depth_console(const unsigned int n)
Definition: logstream.cc:345
void print_line_head()
Definition: logstream.cc:412
std::ostream * file
Definition: logstream.h:314
void attach(std::ostream &o, const bool print_job_id=true)
Definition: logstream.cc:217
Prefix(const std::string &text)
Definition: logstream.cc:41
OutputOperator< VectorType > & operator<<(OutputOperator< VectorType > &out, unsigned int step)
Definition: operator.h:163
std::ostream & get_console()
Definition: logstream.cc:236
bool at_newline
Definition: logstream.h:337
Threads::ThreadLocalStorage< std::shared_ptr< std::ostringstream > > outstreams
Definition: logstream.h:354
void push(const std::string &text)
Definition: logstream.cc:299
SmartPointer< LogStream, LogStream::Prefix > stream
Definition: logstream.h:127
LogStream & operator<<(std::ostream &(*p)(std::ostream &))
Definition: logstream.cc:128
void detach()
Definition: logstream.cc:228
std::ostringstream & get_stream()
Definition: logstream.cc:244
unsigned int file_depth
Definition: logstream.h:327
std::size_t memory_consumption() const