Skip to content

Commit

Permalink
Add documentation for concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
ashtum committed Apr 15, 2024
1 parent d5a6330 commit a996ce5
Show file tree
Hide file tree
Showing 5 changed files with 259 additions and 1 deletion.
1 change: 1 addition & 0 deletions doc/modules/ROOT/nav.adoc
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
* Concepts
** xref:concepts/ConstBufferSequence.adoc[]
** xref:concepts/MutableBufferSequence.adoc[]
** xref:concepts/DynamicBuffer.adoc[]
* xref:reference:boost/buffers.adoc[Reference]
76 changes: 76 additions & 0 deletions doc/modules/ROOT/pages/concepts/ConstBufferSequence.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,79 @@


= ConstBufferSequence

A __ConstBufferSequence__ represents a collection of `const_buffer` s or `mutable_buffer` s.


== Related Identifiers

`is_const_buffer_sequence`.


== Requirements

* `T` denotes a type meeting the requirements of __ConstBufferSequence__.
* `t` denotes a (possibly const) value of type `T`.
* `u` denotes an identifier.

[cols="1a,1a,3a"]
|===
// Headers
|Expression|Type|Semantics, Pre/Post-conditions

// Row 1, Column 1
|`T::value_type`
// Row 1, Column 2
|`const_buffer` or `mutable_buffer`
// Row 1, Column 3
|This type represents a buffer in the sequence.

// Row 2, Column 1
|`T::const_iterator`
// Row 2, Column 2
|
// Row 2, Column 3
|This type represents an iterator type that satisfies the requirements of `std::bidirectional_iterator`, whose value type is `const_buffer` or `mutable_buffer`.

// Row 3, Column 1
|`t.begin()`
// Row 3, Column 2
|`T::const_iterator`
// Row 3, Column 3
|Returns an iterator to the first element of the sequence.

// Row 4, Column 1
|`t.end()`
// Row 4, Column 2
|`T::const_iterator`
// Row 4, Column 3
|Returns an iterator to the element following the last element of the sequence.

// Row 5, Column 1
|`T u(t)`;
// Row 5, Column 2
|
// Row 5, Column 3
|`T` satisfies the requirements of `std::copyconstructible` and `std::destructible`.

Post-conditions:
[source,cpp]
----
assert(std::ranges::size(t) == std::ranges::size(u));
for (auto [l, r] : std::views::zip(t, u))
{
assert(l.data() == r.data());
assert(l.size() == r.size());
}
----

|===


== Models

* `const_buffer_span`
* `mutable_buffer_span`
* `const_buffer_pair`
* `mutable_buffer_pair`
108 changes: 108 additions & 0 deletions doc/modules/ROOT/pages/concepts/DynamicBuffer.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
//
// Copyright (c) 2024 Mohammad Nejati
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/cppalliance/buffers
//


= DynamicBuffer

A __DynamicBuffer__ represents a memory storage that may be automatically resized as required, where the memory is divided into an input sequence followed by an output sequence. These memory regions are internal to the dynamic buffer, but direct access to the elements is provided to permit them to be efficiently used with I/O operations, such as the send or receive operations of a socket. Data written to the output sequence of a dynamic buffer object is appended to the input sequence of the same object.


== Related Identifiers

`is_dynamic_buffer`.


== Requirements

* `D` denotes a dynamic buffer class.
* `a` denotes a value of type `D`.
* `c` denotes a (possibly const) value of type `D`.
* `n` denotes a value of type `std::size_t`.
* `T` denotes a type meeting the requirements for `xref:./ConstBufferSequence.adoc[]`.
* `U` denotes a type meeting the requirements for `xref:./MutableBufferSequence.adoc[]`.

[cols="1a,1a,3a"]
|===
// Headers
|Expression|Type|Semantics, Pre/Post-conditions

// Row 1, Column 1
|`D::const_buffers_type`
// Row 1, Column 2
|`T`
// Row 1, Column 3
|This type represents the memory associated with the input sequence.

// Row 2, Column 1
|`D::mutable_buffers_type`
// Row 2, Column 2
|`U`
// Row 2, Column 3
|This type represents the memory associated with the output sequence.

// Row 3, Column 1
|`c.size()`
// Row 3, Column 2
|`std::size_t`
// Row 3, Column 3
|Returns the size, in bytes, of the input sequence.

// Row 4, Column 1
|`c.max_size()`
// Row 4, Column 2
|`std::size_t`
// Row 4, Column 3
|Returns the permitted maximum of the sum of the sizes of the input sequence and output sequence.

// Row 5, Column 1
|`c.capacity()`
// Row 5, Column 2
|`std::size_t`
// Row 5, Column 3
|Returns the maximum sum of the sizes of the input sequence and output sequence that the dynamic buffer can hold without requiring reallocation.

// Row 6, Column 1
|`c.data()`
// Row 6, Column 2
|`D::const_buffers_type`
// Row 6, Column 3
|Returns a constant buffer sequence `u` that represents the memory associated with the input sequence, and where `buffer_size(u) == size()`.

// Row 7, Column 1
|`a.prepare(n)`
// Row 7, Column 2
|`D::mutable_buffers_type`
// Row 7, Column 3
|Returns a mutable buffer sequence u representing the output sequence, and where `buffer_size(u) == n`. The dynamic buffer reallocates memory as required. All constant or mutable buffer sequences previously obtained using `data()` or `prepare()` are invalidated.

Throws: `length_error` if `size() + n` exceeds `max_size()`.

// Row 8, Column 1
|`a.commit(n)`
// Row 8, Column 2
|
// Row 8, Column 3
|Appends `n` bytes from the start of the output sequence to the end of the input sequence. The remainder of the output sequence is discarded. If `n` is greater than the size of the output sequence, the entire output sequence is appended to the input sequence. All constant or mutable buffer sequences previously obtained using `data()` or `prepare()` are invalidated.

// Row 9, Column 1
|`a.consume(n)`
// Row 9, Column 2
|
// Row 9, Column 3
|Removes `n` bytes from beginning of the input sequence. If `n` is greater than the size of the input sequence, the entire input sequence is removed. All constant or mutable buffer sequences previously obtained using `data()` or `prepare()` are invalidated.

|===


== Models

* `any_dynamic_buffer`
* `circular_buffer`
* `flat_buffer`
* `string_buffer`
73 changes: 73 additions & 0 deletions doc/modules/ROOT/pages/concepts/MutableBufferSequence.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,76 @@


= MutableBufferSequence

A __MutableBufferSequence__ represents a collection of `mutable_buffer` s.


== Related Identifiers

`is_mutable_buffer_sequence`.


== Requirements

* `T` denotes a type meeting the requirements of __MutableBufferSequence__.
* `t` denotes a (possibly const) value of type `T`.

[cols="1a,1a,3a"]
|===
// Headers
|Expression|Type|Semantics, Pre/Post-conditions

// Row 1, Column 1
|`T::value_type`
// Row 1, Column 2
|`mutable_buffer`
// Row 1, Column 3
|This type represents a mutable buffer in the sequence.

// Row 2, Column 1
|`T::const_iterator`
// Row 2, Column 2
|
// Row 2, Column 3
|This type represents an iterator type that satisfies the requirements of `std::bidirectional_iterator`, whose value type is `mutable_buffer`.

// Row 3, Column 1
|`t.begin()`
// Row 3, Column 2
|`T::const_iterator`
// Row 3, Column 3
|Returns an iterator to the first element of the sequence.

// Row 4, Column 1
|`t.end()`
// Row 4, Column 2
|`T::const_iterator`
// Row 4, Column 3
|Returns an iterator to the element following the last element of the sequence.

// Row 5, Column 1
|`T u(t)`;
// Row 5, Column 2
|
// Row 5, Column 3
|`T` satisfies the requirements of `std::copyconstructible` and `std::destructible`.

Post-conditions:
[source,cpp]
----
assert(std::ranges::size(t) == std::ranges::size(u));
for (auto [l, r] : std::views::zip(t, u))
{
assert(l.data() == r.data());
assert(l.size() == r.size());
}
----

|===


== Models

* `mutable_buffer_span`
* `mutable_buffer_pair`
2 changes: 1 addition & 1 deletion doc/modules/ROOT/pages/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ To use the library as header-only; that is, to eliminate the requirement
to link a program to a static or dynamic Boost.URL library, simply place
the following line in *exactly one* source file in your project.

[source, cpp]
[source,cpp]
----
#include <boost/buffers/src.hpp>
----
Expand Down

0 comments on commit a996ce5

Please sign in to comment.