#include "window.hpp" #include #include #include #include #include #include #include #include namespace { class window_output { public: typedef char char_type; typedef boost::iostreams::sink_tag category; window_output(window* _win) : win(_win) { } void close() { } std::streamsize write(const char* s, std::streamsize n) { size_t oldsize = stream.size(); stream.resize(oldsize + n); memcpy(&stream[oldsize], s, n); while(true) { size_t lf = stream.size(); for(size_t i = 0; i < stream.size(); i++) if(stream[i] == '\n') { lf = i; break; } if(lf == stream.size()) break; std::string foo(stream.begin(), stream.begin() + lf); win->message(foo); if(lf + 1 < stream.size()) memmove(&stream[0], &stream[lf + 1], stream.size() - lf - 1); stream.resize(stream.size() - lf - 1); } return n; } protected: std::vector stream; window* win; }; } std::ostream& window::out() throw(std::bad_alloc) { static std::ostream* cached = NULL; if(!cached) cached = new boost::iostreams::stream(this); return *cached; }