itom  3.0.0
qDebugStream.h
1 /* ********************************************************************
2  itom software
3  URL: http://www.uni-stuttgart.de/ito
4  Copyright (C) 2016, Institut fuer Technische Optik (ITO),
5  Universitaet Stuttgart, Germany
6 
7  This file is part of itom.
8 
9  itom is free software; you can redistribute it and/or modify it
10  under the terms of the GNU Library General Public Licence as published by
11  the Free Software Foundation; either version 2 of the Licence, or (at
12  your option) any later version.
13 
14  itom is distributed in the hope that it will be useful, but
15  WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library
17  General Public Licence for more details.
18 
19  You should have received a copy of the GNU Library General Public License
20  along with itom. If not, see <http://www.gnu.org/licenses/>.
21 *********************************************************************** */
22 
23 //################
24 //# qdebugstream.h #
25 //################
26 
27 #ifndef Q_DEBUG_STREAM_H
28 #define Q_DEBUG_STREAM_H
29 
30 #include "../../common/typeDefs.h"
31 #include <iostream>
32 #include <qobject.h>
33 
34 namespace ito {
35 
38 class QDebugStream : public QObject, public std::basic_streambuf<char>
39 {
40  Q_OBJECT
41 
42 public:
43  enum MsgStreamType
44  {
45  msgStreamOut = 1,
46  msgStreamErr = 2,
47  msgStreamIn = 3
48  };
49 
50  QDebugStream(std::ostream &stream, ito::QDebugStream::MsgStreamType type);
51  ~QDebugStream();
52 
53 signals:
54  void flushStream(QString, ito::QDebugStream::MsgStreamType);
56 protected:
57 
59  virtual std::basic_streambuf<char>::int_type overflow(int_type v);
60 
61  virtual std::streamsize xsputn(const char *p, std::streamsize n);
62 
63 private:
64  std::ostream &m_stream;
65  std::streambuf *m_old_buf;
66  std::string m_string;
67  ito::QDebugStream::MsgStreamType msg_type;
68 };
69 
70 }; // namespace ito
71 
72 #endif
ito::QDebugStream::MsgStreamType msg_type
Definition: qDebugStream.h:67
QDebugStream(std::ostream &stream, ito::QDebugStream::MsgStreamType type)
constructor
Definition: qDebugStream.cpp:38
virtual std::basic_streambuf< char >::int_type overflow(int_type v)
this method overwrites a corresponding method in basic_streambuf class and is invoked, if buffer risks to overflow
Definition: qDebugStream.cpp:79
virtual std::streamsize xsputn(const char *p, std::streamsize n)
method invoked if new content has been added to stream
Definition: qDebugStream.cpp:65
std::streambuf * m_old_buf
Definition: qDebugStream.h:65
Definition: apiFunctionsGraph.cpp:39
std::string m_string
Definition: qDebugStream.h:66
~QDebugStream()
destructor
Definition: qDebugStream.cpp:52
void flushStream(QString, ito::QDebugStream::MsgStreamType)
std::ostream & m_stream
Definition: qDebugStream.h:64
Definition: qDebugStream.h:38