File indexing completed on 2025-01-18 09:38:49
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_IOSTREAMS_DETAIL_COUNTED_ARRAY_HPP_INCLUDED
0009 #define BOOST_IOSTREAMS_DETAIL_COUNTED_ARRAY_HPP_INCLUDED
0010
0011 #include <algorithm> // min.
0012 #include <cstddef> // size_t
0013 #include <string> // char_traits
0014 #include <boost/iostreams/categories.hpp>
0015 #include <boost/iostreams/detail/char_traits.hpp>
0016 #include <boost/iostreams/detail/ios.hpp> // streamsize.
0017
0018 namespace boost { namespace iostreams { namespace detail {
0019
0020 template<typename Ch>
0021 class counted_array_source {
0022 public:
0023 typedef Ch char_type;
0024 typedef source_tag category;
0025 counted_array_source(const Ch* buf, std::streamsize size)
0026 : buf_(buf), ptr_(0), end_(size)
0027 { }
0028 std::streamsize read(Ch* s, std::streamsize n)
0029 {
0030 using namespace std;
0031 streamsize result = (std::min)(n, end_ - ptr_);
0032 char_traits<char_type>::copy(
0033 s,
0034 buf_ + ptr_,
0035 static_cast<size_t>(result)
0036 );
0037 ptr_ += result;
0038 return result;
0039 }
0040 std::streamsize count() const { return ptr_; }
0041 private:
0042 const Ch* buf_;
0043 std::streamsize ptr_, end_;
0044 };
0045
0046 template<typename Ch>
0047 struct counted_array_sink {
0048 public:
0049 typedef Ch char_type;
0050 typedef sink_tag category;
0051 counted_array_sink(Ch* buf, std::streamsize size)
0052 : buf_(buf), ptr_(0), end_(size)
0053 { }
0054 std::streamsize write(const Ch* s, std::streamsize n)
0055 {
0056 using namespace std;
0057 std::streamsize result = (std::min)(n, end_ - ptr_);
0058 char_traits<char_type>::copy(
0059 buf_ + ptr_,
0060 s,
0061 static_cast<size_t>(result)
0062 );
0063 ptr_ += result;
0064 return result;
0065 }
0066 std::streamsize count() const { return ptr_; }
0067 private:
0068 Ch* buf_;
0069 std::streamsize ptr_, end_;
0070 };
0071
0072 } } }
0073
0074 #endif