Boost logo

Boost :

From: George M. Garner Jr. (gmgarner_at_[hidden])
Date: 2005-08-17 19:50:13


Johnathan,

> What are you trying to do? <

I believe that we have already discussed this. But since you ask:

template<typename T, typename Tr, typename Alloc, typename Mode>
class normalized_indirect_streambuf
: public boost::iostreams::detail::
indirect_streambuf<T, Tr, Alloc, Mode>
{
public:
typedef boost::iostreams::detail::
indirect_streambuf<T, Tr, Alloc, Mode> base_type;
normalized_indirect_streambuf(void) : base_type()
{
}
protected:
std::streamsize _Xsgetn_s(char_type* _Ptr,
size_t _Ptr_size,
std::streamsize _Count);
int_type underflow()
{
buffer_type& buf = in();
if((buf.size() - pback_size_) == 0)
return traits_type::eof();
return base_type::underflow();
}
};
template<typename T, typename Tr, typename Alloc, typename Mode>
std::streamsize normalized_indirect_streambuf<T, Tr, Alloc, Mode>::
_Xsgetn_s(char_type* s, size_t _Ptr_size, std::streamsize n)
{
using namespace std;
buffer_type& buf = in();
if (!gptr() && buf.size() > 0) init_get_area();
streamsize total = 0;
do {
// Fill request from buffer.
if (streamsize avail =
std::min(n, static_cast<streamsize>(egptr() - gptr())))
{
traits_type::copy(s, gptr(), avail);
gbump((int) avail);
total += avail;
s += avail;
n -= avail;
}
else
{
// Read from source.
streamsize to_read = buf.size() - pback_size_;
if(to_read <= n)
{
//if(to_read == 0)
to_read = n;
if(streamsize amt = obj().read(s, to_read, next_))
{
s += amt;
n -= amt;
total += amt;
if(amt < to_read)
break; // probably EOF
}
else
{
// Something is screwed. Get out of dodge.
break;
}
}
else
{
if(traits_type::eq_int_type(traits_type::eof(), underflow()))
break;
}
}
} while(n > 0);
return total;
}

The implementation avoids excessive copying by bypassing, under carefully
defined circumstances, internal buffering and performing the read operation
in-place.

> Also, component_impl() is virtual, so you should be able to override it
> even
> though its private. <

I'm not sure how this helps; component_impl() returns a void*. What am I
supposed to do, cast it? :-(

Regards,

George.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk