diff --git a/docs/IO/io_port.md b/docs/IO/io_port.md index a5ba6dc2..fce94395 100644 --- a/docs/IO/io_port.md +++ b/docs/IO/io_port.md @@ -404,8 +404,8 @@ port.control ^= 0x0080; uint16_t status = port.status; // Copy data from a buffer to the Tx data port. -std::copy(txBuffer.begin(), txBuffer.end(), serial_port.txdata.iter()); +std::copy(txBuffer.begin(), txBuffer.end(), port.txdata.iter()); // Copy data from the Rx data port to a buffer. -std::copy_n(serial_port.rxdata, serial_port.status, std::back_inserter(rxBuffer)); +std::copy_n(port.rxdata.iter(), status, std::back_inserter(rxBuffer)); ``` diff --git a/docs/chrono/month/month_day.md b/docs/chrono/month/month_day.md index ccabdc33..bf7b0002 100644 --- a/docs/chrono/month/month_day.md +++ b/docs/chrono/month/month_day.md @@ -130,7 +130,7 @@ Less-than-equal operator. ```cpp ETL_CONSTEXPR14 -bool operator <(const etl::chrono::month_day& lhs, +bool operator >(const etl::chrono::month_day& lhs, const etl::chrono::month_day& rhs) ETL_NOEXCEPT ``` @@ -141,7 +141,7 @@ Greater-than operator. ```cpp ETL_CONSTEXPR14 -bool operator <=(const etl::chrono::month_day& lhs, +bool operator >=(const etl::chrono::month_day& lhs, const etl::chrono::month_day& rhs) ETL_NOEXCEPT ``` diff --git a/docs/chrono/time_point.md b/docs/chrono/time_point.md index 3a9ec057..dd0bd674 100644 --- a/docs/chrono/time_point.md +++ b/docs/chrono/time_point.md @@ -146,7 +146,7 @@ Rounds up a duration to the nearest higher precision. --- -```cp +```cpp template ETL_NODISCARD ETL_CONSTEXPR14 diff --git a/docs/chrono/weekday/weekday_indexed.md b/docs/chrono/weekday/weekday_indexed.md index 4062e3cc..9e6f22a4 100644 --- a/docs/chrono/weekday/weekday_indexed.md +++ b/docs/chrono/weekday/weekday_indexed.md @@ -46,10 +46,12 @@ Copy constructor. ## Tests +```cpp ETL_NODISCARD ETL_CONSTEXPR14 bool ok() const ETL_NOEXCEPT +``` **Return** `true` if the weekday_indexed is valid diff --git a/docs/codecs/base64.md b/docs/codecs/base64.md index e76f0040..1292cfff 100644 --- a/docs/codecs/base64.md +++ b/docs/codecs/base64.md @@ -5,309 +5,460 @@ title: "Base64" {{< callout type="info">}} Headers: `base64.h` Common definitions - `base64_encoder.h` Encoder class - `base64_decoder.h` Decoder class - From: `20.38.4` + `base64_encoder.h` Encoder classes + `base64_decoder.h` Decoder classes + From: `20.38.17` {{< /callout >}} Encodes and decodes data to and from Base64 format. -## Encode +The codecs are stream based. Data is fed in one element, or block of elements, at a time and the encoded or decoded result is written to the codec's internal output buffer. The result can be obtained in one of two ways: +- If the internal buffer is large enough to hold the entire result, it can be read directly from the codec via `begin()`/`end()` or `span()`. +- Otherwise a callback may be supplied that is called with a span of the output data each time the internal buffer becomes full, and once more with an empty span to signal that the final block has been processed. -**Input -> pointer/length : Output -> pointer/length** +A separate codec class is supplied for each supported Base64 variant. + +## Encoder + +The encoder classes are declared in `base64_encoder.h`. They all derive from `etl::ibase64_encoder`, which provides the interface described below. + +| Class | Variant | Padding | +| :--- | :--- | :--- | +| `etl::base64_rfc2152_encoder` | RFC-2152 | No | +| `etl::base64_rfc3501_encoder` | RFC-3501 | No | +| `etl::base64_rfc4648_encoder` | RFC-4648 | No | +| `etl::base64_rfc4648_padding_encoder` | RFC-4648 | Yes | +| `etl::base64_rfc4648_url_encoder` | RFC-4648-URL | No | +| `etl::base64_rfc4648_url_padding_encoder` | RFC-4648-URL | Yes | + +### Template parameters +`Buffer_Size` The size of the internal output buffer, in characters. +Defaults to `etl::base64::Min_Encode_Buffer_Size` (4). +Must be a non-zero multiple of `etl::base64::Min_Encode_Buffer_Size`. + +### Member types +```cpp +typedef etl::span span_type; +typedef etl::delegate callback_type; +``` + +### Constructors +```cpp +base64_rfcXXXX_encoder() +``` +**Description** +Constructs an encoder with no callback. The encoded result is read from the internal output buffer. + +--- + +```cpp +base64_rfcXXXX_encoder(callback_type callback) +``` +**Description** +Constructs an encoder with a callback. The callback is called with a span of the encoded data each time the internal buffer becomes full, and with an empty span once the final block has been flushed. + +### Encoding ```cpp template -ETL_CONSTEXPR14 -static -size_t encode(const T* input, size_t input_length, - char* output, size_t output_length) +bool encode(T value) ``` -**Description** -Transforms the input data described by input and input_length to Base64 format to be stored in output output_length. +**Description** +Encodes a single 8 bit value. Enabled if `etl::is_integral` is `true` and `etl::integral_limits::bits == 8`. -**Return** -The length of the encoded data. - -**Error** -If output_length is not large enough to hold the encoded data then an `etl::base64_overflow` is raised. +**Return** +`false` if the output buffer overflowed, otherwise `true`. --- -**Input -> pointer/length : Output -> string** +```cpp +template +bool encode(TInputIterator input_begin, size_t input_length) +``` +**Description** +Encodes `input_length` 8 bit values starting at `input_begin`. + +**Return** +`false` if the output buffer overflowed, otherwise `true`. + +--- + +```cpp +template +bool encode(TInputIterator input_begin, TInputIterator input_end) +``` +**Description** +Encodes the 8 bit values in the range `input_begin` to `input_end`. + +**Return** +`false` if the output buffer overflowed, otherwise `true`. + +--- + +```cpp +template +bool encode_final(TInputIterator input_begin, size_t input_length) +``` +**Description** +Encodes `input_length` 8 bit values starting at `input_begin`, then flushes the final block. Equivalent to `encode()` followed by `flush()`. + +**Return** +`false` if the output buffer overflowed, otherwise `true`. + +--- + +```cpp +template +bool encode_final(TInputIterator input_begin, TInputIterator input_end) +``` +**Description** +Encodes the 8 bit values in the range `input_begin` to `input_end`, then flushes the final block. Equivalent to `encode()` followed by `flush()`. + +**Return** +`false` if the output buffer overflowed, otherwise `true`. + +--- + +```cpp +bool flush() +``` +**Description** +Encodes any remaining buffered input, including any required padding, and marks the end of the data. If a callback has been set it is called with any remaining data and then with an empty span. +Must be called once all of the input has been passed to `encode()`. Not required when `encode_final()` is used. + +**Return** +`false` if the output buffer overflowed, otherwise `true`. + +--- + +```cpp +void restart() +``` +**Description** +Resets the encoder so that it can be reused to encode a new set of data. + +### Reading the result +These functions return a useful value only when no callback has been set. The internal buffer must be large enough to hold the entire encoded result. + +```cpp +const char* begin() const +const char* cbegin() const +``` +**Return** +A pointer to the beginning of the encoded data in the internal buffer. + +--- + +```cpp +const char* end() const +const char* cend() const +``` +**Return** +A pointer to the end of the encoded data in the internal buffer. + +--- + +```cpp +size_t size() const +``` +**Return** +The number of encoded characters currently held in the internal buffer. + +--- + +```cpp +size_t max_size() const +``` +**Return** +The maximum size of the internal output buffer (`Buffer_Size`). + +--- + +```cpp +span_type span() const +``` +**Return** +A span over the encoded data in the internal buffer. + +### Status +```cpp +bool overflow() const +``` +**Return** +`true` if the output buffer has overflowed. + +--- + +```cpp +bool error() const +``` +**Return** +`true` if an error has been detected. For the encoder this is equivalent to `overflow()`. + +### Static functions +```cpp +static size_t safe_output_buffer_size(size_t input_length) +``` +**Return** +The internal buffer size required to encode `input_length` bytes in a single pass. Use this as the `Buffer_Size` template argument when the whole result is to be read from the internal buffer. + +## Decoder + +The decoder classes are declared in `base64_decoder.h`. They all derive from `etl::ibase64_decoder`, which provides the interface described below. + +| Class | Variant | Padding | +| :--- | :--- | :--- | +| `etl::base64_rfc2152_decoder` | RFC-2152 | No | +| `etl::base64_rfc3501_decoder` | RFC-3501 | No | +| `etl::base64_rfc4648_decoder` | RFC-4648 | No | +| `etl::base64_rfc4648_padding_decoder` | RFC-4648 | Yes | +| `etl::base64_rfc4648_url_decoder` | RFC-4648-URL | No | +| `etl::base64_rfc4648_url_padding_decoder` | RFC-4648-URL | Yes | + +### Template parameters +`Buffer_Size` The size of the internal output buffer, in bytes. +Defaults to `etl::base64::Min_Decode_Buffer_Size` (3). +Must be greater than or equal to `etl::base64::Min_Decode_Buffer_Size`. + +### Member types +```cpp +typedef etl::span span_type; +typedef etl::delegate callback_type; +``` + +### Constructors +```cpp +base64_rfcXXXX_decoder() +``` +**Description** +Constructs a decoder with no callback. The decoded result is read from the internal output buffer. + +--- + +```cpp +base64_rfcXXXX_decoder(callback_type callback) +``` +**Description** +Constructs a decoder with a callback. The callback is called with a span of the decoded data each time the internal buffer becomes full, and with an empty span once the final block has been flushed. + +### Decoding ```cpp template -ETL_CONSTEXPR14 -static -size_t encode(const T* input, size_t input_length, - etl::istring& output) +bool decode(T value) ``` -**Description** -Transforms the input data described by input and input_length to Base64 format to be stored in output. -Enabled if `etl::is_integral` is `true` and `etl::integral_limits::bits == 8`. -The output string must have capacity of at least `etl::base64::encode_size(input)`. - -**Return** -The length of the encoded data. - -**Error** -If output_length is not large enough to hold the encoded data then an `etl::base64_overflow` is raised. - ---- - -**Input -> pointer/pointer : Output -> pointer/pointer** -```cpp -template -ETL_CONSTEXPR14 -static -size_t encode(const T* input_begin, const T* input_end, - char* output_begin, char* output_end) -``` -**Description** -Transforms the input data described by input_begin and input_end to Base64 format to be stored in output_begin to output_end. -Enabled if `etl::is_integral` is `true` and `etl::integral_limits::bits == 8`. - -**Return** -The length of the encoded data. - -**Error** -If the output buffer is not large enough to hold the encoded data then an `etl::base64_overflow` is raised. - ---- - -**Input -> pointer/pointer : Output -> string** -```cpp -template -ETL_CONSTEXPR14 -static -size_t encode(const T* input_begin, const T* input_end, - etl::istring& output) -``` -**Description** -Transforms the input data described by input_begin and input_end to Base64 format to be stored in output. -Enabled if `etl::is_integral` is `true` and `etl::integral_limits::bits == 8`. -The output string must have capacity of at least `etl::base64::encode_size(input)`. - -**Return** -The length of the encoded data. - -**Error** -If the output buffer is not large enough to hold the encoded data then an `etl::base64_overflow` is raised. - ---- - -**Input -> span : Output -> span** -```cpp -template -ETL_CONSTEXPR14 -static -size_t encode(const etl::span& input_span, - const etl::span& output_span) -``` -**Description** -Transforms the input data described by input_span to Base64 format to be stored in output_span. -Enabled if etl::is_integral is true and etl::integral_limits::bits == 8. - -**Return** -The length of the encoded data. - -**Error** -If the output span is not large enough to hold the encoded data then an etl::base64_overflow is raised. - ---- - -**Input -> span : Output -> string** -```cpp -template -ETL_CONSTEXPR14 -static -size_t encode(const etl::span& input_span, - etl::istring& output) -``` -**Description** -Transforms the input data described by input_span to Base64 format to be stored in output. -Enabled if etl::is_integral is true and etl::integral_limits::bits == 8 -The output string must have capacity of at least etl::base64::encode_size(input). - -**Return** -The length of the encoded data. - -**Error** -If the output span is not large enough to hold the encoded data then an etl::base64_overflow is raised. - ---- - -```cpp -ETL_NODISCARD -ETL_CONSTEXPR14 -static -size_t encode_size(size_t input_length) -``` -**Return** -Returns the size of the output buffer required to encode the specified input data length. - -## Decode - -**Input -> pointer/length : Output -> pointer/length** -```cpp -template -ETL_CONSTEXPR14 -static -size_t decode(const char* input, size_t input_length, - T* output, size_t output_length) -``` -**Description** -Transforms the Base64 format input data described by input and input_length to by output and output_length. +**Description** +Decodes a single Base64 character. Enabled if `etl::is_integral` is `true` and `etl::integral_limits::bits == 8`. -**Return** -The length of the decoded data. - -**Error** -If `output_length` is not large enough to hold the decoded data then an `etl::base64_overflow` is raised. - ---- - -**Input -> pointer/pointer: Output -> pointer/pointer** -```cpp -template -ETL_CONSTEXPR14 -static -size_t decode(const char* input_begin, const char* input_end, - T* output_begin, T* output_end) -``` -**Description*** -Transforms the Base64 format input data described by `input_begin` and `input_end` to `output_begin` and `output_end`. -Enabled if `etl::is_integral` is `true` and `etl::integral_limits::bits == 8`. - -**Return** -The length of the decoded data. - -**Error** -If the output buffer is not large enough to hold the decoded data then an `etl::base64_overflow` is raised. - ---- - -**Input -> span: Output -> span** -```cpp -template -ETL_CONSTEXPR14 -static -size_t decode(const etl::span& input_span, - const etl::span& output_span) -``` -**Description** -Transforms the Base64 format input data described by input_span to output_span. -Enabled if `etl::is_integral` is `true` and `etl::integral_limits::bits == 8`. - -**Return** -The length of the decoded data. - -**Error** -If the output span is not large enough to hold the decoded data then an `etl::base64_overflow` is raised. +**Return** +`false` if an error was detected, otherwise `true`. --- ```cpp -ETL_NODISCARD -ETL_CONSTEXPR14 -static -size_t decode_size(const char* input, size_t input_length) +template +bool decode(TInputIterator input_begin, TInputIterator input_end) ``` -**Return** -The size of the output buffer required to decode the specified input Base64 data length. +**Description** +Decodes the Base64 characters in the range `input_begin` to `input_end`. + +**Return** +`false` if an error was detected, otherwise `true`. --- ```cpp -ETL_NODISCARD -ETL_CONSTEXPR14 -static -size_t decode_size(const char* input_begin, const char* input_end) +template +bool decode(TInputIterator input_begin, size_t input_length) ``` -**Return** -The size of the output buffer required to decode the specified input Base64 data length. +**Description** +Decodes `input_length` Base64 characters starting at `input_begin`. + +**Return** +`false` if an error was detected, otherwise `true`. --- ```cpp -ETL_NODISCARD -ETL_CONSTEXPR14 -static -size_t decode_size(etl::span input) +template +bool decode_final(TInputIterator input_begin, TInputIterator input_end) ``` -**Return** -The size of the output buffer required to decode the specified input Base64 data length. +**Description** +Decodes the Base64 characters in the range `input_begin` to `input_end`, then flushes the final block. Equivalent to `decode()` followed by `flush()`. + +**Return** +`false` if an error was detected, otherwise `true`. + +--- + +```cpp +template +bool decode_final(TInputIterator input_begin, size_t input_length) +``` +**Description** +Decodes `input_length` Base64 characters starting at `input_begin`, then flushes the final block. Equivalent to `decode()` followed by `flush()`. + +**Return** +`false` if an error was detected, otherwise `true`. + +--- + +```cpp +bool flush() +``` +**Description** +Decodes any remaining buffered input and marks the end of the data. If a callback has been set it is called with any remaining data and then with an empty span. +Must be called once all of the input has been passed to `decode()`. Not required when `decode_final()` is used. + +**Return** +`false` if an error was detected, otherwise `true`. + +--- + +```cpp +void restart() +``` +**Description** +Resets the decoder so that it can be reused to decode a new set of data. + +### Reading the result +These functions return a useful value only when no callback has been set. The internal buffer must be large enough to hold the entire decoded result. + +```cpp +const unsigned char* begin() const +const unsigned char* cbegin() const +``` +**Return** +A pointer to the beginning of the decoded data in the internal buffer. + +--- + +```cpp +const unsigned char* end() const +const unsigned char* cend() const +``` +**Return** +A pointer to the end of the decoded data in the internal buffer. + +--- + +```cpp +size_t size() const +``` +**Return** +The number of decoded bytes currently held in the internal buffer. + +--- + +```cpp +size_t buffer_size() const +``` +**Return** +The maximum size of the internal output buffer (`Buffer_Size`). + +--- + +```cpp +span_type span() const +``` +**Return** +A span over the decoded data in the internal buffer. + +### Status +```cpp +bool overflow() const +``` +**Return** +`true` if the output buffer has overflowed. + +--- + +```cpp +bool invalid_data() const +``` +**Return** +`true` if an invalid Base64 character was encountered. + +--- + +```cpp +bool error() const +``` +**Return** +`true` if an error has been detected. Equivalent to `overflow() || invalid_data()`. + +### Static functions +```cpp +static size_t safe_output_buffer_size(size_t input_length) +``` +**Return** +The internal buffer size required to decode `input_length` Base64 characters in a single pass. Use this as the `Buffer_Size` template argument when the whole result is to be read from the internal buffer. ## Examples -### Encode +### Encode - reading the result from the internal buffer ```cpp -const etl::array input = +// The data to encode. "Hello World!" +constexpr size_t Input_Length = 12U; + +const etl::array input = { - 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, - 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 // "Hello World!" + 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, + 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 }; -etl::string<20> encoded; +// An encoder whose internal buffer is large enough to hold the entire result. +using encoder_type = etl::base64_rfc4648_encoder::safe_output_buffer_size(Input_Length)>; -size_t encoded_size = etl::base64::encode(input.data(), input.size(), - encoded.data(), encoded.size()); +encoder_type encoder; -encoded.resize(encoded_size); -// encoded == "OycDQy37KCphrg==" +// Encode all of the input and flush the final block. +encoder.encode_final(input.begin(), input.end()); + +// Copy the result out of the encoder's internal buffer. +etl::string<16> encoded(encoder.begin(), encoder.end()); +// encoded == "SGVsbG8gV29ybGQh" ``` --- -*For C++14 or above* +### Encode - streaming the result through a callback ```cpp -const etl::array input = +etl::string<16> encoded; + +// Called with each chunk of encoded data as the internal buffer fills, +// and finally with an empty span to signal the end of the data. +auto append = [&encoded](const etl::span& chunk) { - 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, - 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 // "Hello World!" + encoded.append(chunk.begin(), chunk.end()); }; -constexpr size_t length = etl::base64::encode_size(input.size()); -etl::string output; -output.uninitialized_resize(output.capacity()); +etl::base64_rfc4648_encoder<>::callback_type callback = append; -etl::base64::encode(input.data(), input.size(), output.data(), output.size()); -// output == "OycDQy37KCphrg==" +// A minimum size encoder that streams its output through the callback. +etl::base64_rfc4648_encoder<> encoder(callback); + +encoder.encode_final(input.begin(), input.end()); +// encoded == "SGVsbG8gV29ybGQh" ``` --- -### Decode +### Decode - reading the result from the internal buffer ```cpp -const etl::string<16> encoded = "OycDQy37KCphrg=="; +const etl::string<16> encoded = "SGVsbG8gV29ybGQh"; -etl::vector output; +// A decoder whose internal buffer is large enough to hold the entire result. +using decoder_type = etl::base64_rfc4648_decoder::safe_output_buffer_size(16U)>; -size_t decoded_size = etl::base64::decode(encoded.data(), encoded.size(), - output.data(), output.size()); +decoder_type decoder; -output.resize(decoded_size); -// output == { 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, -// 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 }; -``` - ---- - -*For C++14 or above* -```cpp -// "OycDQy37KCphrg==" -constexpr const etl::array input = -{ - 0x4F, 0x79, 0x63, 0x44, 0x51, 0x79, 0x33, 0x37, - 0x4B, 0x43, 0x70, 0x68, 0x72, 0x67, 0x3D, 0x3D -}; - -constexpr size_t length = etl::base64::decode_size(input.data(), input.size()); -etl::vector output; - -etl::base64::decode(input.data(), input.size(), output.data(), output.size()); -// output == { 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, -// 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 }; +// Decode all of the input and flush the final block. +decoder.decode_final(encoded.begin(), encoded.end()); + +// Copy the result out of the decoder's internal buffer. +etl::vector output(decoder.begin(), decoder.end()); +// output == { 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, +// 0x57, 0x6f, 0x72, 0x6c, 0x64, 0x21 }; // "Hello World!" ``` diff --git a/docs/containers/binary/bloom-filter.md b/docs/containers/binary/bloom-filter.md index 828b0313..28f22a5c 100644 --- a/docs/containers/binary/bloom-filter.md +++ b/docs/containers/binary/bloom-filter.md @@ -61,7 +61,7 @@ Equal to `100 * count() / width()` --- ```cpp -bool count() const +size_t count() const ``` **Description** Returns the number of elements in use in the filter. @@ -69,7 +69,7 @@ Returns the number of elements in use in the filter. --- ```cpp -bool width() const +size_t width() const ``` **Description** Returns the width of the filter. diff --git a/docs/containers/lists/forward-list.md b/docs/containers/lists/forward-list.md index b0b358bd..2be721e0 100644 --- a/docs/containers/lists/forward-list.md +++ b/docs/containers/lists/forward-list.md @@ -84,8 +84,8 @@ reference value_type& const_reference const value_type& pointer value_type* const_pointer const value_type* -iterator Bi-directional iterator -const_iterator Constant bi-directional iterator +iterator Forward iterator +const_iterator Constant forward iterator ``` ## Constructors diff --git a/docs/containers/lists/intrusive-forward-list.md b/docs/containers/lists/intrusive-forward-list.md index 81566090..5f1ee051 100644 --- a/docs/containers/lists/intrusive-forward-list.md +++ b/docs/containers/lists/intrusive-forward-list.md @@ -96,26 +96,6 @@ const_iterator cend() const **Description** Returns an iterator to the end of the list. ---- - -```cpp -iterator rbegin() -const_iterator rbegin() const -const_iterator crbegin() const -``` -**Description** -Returns a reverse iterator to the beginning of the list. - ---- - -```cpp -iterator rend() -const_iterator rend() const -const_iterator crend() const -``` -**Description** -Returns a reverse iterator to the end of the list. - ## Capacity ```cpp diff --git a/docs/containers/lists/intrusive-list.md b/docs/containers/lists/intrusive-list.md index f0d4cf71..5d324c9e 100644 --- a/docs/containers/lists/intrusive-list.md +++ b/docs/containers/lists/intrusive-list.md @@ -52,7 +52,7 @@ Creates the list from the range [`begin`, `end`) of node links. ```cpp template -intrusive_list(TLink& first, TLinks&... links)) +intrusive_list(TLink& first, TLinks&... links) ``` **Description** Creates the list from node link references. @@ -95,26 +95,6 @@ const_iterator cend() const **Description** Returns an iterator to the end of the list. ---- - -```cpp -iterator rbegin() -const_iterator rbegin() const -const_iterator crbegin() const -``` -**Description** -Returns a reverse iterator to the beginning of the list. - ---- - -```cpp -iterator rend() -const_iterator rend() const -const_iterator crend() const -``` -**Description** -Returns a reverse iterator to the end of the list. - ## Capacity ```cpp diff --git a/docs/containers/maps/map.md b/docs/containers/maps/map.md index 5266d0d2..d212ce5e 100644 --- a/docs/containers/maps/map.md +++ b/docs/containers/maps/map.md @@ -43,7 +43,7 @@ constexpr auto make_flat_map(TValues&&... values) ### Example ```cpp -auto data = etl::make_map(etl::pair{0, 1}, etl::pair{2, 3}, +auto data = etl::make_map(etl::pair{0, 1}, etl::pair{2, 3}, etl::pair{4, 5}, etl::pair{6, 7}); ``` diff --git a/docs/containers/maps/multimap.md b/docs/containers/maps/multimap.md index 96190528..09fda167 100644 --- a/docs/containers/maps/multimap.md +++ b/docs/containers/maps/multimap.md @@ -43,7 +43,7 @@ constexpr auto make_flat_map(TValues&&... values) ### Example ```cpp -auto data = etl::make_map(etl::pair{0, 1}, etl::pair{2, 3}, +auto data = etl::make_multimap(etl::pair{0, 1}, etl::pair{2, 3}, etl::pair{4, 5}, etl::pair{6, 7}); ``` diff --git a/docs/containers/maps/reference-flat-map.md b/docs/containers/maps/reference-flat-map.md index 738b7df4..57f7dda1 100644 --- a/docs/containers/maps/reference-flat-map.md +++ b/docs/containers/maps/reference-flat-map.md @@ -47,7 +47,7 @@ constexpr auto make_reference_flat_map(TValues&&... values) ``` ### Example -auto data = etl::make_reference_flat_map(etl::pair{0, 1}, etl::pair{2, 3}, +auto data = etl::make_reference_flat_map(etl::pair{0, 1}, etl::pair{2, 3}, etl::pair{4, 5}, etl::pair{6, 7}); ## Member types diff --git a/docs/containers/maps/reference-flat-multimap.md b/docs/containers/maps/reference-flat-multimap.md index f34bbb67..9d4ccd64 100644 --- a/docs/containers/maps/reference-flat-multimap.md +++ b/docs/containers/maps/reference-flat-multimap.md @@ -47,7 +47,7 @@ constexpr auto make_reference_flat_map(TValues&&... values) ``` ### Example -auto data = etl::make_reference_flat_map(etl::pair{0, 1}, etl::pair{2, 3}, +auto data = etl::make_reference_flat_multimap(etl::pair{0, 1}, etl::pair{2, 3}, etl::pair{4, 5}, etl::pair{6, 7}); ## Member types diff --git a/docs/containers/queues & stacks/queue-spsc-locked.md b/docs/containers/queues & stacks/queue-spsc-locked.md index ed925688..271d88f8 100644 --- a/docs/containers/queues & stacks/queue-spsc-locked.md +++ b/docs/containers/queues & stacks/queue-spsc-locked.md @@ -109,8 +109,8 @@ Returns the maximum possible size of the queue. ```cpp bool push(const T& value) bool push(T&& value) -bool push_from_locked(const T& value) -bool push_from_locked(T&& value) +bool push_from_unlocked(const T& value) +bool push_from_unlocked(T&& value) ``` **Description** Pushes a value to the back of the queue. diff --git a/docs/getting-started/interfacing-with-c.md b/docs/getting-started/interfacing-with-c.md index 4ec3e513..8aa9592a 100644 --- a/docs/getting-started/interfacing-with-c.md +++ b/docs/getting-started/interfacing-with-c.md @@ -11,6 +11,7 @@ This is a C function that copies `count` characters , starting from `a`, to a bu size_t CFunctionCopyToBuffer(char* start, size_t count) { size_t i = 0; + char* p = start; while (i < count) { *p++ = 'a' + i; diff --git a/docs/iterators/circular_iterator.md b/docs/iterators/circular_iterator.md index 79c2e791..1e70e539 100644 --- a/docs/iterators/circular_iterator.md +++ b/docs/iterators/circular_iterator.md @@ -233,17 +233,17 @@ ETL_CONSTEXPR14 bool operator !=(TIterator& lhs, std::list data{ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; // The start position to loop from. -std::list::const_iterator> start = data.begin(); +std::list::const_iterator start = data.begin(); std::advance(start, 2); // Create circular iterators. -etl::circular_iterator::const_iterator>> cli(data.begin(), data.end(), start); -etl::circular_iterator::const_reverse_iterator>> clri(data.rbegin(), data.rend); +etl::circular_iterator::const_iterator> cli(data.begin(), data.end(), start); +etl::circular_iterator::const_reverse_iterator> clri(data.rbegin(), data.rend()); // Loop 10 times, taking every third value, starting from the third element for the forward iterator and from the end for the reverse iterator. -for (int = 0; i < 10; ++i) +for (int i = 0; i < 10; ++i) { - std::cout << "(" << *cli << "," << *clrl << ")"; + std::cout << "(" << *cli << "," << *clri << ")"; std::advance(cli, 3); std::advance(clri, 3); } diff --git a/docs/iterators/fixed_iterator.md b/docs/iterators/fixed_iterator.md index d4dfa7a5..207a16d5 100644 --- a/docs/iterators/fixed_iterator.md +++ b/docs/iterators/fixed_iterator.md @@ -75,7 +75,7 @@ etl::fixed_iterator uart_read(UART_READ); etl::fixed_iterator uart_write(UART_WRITE); // Read 20 characters from the port. -std::copy_n(uart_read, 20, std::back_inserter(buffer)); +std::copy_n(uart_read, 20, std::back_inserter(buffer)); // Write the buffer of characters to the port. std::copy(buffer.begin(), buffer.end(), uart_write); diff --git a/docs/maths/constants.md b/docs/maths/constants.md index aecfdebf..d07e292f 100644 --- a/docs/maths/constants.md +++ b/docs/maths/constants.md @@ -89,8 +89,8 @@ power_of_2_round_up<9> -> 16 C++17 and above ```cpp -template -inline constexpr size_t power_of_2_round_up_v = power_of_2_round_up::value; +template +inline constexpr size_t power_of_2_round_up_v = power_of_2_round_up::value; ``` ## power_of_2_round_down @@ -111,8 +111,8 @@ power_of_2_round_down<9> -> 8 C++17 and above ```cpp -template -inline constexpr size_t power_of_2_round_down_v = power_of_2_round_down::value; +template +inline constexpr size_t power_of_2_round_down_v = power_of_2_round_down::value; ``` ## is_power_of_2 @@ -127,8 +127,8 @@ Defines the member value to true if N is a power of 2, otherwise false. C++17 and above ```cpp -template -inline constexpr size_t is_power_of_2_v = is_power_of_2::value; +template +inline constexpr size_t is_power_of_2_v = is_power_of_2::value; ``` ## sqrt @@ -144,7 +144,7 @@ Defines the member value as the largest integer that, when squared, is at less t C++17 and above ```cpp template -inline constexpr size_t sqrt_v = sqrt::value; +inline constexpr size_t sqrt_v = sqrt::value; ``` ## factorial diff --git a/docs/maths/limiter.md b/docs/maths/limiter.md index f2d737c6..648451f8 100644 --- a/docs/maths/limiter.md +++ b/docs/maths/limiter.md @@ -10,8 +10,8 @@ title: "limiter" Limits an input range. ```cpp -template > -class limit : public etl::unary_function +template > +class limiter : public etl::unary_function ``` `TInput` The input data type. diff --git a/docs/messaging/shared-message.md b/docs/messaging/shared-message.md index 79ea8a74..44d58bf5 100644 --- a/docs/messaging/shared-message.md +++ b/docs/messaging/shared-message.md @@ -32,7 +32,7 @@ etl::ireference_counted_message* allocate(const TMessage& message) --- ```cpp -explicit shared_message(etl::ireference_coutnted_message& message) +explicit shared_message(etl::ireference_counted_message& message) ``` Construct from a reference counted message. diff --git a/docs/patterns/singleton-base.md b/docs/patterns/singleton-base.md index af66aa72..94ef116f 100644 --- a/docs/patterns/singleton-base.md +++ b/docs/patterns/singleton-base.md @@ -6,14 +6,16 @@ title: "singleton_base" Header: `singleton_base.h` {{< /callout >}} -Allows creation of a singleton base class. +Allows creation of a singleton base class. + +The class to apply to needs to derive from it. I.e. ``singleton_base`` is intrusive. ```cpp etl::singleton_base ``` `T` The type to use as a singleton. -The class derived derived from this must call the constructor with the instance of itself. +The class derived from this must call the constructor with the instance of itself. Multiple calls to the constructor will result in an `etl::singleton_base_already_created` assertion. Before the constructor Is called, the singleton is in the invalid state. @@ -40,12 +42,15 @@ Returns `true` if the instance is has been attached, otherwise `false`. ```cpp class MyType : public etl::singleton_base { - MyType() - : etl::singleton_base(*this) +public: + MyType() + : etl::singleton_base(*this) { } }; +MyType my_instance; // Construct the singleton instance. + bool is_valid; is_valid = MyType::is_valid(); // true diff --git a/docs/patterns/singleton.md b/docs/patterns/singleton.md index 4d11cdd5..7cbd6d4b 100644 --- a/docs/patterns/singleton.md +++ b/docs/patterns/singleton.md @@ -6,7 +6,9 @@ title: "singleton" Header: `singleton.h` {{< /callout >}} -Allows creation of a singleton, with deterministic construction and destruction. +Allows creation of a singleton, with deterministic construction and destruction. + +Non-intrusive to the class to apply to. ```cpp etl::singleton diff --git a/docs/timers/callback-timer-atomic.md b/docs/timers/callback-timer-atomic.md index d648ac7f..e074ddc8 100644 --- a/docs/timers/callback-timer-atomic.md +++ b/docs/timers/callback-timer-atomic.md @@ -197,7 +197,7 @@ Test test; using callback_type = etl::icallback_timer_atomic::callback_type; -callback_type member_callback = callback_type::create member_callback; +callback_type member_callback = callback_type::create(); //*************************************************************************** // Free function callback via etl::function @@ -206,10 +206,10 @@ int free_ticks1 = 0; void free_callback1() { - ++free_ticks; + ++free_ticks1; } -callback_type free_callback1 = callback_type::create(); +callback_type free_function_callback = callback_type::create(); //*************************************************************************** // Free function callback via function pointer diff --git a/docs/timers/callback-timer-deferred-locked.md b/docs/timers/callback-timer-deferred-locked.md index f7763566..6ce6e5c1 100644 --- a/docs/timers/callback-timer-deferred-locked.md +++ b/docs/timers/callback-timer-deferred-locked.md @@ -250,9 +250,9 @@ public: int ticks; }; -using callback_type = etl::icallback_timer_atomic::callback_type; +using callback_type = etl::icallback_timer_locked::callback_type; -callback_type member_callback = callback_type::create member_callback; +callback_type member_callback = callback_type::create(); //*************************************************************************** // Free function callback via etl::function @@ -261,15 +261,15 @@ int free_ticks1 = 0; void free_callback1() { - ++free_ticks; + ++free_ticks1; } -callback_type free_callback1 = callback_type::create(); +callback_type free_function_callback = callback_type::create(); //*************************************************************************** // Timer controller. //*************************************************************************** -etl::callback_timer<2> timer_controller; +etl::callback_timer_deferred_locked<2, 4> timer_controller; //*************************************************************************** // The main loop. @@ -286,7 +286,6 @@ int main() timer_controller.start(id1); timer_controller.start(id2); - timer_controller.start(id3); timer_controller.enable(true); diff --git a/docs/timers/callback-timer-interrupt.md b/docs/timers/callback-timer-interrupt.md index db486b86..45834642 100644 --- a/docs/timers/callback-timer-interrupt.md +++ b/docs/timers/callback-timer-interrupt.md @@ -19,8 +19,8 @@ The framework relies on a supplied interrupt enable/disable guard type. With thi **Defines the following classes** ```cpp -etl::icallback_timer_atomic -etl::callback_timer_atomic +etl::icallback_timer_interrupt +etl::callback_timer_interrupt ``` Uses definitions from `timer.h`. @@ -215,9 +215,9 @@ struct InterruptGuard int state; }; -using callback_type = etl::icallback_timer_atomic::callback_type; +using callback_type = etl::icallback_timer_interrupt::callback_type; -callback_type member_callback = callback_type::create member_callback; +callback_type member_callback = callback_type::create(); //*************************************************************************** // Free function callback via etl::function @@ -226,10 +226,10 @@ int free_ticks1 = 0; void free_callback1() { - ++free_ticks; + ++free_ticks1; } -callback_type free_callback1 = callback_type::create(); +callback_type free_function_callback = callback_type::create(); //*************************************************************************** // Free function callback via function pointer @@ -244,7 +244,7 @@ void free_callback2() //*************************************************************************** // Timer controller. //*************************************************************************** -etl::callback_timer_atomic<2, InterruptGuard> timer_controller; +etl::callback_timer_interrupt<2, InterruptGuard> timer_controller; //*************************************************************************** // The main loop. diff --git a/docs/timers/callback-timer-locked.md b/docs/timers/callback-timer-locked.md index 1803ed96..55322344 100644 --- a/docs/timers/callback-timer-locked.md +++ b/docs/timers/callback-timer-locked.md @@ -228,9 +228,9 @@ public: int ticks; }; -using callback_type = etl::icallback_timer_atomic::callback_type; +using callback_type = etl::icallback_timer_locked::callback_type; -callback_type member_callback = callback_type::create member_callback; +callback_type member_callback = callback_type::create(); //*************************************************************************** // Free function callback via etl::function @@ -239,15 +239,15 @@ int free_ticks1 = 0; void free_callback1() { - ++free_ticks; + ++free_ticks1; } -callback_type free_callback1 = callback_type::create(); +callback_type free_function_callback = callback_type::create(); //*************************************************************************** // Timer controller. //*************************************************************************** -etl::callback_timer<2> timer_controller; +etl::callback_timer_locked<2> timer_controller; //*************************************************************************** // The main loop. @@ -264,7 +264,6 @@ int main() timer_controller.start(id1); timer_controller.start(id2); - timer_controller.start(id3); timer_controller.enable(true); diff --git a/docs/timers/callback-timer.md b/docs/timers/callback-timer.md index e482f75a..d64c8dba 100644 --- a/docs/timers/callback-timer.md +++ b/docs/timers/callback-timer.md @@ -245,7 +245,7 @@ int free_ticks1 = 0; void free_callback1() { - ++free_ticks; + ++free_ticks1; } etl::function_fv free_function_callback; diff --git a/docs/timers/message-timer-interrupt.md b/docs/timers/message-timer-interrupt.md index 30ad6f35..9cbc6d70 100644 --- a/docs/timers/message-timer-interrupt.md +++ b/docs/timers/message-timer-interrupt.md @@ -19,8 +19,8 @@ The framework relies on a supplied interrupt enable/disable guard type. With thi **Defines the following classes** ```cpp -etl::imessage_timer_atomic -etl::message_timer_atomic +etl::imessage_timer_interrupt +etl::message_timer_interrupt ``` The `TInterruptGuard` type must disable and save the interrupt state on construction, and restore on destruction. @@ -257,7 +257,7 @@ class Bus1 : public etl::message_bus<1> Router1 router1; Bus1 bus1; -etl::message_timer_atomic<3, InterruptGuard> timer_controller; +etl::message_timer_interrupt<3, InterruptGuard> timer_controller; //*************************************************************************** // The main loop. diff --git a/docs/timers/message-timer-locked.md b/docs/timers/message-timer-locked.md index e134b09c..dadd6d46 100644 --- a/docs/timers/message-timer-locked.md +++ b/docs/timers/message-timer-locked.md @@ -263,7 +263,7 @@ class Bus1 : public etl::message_bus<1> Router1 router1; Bus1 bus1; -etl::message_timer_atomic<3> timer_controller; +etl::message_timer_locked<3> timer_controller; //*************************************************************************** // The main loop. diff --git a/docs/tutorials/callback-service.md b/docs/tutorials/callback-service.md index cb05346b..972e97c1 100644 --- a/docs/tutorials/callback-service.md +++ b/docs/tutorials/callback-service.md @@ -35,8 +35,8 @@ enum VectorId USART1_IRQ_HANDLER = 52, USART2_IRQ_HANDLER = 53, VECTOR_ID_END, - OFFSET = TIM1_CC_IRQ_HANDLER, - RANGE = VECTOR_ID_END - VECTOR_ID_OFFSET, + VECTOR_ID_OFFSET = TIM1_CC_IRQ_HANDLER, + VECTOR_ID_RANGE = VECTOR_ID_END - VECTOR_ID_OFFSET, }; typedef etl::callback_service InterruptVectors; diff --git a/docs/tutorials/shared-message_tutorial.md b/docs/tutorials/shared-message_tutorial.md index d9d1803b..f94efb1b 100644 --- a/docs/tutorials/shared-message_tutorial.md +++ b/docs/tutorials/shared-message_tutorial.md @@ -302,8 +302,8 @@ Bus bus; // to store reference counted messages in. // The reference counted message parameters type for the messages we will use. -using message_parameters_small = MessagePool::pool_message_parameters; +using message_parameters_small = MessagePool::pool_message_parameters; using message_parameters_large = MessagePool::pool_message_parameters; diff --git a/docs/tutorials/visitor-tutorial.md b/docs/tutorials/visitor-tutorial.md index 74073194..7ce60000 100644 --- a/docs/tutorials/visitor-tutorial.md +++ b/docs/tutorials/visitor-tutorial.md @@ -28,7 +28,7 @@ class Triangle; // Pure virtual 'visit' functions will be defined for the Square, // Circle, and Triangle types. //***************************************************************** -class Shape_Visitor : public etl:visitor +class Shape_Visitor : public etl::visitor { }; ``` diff --git a/docs/types/smallest.md b/docs/types/smallest.md index fd1f26b1..6cdc41d7 100644 --- a/docs/types/smallest.md +++ b/docs/types/smallest.md @@ -50,12 +50,12 @@ template struct Test { // Defines smallest_t as the smallest type of T1, T2 and T3. - typedef typename etl::smallest_type::type largest_t; + typedef typename etl::smallest_type::type smallest_t; enum { - // Defines size as the size of the largest type. - size = etl::largest_type::size; + // Defines size as the size of the smallest type. + size = etl::smallest_type::size; } }; ``` diff --git a/docs/utilities/algorithms.md b/docs/utilities/algorithms.md index 05a4f7ae..e6e1e0d8 100644 --- a/docs/utilities/algorithms.md +++ b/docs/utilities/algorithms.md @@ -43,9 +43,9 @@ Swaps the elements pointed to by two iterators. ## swap_ranges ```cpp -template -TIterator2 swap_ranges(T1terator1 first1, - T1terator1 last1, +template +TIterator2 swap_ranges(TIterator1 first1, + TIterator1 last1, TIterator2 first2) ``` **Description** @@ -116,10 +116,10 @@ A safer version that will stop copying when either `n` items have been copied o ```cpp template -TOutputIterator copy_n_s(TIterator i_begin, +TOutputIterator copy_n_s(TInputIterator i_begin, TSize1 n1, TOutputIterator o_begin, - TSize1 n2,) + TSize2 n2) ``` **Description** A safer version that will stop copying when either n1 or n2 items have been copied. diff --git a/docs/utilities/bit-stream-reader.md b/docs/utilities/bit-stream-reader.md index 3a528a8a..2a383c01 100644 --- a/docs/utilities/bit-stream-reader.md +++ b/docs/utilities/bit-stream-reader.md @@ -247,7 +247,7 @@ namespace etl short s = stream.read_unchecked(); int32_t i = stream.read_unchecked(); - return CustomType { c.value(), s.value(), i.value() }; + return CustomType { c, s, i }; } } @@ -257,6 +257,6 @@ etl::bit_stream_reader bit_stream(storage.data(), storage.size()); // Read unchecked values from the stream. char c = etl::read_unchecked(bit_stream, 6U); unsigned short s = etl::read_unchecked(bit_stream, 13U); -CustomType custom = etl::read_unchecked(bit_stream); +CustomType custom = etl::read_unchecked(bit_stream); int32_t i = etl::read_unchecked<>(bit_stream, 23U); ``` diff --git a/docs/utilities/utility.md b/docs/utilities/utility.md index eeeb2267..3e36bc7a 100644 --- a/docs/utilities/utility.md +++ b/docs/utilities/utility.md @@ -161,7 +161,7 @@ Calls the wrapped function with the forwarded parameters. ### Example ```cpp -void int Function(int i) +int Function(int i) { return i; }