Пример #1
0
std::streamsize copy_impl( Source& src, Sink& snk, 
                           std::streamsize buffer_size,
                           mpl::false_, mpl::true_ )
{
    typedef typename char_type_of<Source>::type  char_type;
    typedef std::pair<char_type*, char_type*>    pair_type;
    detail::basic_buffer<char_type>  buf(buffer_size);
    pair_type                        p = snk.output_sequence();
    std::streamsize                  total = 0;
    std::ptrdiff_t                   capacity = p.second - p.first;
    while (true) {
        std::streamsize amt = 
            iostreams::read(
                src, 
                buf.data(),
                buffer_size < capacity - total ?
                    buffer_size :
                    static_cast<std::streamsize>(capacity - total)
            );
        if (amt == -1)
            break;
        std::copy(buf.data(), buf.data() + amt, p.first + total);
        total += amt;
    }
    return total;
}
Пример #2
0
std::streamsize copy_impl( Source& src, Sink& snk, 
                           std::streamsize buffer_size,
                           mpl::false_, mpl::true_ )
{   // Copy from an indirect Source to a direct Sink.
    using namespace std;
    typedef typename char_type_of<Source>::type  char_type;
    typedef pair<char_type*, char_type*>         pair_type;
    detail::basic_buffer<char_type>  buf(buffer_size);
    pair_type                        p = snk.output_sequence();
    streamsize                       total = 0;
    bool                             done  = false;
    while (!done) {
        streamsize amt;
        done = (amt = iostreams::read(src, buf.data(), buffer_size)) == -1;
        std::copy(buf.data(), buf.data() + amt, p.first + total);
        if (amt != -1)
            total += amt;
    }
    return total;
}