atomicrex  0.1
An advanced atomistic model building tool
Logger.h
1 //
3 // Copyright (C) 2017, Alexander Stukowski and Paul Erhart
4 //
5 // This file is part of atomicrex.
6 //
7 // Atomicrex is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // Atomicrex is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //
21 
22 #pragma once
23 
24 #include <sstream>
25 
26 namespace atomicrex {
27 
30  none,
31  minimum,
32  medium,
33  maximum,
34  debug
35 };
36 
37 class MsgLogger
38 {
39 public:
40 
42  MsgLogger(LoggerVerbosity verb) : _enabled(verb <= _globalLoggerVerbosity) {}
43 
45  ~MsgLogger() { std::cout << _buffer.str(); }
46 
47  template<typename T>
48  MsgLogger& operator<<(T const& t) {
49  if(_enabled)
50  _buffer << t;
51  return *this;
52  }
53 
54  MsgLogger& operator<<( std::ostream&(*f)(std::ostream&) ) {
55  if(_enabled)
56  _buffer << f;
57  return *this;
58  }
59 
60  bool isEnabled() const { return _enabled; }
61 
63  static void setVerbosity(LoggerVerbosity verb) {
64  _globalLoggerVerbosity = verb;
65  }
66 
67 private:
68 
69  bool _enabled;
70  std::ostringstream _buffer;
71 
72  // The current verbosity level.
73  static LoggerVerbosity _globalLoggerVerbosity;
74 };
75 
76 
78 inline std::ostream& separatorLine(std::ostream& stream) {
79  return stream << "-------------------------------------------------------" << std::endl;
80 }
81 
82 } // End of namespace
LoggerVerbosity
Levels of program output verbosity.
Definition: Logger.h:29
Definition: Logger.h:37
std::ostream & separatorLine(std::ostream &stream)
This stream manipulator function outputs a separator line to the output stream.
Definition: Logger.h:78
static void setVerbosity(LoggerVerbosity verb)
Changes the verbosity threshold level of the logger stream.
Definition: Logger.h:63
This file collects the definition of classes that define various simple crystal structures.
Definition: Atomicrex.h:67
~MsgLogger()
Destructor.
Definition: Logger.h:45
MsgLogger(LoggerVerbosity verb)
Constructor.
Definition: Logger.h:42