Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ Decorate basic_stream::underflow()
    primarykey
    data
    text
    <p>I want to extend the behavior of a basic_streambuf object by using the decorator pattern. That`s what I currently got:</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() { } // locales: // std::locale pubimbue(std::locale const&amp; loc); // =&gt; Calls: imbue(loc) | Returns: Previous value of getloc(); // std::locale getloc () const; // =&gt; Returns: If pubimbue() has ever been called, then the last value of loc supplied, otherwise the // current global locale, locale(), in effect at the time of construction. If called after // pubimbue() has been called but before pubimbue has returned (i.e., from within the call // of imbue()) then it returns the previous value. // buffer management and positioning: // forwarded_type* pubsetbuf (char_type* s, std::streamsize n); =&gt; Returns: setbuf(s, n) // pos_type pubseekoff(off_type off, std::ios_base::seekdir way, // std::ios_base::openmode which = std::ios_base::in | std::ios_base::out); // =&gt; Returns seekoff(off, way, which) // pos_type pubseekpos(pos_type sp, // std::ios_base::openmode which = std::ios_base::in | std::ios_base::out); // =&gt; Returns: seekpos(sp, which) // int pubsync (); =&gt; Returns: sync() // get and put areas: // get area: // std::streamsize sgetn (char_type* s, std::streamsize n); =&gt; Returns: xsgetn(s, n) // put area: // std::streamsize sputn(char_type const* s, std::streamsize n); =&gt; Returns: xsputn(s, n) protected: // virtual functions: // locales: virtual void imbue(std::locale const&amp; loc) { this-&gt;m_fwd-&gt;pubimbue(loc); } // buffer management and positioning: virtual forwarded_type* setbuf (char_type* s, std::streamsize n) { return this-&gt;m_fwd-&gt;pubsetbuf(s, n); } virtual pos_type seekoff(off_type off, std::ios_base::seekdir way, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) { return this-&gt;m_fwd-&gt;pubseekoff(off, way); } virtual pos_type seekpos(pos_type sp, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) { return this-&gt;m_fwd-&gt;pubseekpos(sp, which); } virtual int sync () { return this-&gt;m_fwd-&gt;pubsync(); } // get and put areas: // get area: virtual std::streamsize xsgetn(char_type* s, std::streamsize n) { return this-&gt;m_fwd-&gt;sgetn(s, n); } virtual int_type uflow() { if (traits_type::eq_int_type(this-&gt;underflow(), traits_type::eof())) return traits_type::eof(); return this-&gt;m_fwd-&gt;sgetc(); } // put area: virtual std::streamsize xsputn (char_type const* s, std::streamsize n) { return this-&gt;m_fwd-&gt;sputn(s, n); } virtual int_type overflow(int_type c = traits_type::eof()) { if (traits_type::eq_int_type(c, traits_type::eof())) return traits_type::not_eof(c); return this-&gt;m_fwd-&gt;sputc(traits_type::to_char_type(c)); } private: forwarded_type* m_fwd; }; </code></pre> <p>The basic goal (as a first step) would be to simply forward each functionality to the decorated object. Thus, it should be possible to use this decorater even with a pointer to it`s base class.</p> <p>That all works fine for writing methods, but I don`t know how to deal with the underflow() function, which is called from uflow() and sgetc().</p>
    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.
 

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