00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include <Console.hpp>
00021
00022 #include <ErrorHandler.hpp>
00023
00024 #ifdef HAVE_GUI_LIBS
00025 #include <QtGui/QTextEdit>
00026 #include <iostream>
00027
00028 void Console::
00029 setConsole(QTextEdit* console)
00030 {
00031 __console = console;
00032 }
00033
00034 void Console::
00035 _writeError(std::string output)
00036 {
00037 size_t cr_position = output.find('\n');
00038 while (cr_position < output.size()) {
00039 std::cout << "[errput] "<< __error_buffer->str()
00040 << output.substr(0,cr_position+1);
00041 output = output.substr(cr_position+1);
00042 cr_position = output.find('\n');
00043 delete __error_buffer;
00044 __error_buffer = new std::stringstream();
00045 }
00046 (*__error_buffer) << output;
00047
00048 }
00049
00050 void Console::
00051 _writeStd(std::string output)
00052 {
00053 size_t cr_position = output.find('\n');
00054 while (cr_position < output.size()) {
00055 (*__std_buffer) << output.substr(0,cr_position);
00056 output = output.substr(cr_position+1);
00057 cr_position = output.find('\n');
00058
00059 QString line(__std_buffer->str().c_str());
00060 __console->append(line);
00061 __console->update();
00062
00063 delete __std_buffer;
00064 __std_buffer = new std::stringstream();
00065 }
00066 (*__std_buffer) << output;
00067 }
00068
00069 #else
00070
00071 void Console::
00072 _writeError(std::string output)
00073 {
00074 throw ErrorHandler(__FILE__,__LINE__,
00075 "cannot use console output",
00076 ErrorHandler::unexpected);
00077 }
00078
00079 void Console::
00080 _writeStd(std::string output)
00081 {
00082 throw ErrorHandler(__FILE__,__LINE__,
00083 "cannot use console output",
00084 ErrorHandler::unexpected);
00085 }
00086
00087 #endif // HAVE_GUI_LIBS
00088
00089 Console::Console()
00090 {
00091 __std_buffer = new std::stringstream();
00092 __error_buffer = new std::stringstream();
00093 }
00094
00095 Console::~Console()
00096 {
00097 delete __std_buffer;
00098 delete __error_buffer;
00099 }