1 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
2 // (C) Copyright 2005-2007 Jonathan Turkanis
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
6 // See http://www.boost.org/libs/iostreams for documentation.
8 #ifndef BOOST_IOSTREAMS_DETAIL_COUNTED_ARRAY_HPP_INCLUDED
9 #define BOOST_IOSTREAMS_DETAIL_COUNTED_ARRAY_HPP_INCLUDED
11 #include <algorithm> // min.
12 #include <cstddef> // size_t
13 #include <string> // char_traits
14 #include <boost/iostreams/categories.hpp>
15 #include <boost/iostreams/detail/char_traits.hpp>
16 #include <boost/iostreams/detail/ios.hpp> // streamsize.
18 namespace boost { namespace iostreams { namespace detail {
21 class counted_array_source {
24 typedef source_tag category;
25 counted_array_source(const Ch* buf, std::streamsize size)
26 : buf_(buf), ptr_(0), end_(size)
28 std::streamsize read(Ch* s, std::streamsize n)
31 streamsize result = (std::min)(n, end_ - ptr_);
32 char_traits<char_type>::copy(
35 static_cast<size_t>(result)
40 std::streamsize count() const { return ptr_; }
43 std::streamsize ptr_, end_;
47 struct counted_array_sink {
50 typedef sink_tag category;
51 counted_array_sink(Ch* buf, std::streamsize size)
52 : buf_(buf), ptr_(0), end_(size)
54 std::streamsize write(const Ch* s, std::streamsize n)
57 std::streamsize result = (std::min)(n, end_ - ptr_);
58 char_traits<char_type>::copy(
61 static_cast<size_t>(result)
66 std::streamsize count() const { return ptr_; }
69 std::streamsize ptr_, end_;
72 } } } // End namespaces iostreams, boost.
74 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_COUNTED_ARRAY_HPP_INCLUDED