VM2D  1.12
Vortex methods for 2D flows simulation
LogStream.h
Go to the documentation of this file.
1 /*--------------------------------*- VMlib -*----------------*---------------*\
2 | ## ## ## ## ## ## ## | | Version 1.12 |
3 | ## ## ### ### ## ## | VMlib: VM2D/VM3D Library | 2024/01/14 |
4 | ## ## ## # ## ## ## #### | Open Source Code *----------------*
5 | #### ## ## ## ## ## ## | https://www.github.com/vortexmethods/VM2D |
6 | ## ## ## #### ### #### | https://www.github.com/vortexmethods/VM3D |
7 | |
8 | Copyright (C) 2017-2024 Ilia Marchevsky |
9 *-----------------------------------------------------------------------------*
10 | File name: LogStream.h |
11 | Info: Source code of VMlib |
12 | |
13 | This file is part of VMlib. |
14 | VMLib is free software: you can redistribute it and/or modify it |
15 | under the terms of the GNU General Public License as published by |
16 | the Free Software Foundation, either version 3 of the License, or |
17 | (at your option) any later version. |
18 | |
19 | VMlib is distributed in the hope that it will be useful, but WITHOUT |
20 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
21 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
22 | for more details. |
23 | |
24 | You should have received a copy of the GNU General Public License |
25 | along with VMlib. If not, see <http://www.gnu.org/licenses/>. |
26 \*---------------------------------------------------------------------------*/
27 
28 
37 #ifndef LOGSTREAM_H
38 #define LOGSTREAM_H
39 
40 #include <ostream>
41 #include <string>
42 
43 namespace VMlib
44 {
45 
53  class LogStream
54  {
55  private:
57  std::ostream* pStr;
58 
60  std::string label;
61 
62  public:
63 
68  : pStr(nullptr), label("") {};
69 
70 
77  void assignStream(std::ostream* pStr_, const std::string& label_)
78  {
79  pStr = pStr_;
80  label = label_;
81  }
82 
83 
90  void inheritStream(LogStream& infoStream_, const std::string& label_)
91  {
92  assignStream(infoStream_.pStr, infoStream_.label + "->" + label_);
93  }
94 
96  ~LogStream() {};
97 
98 
100  void endl()
101  {
102  *pStr << std::endl;
103  }
104 
105 
118  std::ostream& operator() (char c)
119  {
120  if (pStr != nullptr)
121  {
122  switch (c)
123  {
124  case 'i':
125  *pStr << label << (label.length() > 0 ? " " : "") << "info: ";
126  break;
127 
128  case 'e':
129  *pStr << label << (label.length() > 0 ? " " : "") << "ERROR: ";
130  break;
131 
132  case 't':
133  *pStr << label << (label.length() > 0 ? " " : "") << "tele: ";
134  break;
135 
136  case '-':
137  *pStr << " ";
138  break;
139 
140  case '_':
141  *pStr << " ";
142  break;
143 
144  }
145  return *pStr;
146  }
147  else
148  {
149  pStr = new std::ostream(NULL);
150  return *pStr;
151  }
152  }
153  };
154 
155 }//namespace VMlib;
156 
157 #endif
Класс, определяющий работу с потоком логов
Definition: LogStream.h:53
void assignStream(std::ostream *pStr_, const std::string &label_)
Связывание потока логов с потоком вывода
Definition: LogStream.h:77
std::ostream & operator()(char c)
Оператор вывода в поток логов
Definition: LogStream.h:118
~LogStream()
Деструктор
Definition: LogStream.h:96
std::string label
Метка потока
Definition: LogStream.h:60
void inheritStream(LogStream &infoStream_, const std::string &label_)
Связывание потока логов с потоком вывода от другого потока логов
Definition: LogStream.h:90
void endl()
Вывод в поток логов пустой строки
Definition: LogStream.h:100
std::ostream * pStr
Указатель на поток вывода
Definition: LogStream.h:57
LogStream()
Конструктор
Definition: LogStream.h:67