g2o
stream_redirect.h
Go to the documentation of this file.
1 // g2o - General Graph Optimization
2 // Copyright (C) 2011 R. Kuemmerle, G. Grisetti, W. Burgard
3 //
4 // g2o is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as published
6 // by the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // g2o is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Lesser General Public License for more details.
13 //
14 // You should have received a copy of the GNU Lesser General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef G2O_STREAM_REDIRECT_H
18 #define G2O_STREAM_REDIRECT_H
19 
20 #include <iostream>
21 #include <streambuf>
22 #include <string>
23 #include <QMutex>
24 
25 #include "g2o_viewer_api.h"
26 
27 class QPlainTextEdit;
28 
32 class G2O_VIEWER_API StreamRedirect : public std::basic_streambuf<char>
33 {
34  public:
35  typedef std::char_traits<char>::int_type int_type;
36 
37  public:
38  StreamRedirect(std::ostream &stream, QPlainTextEdit* te);
39  ~StreamRedirect();
40 
41  protected:
42  virtual std::char_traits<char>::int_type overflow(int_type v);
43  virtual std::streamsize xsputn(const char *p, std::streamsize n);
44 
45  private:
46  std::ostream& _stream;
47  std::streambuf* _old_buf;
48  std::string _buffer;
49  QPlainTextEdit* _te;
50  QMutex _mutex;
51 };
52 
53 #endif
redirect a stream to a QPlainTextEdit
#define G2O_VIEWER_API
std::string _buffer
std::streambuf * _old_buf
QPlainTextEdit * _te
std::ostream & _stream
std::char_traits< char >::int_type int_type