Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I might be missing something but your design doesn't make much sense to me. </p> <p>As I see it, extending a <code>streambuf</code> is done by overriding the protected virtual interface, if you'd want to use a decorator pattern your decorator base class would do just that.</p> <pre><code>template&lt;typename char_type, class traits_type&gt; class forwarding_basic_streambuf : boost::noncopyable, public std::basic_streambuf&lt;char_type, traits_type&gt; { public: typedef std::basic_streambuf&lt;char_type, traits_type&gt; forwarded_type; forwarding_basic_streambuf(forwarded_type&amp; fwd_buf) : m_fwd(&amp;fwd_buf) { } virtual ~forwarding_basic_streambuf() { } protected: virtual streamsize xsputn ( const char * s, streamsize n ) { m_fwd-&gt;xsputn(s,n); } virtual int overflow ( int c) { m_fwd-&gt;overflow(c); } // etc. }; </code></pre> <p>You real implementation would then add any needed 'decorations' e.g.</p> <pre><code>template&lt;typename char_type, class traits_type&gt; class add_timestamp_decorator : public forwarding_basic_streambuf&lt;char_type, traits_type&gt; { public: typedef std::forwarding_basic_streambuf&lt;char_type, traits_type&gt; base_type; add_timestamp_decorator(base_type::forwarded_type&amp; fwd_buf) : base_type(&amp;fwd_buf) { } virtual ~add_timestamp_decorator() { } protected: virtual streamsize xsputn ( const char * s, streamsize n ) { // detect and remember when a newline is written // before the next char is written output the timestamp base_type::xsputn(s, n); } // etc. }; </code></pre> <p>And then use it on an outputstream (pseudo code, omitted template definitions for clarity)</p> <pre><code>ostream outputstream; // .... add_timestamp_decorator decorator = new add_timestamp_decorator(outputstream.rdbuf()); outputstream.rdbuf(decorator); outputstream &lt;&lt; "some lines\ntimestamps will be inserted\n\n"; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload