Virtual Testbed
Ship dynamics simulator for extreme conditions
LogStreamBuffer.hh
1 #ifndef VTESTBED_GUI_LOGSTREAMBUFFER_HH
2 #define VTESTBED_GUI_LOGSTREAMBUFFER_HH
3 
4 #include <streambuf>
5 
6 #include <vtestbed/gui/CircularLineBuffer.hh>
7 
8 namespace vtb {
9 
10  namespace gui {
11 
13 
14  private:
15  std::streambuf* sb;
16  CircularLineBuffer* ilb;
17  LogLineMarker _marker;
18 
19  public:
20 
21  inline
23  std::streambuf* sb,
24  CircularLineBuffer* ilb,
25  LogLineMarker marker
26  ): sb(sb), ilb(ilb), _marker(marker) {}
27 
28  protected:
29 
30  virtual int
31  overflow(int c) {
32  if (c == traits_type::eof()) {
33  return !traits_type::eof();
34  } else {
35  int const r = sb->sputc(c);
36  const char cc = traits_type::to_char_type(c);
37  ilb->put(&cc, _marker);
38  return r == traits_type::eof() ? traits_type::eof() : c;
39  }
40  }
41 
42  virtual std::streamsize
43  xsputn(const char* s, std::streamsize n){
44  sb->sputn(s, n);
45  ilb->put(s, _marker, n);
46  return n;
47  }
48 
49  };
50 
51  }
52 
53 }
54 
55 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9