Clean up some header files
[lsnes.git] / window.cpp
blob9651be7d0d5b5beb1e4430b7e52e3940e984ce2f
1 #include "window.hpp"
2 #include <boost/iostreams/categories.hpp>
3 #include <boost/iostreams/copy.hpp>
4 #include <boost/iostreams/stream.hpp>
5 #include <boost/iostreams/stream_buffer.hpp>
6 #include <boost/iostreams/filter/symmetric.hpp>
7 #include <boost/iostreams/filter/zlib.hpp>
8 #include <boost/iostreams/filtering_stream.hpp>
9 #include <boost/iostreams/device/back_inserter.hpp>
11 namespace
13 class window_output
15 public:
16 typedef char char_type;
17 typedef boost::iostreams::sink_tag category;
18 window_output(window* _win)
19 : win(_win)
23 void close()
27 std::streamsize write(const char* s, std::streamsize n)
29 size_t oldsize = stream.size();
30 stream.resize(oldsize + n);
31 memcpy(&stream[oldsize], s, n);
32 while(true) {
33 size_t lf = stream.size();
34 for(size_t i = 0; i < stream.size(); i++)
35 if(stream[i] == '\n') {
36 lf = i;
37 break;
39 if(lf == stream.size())
40 break;
41 std::string foo(stream.begin(), stream.begin() + lf);
42 win->message(foo);
43 if(lf + 1 < stream.size())
44 memmove(&stream[0], &stream[lf + 1], stream.size() - lf - 1);
45 stream.resize(stream.size() - lf - 1);
47 return n;
49 protected:
50 std::vector<char> stream;
51 window* win;
55 std::ostream& window::out() throw(std::bad_alloc)
57 static std::ostream* cached = NULL;
58 if(!cached)
59 cached = new boost::iostreams::stream<window_output>(this);
60 return *cached;