CMR  1.3.0
logger.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <sstream>
4 #include <iostream>
5 
6 #include "common.hpp"
7 
8 namespace tu
9 {
10 
18  class logger
19  {
20  public:
21 
29 
34  virtual ~logger();
35 
40  inline log_level level() const
41  {
42  return _level;
43  }
44 
49  inline bool is_quiet() const
50  {
51  return _level == LOG_QUIET;
52  }
53 
58  inline bool is_verbose() const
59  {
60  return _level == LOG_VERBOSE;
61  }
62 
67  inline bool is_progressive() const
68  {
69  return _level == LOG_PROGRESSIVE;
70  }
71 
78  inline void indent(size_t amount = 1)
79  {
80  _indent += amount;
81  }
82 
89  inline void unindent(size_t amount = 1)
90  {
91  _indent -= amount;
92  }
93 
98  inline void clear()
99  {
100  delete _line;
101  _line = new std::stringstream();
102  }
103 
108  inline size_t size() const
109  {
110  return line().str().size();
111  }
112 
119  inline void erase(size_t position)
120  {
121  std::string data = line().str();
122  data.erase(position);
123  clear();
124  line() << data;
125  }
126 
131  inline std::stringstream& line()
132  {
133  return *_line;
134  }
135 
140  inline const std::stringstream& line() const
141  {
142  return *_line;
143  }
144 
146 
147  friend std::ostream& operator<<(std::ostream&, logger&);
148 
149  private:
150  size_t _indent;
151  log_level _level;
152  std::stringstream* _line;
153 
154  };
155 
164  std::ostream& operator<<(std::ostream&, logger&);
165 
166 } /* namespace tu */
Definition: logger.hpp:19
void clear()
Definition: logger.hpp:98
void indent(size_t amount=1)
Definition: logger.hpp:78
bool is_progressive() const
Definition: logger.hpp:67
std::stringstream & line()
Definition: logger.hpp:131
const std::stringstream & line() const
Definition: logger.hpp:140
void unindent(size_t amount=1)
Definition: logger.hpp:89
bool is_verbose() const
Definition: logger.hpp:58
bool is_quiet() const
Definition: logger.hpp:49
friend std::ostream & operator<<(std::ostream &, logger &)
Stream operator.
Definition: logger.cpp:42
logger(log_level level)
Definition: logger.cpp:19
size_t size() const
Definition: logger.hpp:108
void erase(size_t position)
Definition: logger.hpp:119
log_level level() const
Definition: logger.hpp:40
virtual ~logger()
Definition: logger.cpp:29
Definition: algorithm.hpp:14
std::ostream & operator<<(std::ostream &stream, const binary_linear_space &space)
Definition: binary_linear_space.hpp:205
log_level
Definition: common.hpp:36
@ LOG_VERBOSE
Definition: common.hpp:37
@ LOG_PROGRESSIVE
Definition: common.hpp:37
@ LOG_QUIET
Definition: common.hpp:37