From eeceba51b83b2fee4b6f3e261e3e5901b65419e5 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Fri, 29 Sep 2017 23:05:24 -0700 Subject: [PATCH] ircd::buffer: Add some doc; fixes. --- include/ircd/buffer.h | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/include/ircd/buffer.h b/include/ircd/buffer.h index 18ab0f2e9..2b9554f6c 100644 --- a/include/ircd/buffer.h +++ b/include/ircd/buffer.h @@ -106,6 +106,8 @@ namespace ircd using buffer::mutable_buffers; } +/// Base for all buffer types +/// template struct ircd::buffer::buffer :std::tuple @@ -160,6 +162,9 @@ namespace ircd::buffer template struct mutable_buffer_base; } +/// Base for mutable buffers, or buffers which can be written to because they +/// are not const. +/// template struct ircd::buffer::mutable_buffer_base :buffer @@ -179,14 +184,19 @@ struct ircd::buffer::mutable_buffer_base } using buffer::buffer; + mutable_buffer_base(): buffer{} {} // lvalue string reference offered to write through to a std::string as // the buffer. not explicit; should be hard to bind by accident... mutable_buffer_base(std::string &buf) - :mutable_buffer_base{const_cast(buf.data()), buf.size()} + :mutable_buffer_base{const_cast(buf.data()), buf.size()} {} }; +/// A writable buffer of signed char data. Convention is for this buffer to +/// represent readable strings, which may or may not be null terminated. This +/// is just a convention; not a gurantee of the type. +/// struct ircd::buffer::mutable_buffer :mutable_buffer_base { @@ -196,13 +206,19 @@ struct ircd::buffer::mutable_buffer using mutable_buffer_base::mutable_buffer_base; }; +/// A writable buffer of unsigned signed char data. Convention is for this +/// buffer to represent unreadable binary data. It may also be constructed +/// from a mutable_buffer because a buffer of any data (this one) can also +/// be readable data. The inverse is not true, mutable_buffer cannot be +/// constructed from this class. +/// struct ircd::buffer::mutable_raw_buffer :mutable_buffer_base { // Conversion offered for the analogous asio buffer operator boost::asio::mutable_buffer() const; - using mutable_buffer_base::mutable_buffer_base; + using mutable_buffer_base::mutable_buffer_base; mutable_raw_buffer(const mutable_buffer &b) :mutable_buffer_base{reinterpret_cast(data(b)), size(b)} @@ -221,18 +237,19 @@ struct ircd::buffer::const_buffer_base using iterator = typename buffer::iterator; using value_type = typename buffer::value_type; - using buffer::buffer; + using buffer::buffer; + const_buffer_base(): buffer{} {} const_buffer_base(const mutable_buffer &b) - :buffer{data(b), size(b)} + :buffer{reinterpret_cast(data(b)), size(b)} {} const_buffer_base(const string_view &s) - :buffer{std::begin(s), std::end(s)} + :buffer{reinterpret_cast(s.data()), s.size()} {} explicit const_buffer_base(const std::string &s) - :buffer{s.data(), s.size()} + :buffer{reinterpret_cast(s.data()), s.size()} {} };