26 #ifndef ConsoleStream_H
27 #define ConsoleStream_H
75 init(stream, textEdit);
80 previousBuffer =
nullptr;
81 logTextEdit =
nullptr;
88 if (!myString.empty()) {
89 logTextEdit->append(myString.c_str());
99 previousBuffer = stream->rdbuf();
105 logTextEdit = text_edit;
109 void init(std::ostream* stream, QTextEdit* textEdit) {
116 if (previousBuffer !=
nullptr && myStream !=
nullptr) {
117 myStream->rdbuf(previousBuffer);
124 logTextEdit->append(myString.c_str());
125 myString.erase(myString.begin(), myString.end());
135 std::streamsize
xsputn(
const char* p, std::streamsize n) {
136 myString.append(p, p + n);
138 std::string::size_type pos = 0;
139 while (pos != std::string::npos) {
140 pos = myString.find(
'\n');
141 if (pos != std::string::npos) {
142 std::string tmp(myString.begin(), myString.begin() + pos);
143 logTextEdit->append(tmp.c_str());
144 myString.erase(myString.begin(), myString.begin() + pos + 1);
152 std::ostream* myStream;
153 std::streambuf* previousBuffer;
154 std::string myString;
155 QTextEdit* logTextEdit;
Provides a console windows, within the CamiTK application.
Definition: ConsoleStream.h:71
ConsoleStream(std::ostream *stream, QTextEdit *textEdit)
constructor to use when you are sure about both paramaters
Definition: ConsoleStream.h:74
~ConsoleStream()
destructor: use free() to restore previous stream output buffer
Definition: ConsoleStream.h:86
std::streamsize xsputn(const char *p, std::streamsize n)
rewriting of the inherited method xsputn
Definition: ConsoleStream.h:135
void free()
reset the state as it was before (stream use the old buffer again)
Definition: ConsoleStream.h:115
void setTextEdit(QTextEdit *text_edit)
set the log QTextEdit
Definition: ConsoleStream.h:104
void init(std::ostream *stream, QTextEdit *textEdit)
initialize ConsoleStream using both input stream and output text edit
Definition: ConsoleStream.h:109
void setStream(std::ostream *stream)
set the value for the buffer to be replaced by the ConsoleStream
Definition: ConsoleStream.h:96
int_type overflow(int_type v)
rewriting of the inherited method overflow
Definition: ConsoleStream.h:122
ConsoleStream()
default constructor, init(..) have to be called later, before first use
Definition: ConsoleStream.h:79
Definition: Action.cpp:36