HCE project C++ developers source code library  1.1.1
HCE project developer library
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
LoggerStream.cpp
Go to the documentation of this file.
1 #include "LoggerStream.hpp"
2 
3 namespace HCE
4 {
5 //-----------------------------------------------------------------------------
7 : inherited(), logBuf(), pBuf(nullptr)
8 {
10  resetLoggable();
11 }
12 //-----------------------------------------------------------------------------
14 {
15 }
16 //-----------------------------------------------------------------------------
18 {
19  logBuf.str("");
20  pBuf = &logBuf;
21  this->rdbuf(pBuf);
22 }
23 //-----------------------------------------------------------------------------
24 void LoggerStream::setLogStream(std::ostream& os_)
25 {
26  pBuf=os_.rdbuf();
27  this->rdbuf(pBuf);
28 }
29 //-----------------------------------------------------------------------------
30 std::string LoggerStream::logMsg(bool isReset)
31 {
32  std::string result = logBuf.str();
33  if (isReset)
34  logBuf.str("");
35  return result;
36 }
37 //-----------------------------------------------------------------------------
39 {
40  loggable = loggable_;
41 }
42 //-----------------------------------------------------------------------------
44 {
45  loggable = [](const std::string& data) {return data;};
46 }
47 //-----------------------------------------------------------------------------
48 std::ostream& LoggerStream::put(const std::string& data)
49 {
50  *this << loggable(data);
51  return *this;
52 }
53 //-----------------------------------------------------------------------------
55 {
56  std::stringstream str;
57  str << rdbuf();
58  logBuf.str("");
59  std::endl(put(str.str()));
60  return *this;
61 }
62 //-----------------------------------------------------------------------------
63 //-----------------------------------------------------------------------------
64 std::ostream& endl(std::ostream& os)
65 {
66  if (typeid(os)==typeid(LoggerStream))
67  {
68  LoggerStream& ls = reinterpret_cast<LoggerStream&>(os);
69  ls.endl();
70  }
71  else
72  std::endl(os);
73  return os;
74 }
75 //-----------------------------------------------------------------------------
76 LoggerStream& operator<<(LoggerStream& os, const std::string& rhs)
77 {
78  os.log() << rhs;
79  return os;
80 }
81 //-----------------------------------------------------------------------------
82 LoggerStream& operator<<(LoggerStream& os, const char* rhs)
83 {
84  os.log() << rhs;
85  return os;
86 }
87 //-----------------------------------------------------------------------------
88 //-----------------------------------------------------------------------------
89 } // end namespace HCE