日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Boost Asio总结(9)数据缓冲区class mutable_buffer和const_buffer

發布時間:2025/3/21 编程问答 266 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Boost Asio总结(9)数据缓冲区class mutable_buffer和const_buffer 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 保存了一個void*的內存地址和數據長度。

    /// Holds a buffer that can be modified. class mutable_buffer { public:/// Construct an empty buffer.mutable_buffer() BOOST_ASIO_NOEXCEPT: data_(0),size_(0){}/// Construct a buffer to represent a given memory range.mutable_buffer(void* data, std::size_t size) BOOST_ASIO_NOEXCEPT: data_(data),size_(size){}#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)mutable_buffer(void* data, std::size_t size,boost::asio::detail::function<void()> debug_check): data_(data),size_(size),debug_check_(debug_check){}const boost::asio::detail::function<void()>& get_debug_check() const{return debug_check_;} #endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING/// Get a pointer to the beginning of the memory range.void* data() const BOOST_ASIO_NOEXCEPT{ #if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)if (size_ && debug_check_)debug_check_(); #endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGINGreturn data_;}/// Get the size of the memory range.std::size_t size() const BOOST_ASIO_NOEXCEPT{return size_;}/// Move the start of the buffer by the specified number of bytes.mutable_buffer& operator+=(std::size_t n) BOOST_ASIO_NOEXCEPT{std::size_t offset = n < size_ ? n : size_;data_ = static_cast<char*>(data_) + offset;size_ -= offset;return *this;}private:void* data_;std::size_t size_;#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)boost::asio::detail::function<void()> debug_check_; #endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING };/// Holds a buffer that cannot be modified.class const_buffer { public:/// Construct an empty buffer.const_buffer() BOOST_ASIO_NOEXCEPT: data_(0),size_(0){}/// Construct a buffer to represent a given memory range.const_buffer(const void* data, std::size_t size) BOOST_ASIO_NOEXCEPT: data_(data),size_(size){}/// Construct a non-modifiable buffer from a modifiable one.const_buffer(const mutable_buffer& b) BOOST_ASIO_NOEXCEPT: data_(b.data()),size_(b.size()) #if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING), debug_check_(b.get_debug_check()) #endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING{}#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)const_buffer(const void* data, std::size_t size,boost::asio::detail::function<void()> debug_check): data_(data),size_(size),debug_check_(debug_check){}const boost::asio::detail::function<void()>& get_debug_check() const{return debug_check_;} #endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING/// Get a pointer to the beginning of the memory range.const void* data() const BOOST_ASIO_NOEXCEPT{ #if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)if (size_ && debug_check_)debug_check_(); #endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGINGreturn data_;}/// Get the size of the memory range.std::size_t size() const BOOST_ASIO_NOEXCEPT{return size_;}/// Move the start of the buffer by the specified number of bytes.const_buffer& operator+=(std::size_t n) BOOST_ASIO_NOEXCEPT{std::size_t offset = n < size_ ? n : size_;data_ = static_cast<const char*>(data_) + offset;size_ -= offset;return *this;}private:const void* data_;std::size_t size_;#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)boost::asio::detail::function<void()> debug_check_; #endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING };class mutable_buffers_1: public mutable_buffer { public:/// The type for each element in the list of buffers.typedef mutable_buffer value_type;/// A random-access iterator type that may be used to read elements.typedef const mutable_buffer* const_iterator;/// Get a random-access iterator to the first element.const_iterator begin() const BOOST_ASIO_NOEXCEPT{return this;}/// Get a random-access iterator for one past the last element.const_iterator end() const BOOST_ASIO_NOEXCEPT{return begin() + 1;} };class const_buffers_1: public const_buffer { public:/// The type for each element in the list of buffers.typedef const_buffer value_type;/// A random-access iterator type that may be used to read elements.typedef const const_buffer* const_iterator;/// Construct to represent a given memory range.const_buffers_1(const void* data, std::size_t size) BOOST_ASIO_NOEXCEPT: const_buffer(data, size){}#if defined(BOOST_ASIO_ENABLE_BUFFER_DEBUGGING)const_buffers_1(const void* data, std::size_t size,boost::asio::detail::function<void()> debug_check): const_buffer(data, size, debug_check){} #endif // BOOST_ASIO_ENABLE_BUFFER_DEBUGGING/// Construct to represent a single non-modifiable buffer.explicit const_buffers_1(const const_buffer& b) BOOST_ASIO_NOEXCEPT: const_buffer(b){}/// Get a random-access iterator to the first element.const_iterator begin() const BOOST_ASIO_NOEXCEPT{return this;}/// Get a random-access iterator for one past the last element.const_iterator end() const BOOST_ASIO_NOEXCEPT{return begin() + 1;} };

    總結

    以上是生活随笔為你收集整理的Boost Asio总结(9)数据缓冲区class mutable_buffer和const_buffer的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。