mirror of
https://github.com/ETLCPP/etl.git
synced 2026-07-31 00:36:20 +08:00
Compare commits
24 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f290365a9 | ||
|
|
afa17c5042 | ||
|
|
c5dc331004 | ||
|
|
4bf6ed6ce8 | ||
|
|
2ed9019df0 | ||
|
|
423e18d96d | ||
|
|
c707428cc4 | ||
|
|
338bfdbb1f | ||
|
|
269025424f | ||
|
|
c004cc9d50 | ||
|
|
faa4c15b49 | ||
|
|
1523e63e35 | ||
|
|
878a0ba5a2 | ||
|
|
da0c764a30 | ||
|
|
5287fe4b3b | ||
|
|
40dddd7f96 | ||
|
|
84fca4cd62 | ||
|
|
dca6653b37 | ||
|
|
c52b2ac7b1 | ||
|
|
165674cb23 | ||
|
|
032ec4cc80 | ||
|
|
98cb365d4c | ||
|
|
5cd2f28cd5 | ||
|
|
a47c0aae81 |
32
.github/workflows/gcc-c++23.yml
vendored
32
.github/workflows/gcc-c++23.yml
vendored
@ -21,12 +21,12 @@ jobs:
|
||||
- name: Build
|
||||
run: |
|
||||
export ASAN_OPTIONS=alloc_dealloc_mismatch=0,detect_leaks=0
|
||||
export CC=gcc
|
||||
export CXX=g++
|
||||
export CC=gcc-14
|
||||
export CXX=g++-14
|
||||
cmake -DBUILD_TESTS=ON -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=23 -DETL_OPTIMISATION=-O3 ./
|
||||
gcc --version
|
||||
gcc-14 --version
|
||||
make -j "$(getconf _NPROCESSORS_ONLN)"
|
||||
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
@ -43,12 +43,12 @@ jobs:
|
||||
- name: Build
|
||||
run: |
|
||||
export ASAN_OPTIONS=alloc_dealloc_mismatch=0,detect_leaks=0
|
||||
export CC=gcc
|
||||
export CXX=g++
|
||||
export CC=gcc-14
|
||||
export CXX=g++-14
|
||||
cmake -DBUILD_TESTS=ON -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=OFF -DETL_CXX_STANDARD=23 -DETL_OPTIMISATION=-O3 ./
|
||||
gcc --version
|
||||
gcc-14 --version
|
||||
make -j "$(getconf _NPROCESSORS_ONLN)"
|
||||
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
@ -65,10 +65,10 @@ jobs:
|
||||
- name: Build
|
||||
run: |
|
||||
export ASAN_OPTIONS=alloc_dealloc_mismatch=0,detect_leaks=0
|
||||
export CC=gcc
|
||||
export CXX=g++
|
||||
export CC=gcc-14
|
||||
export CXX=g++-14
|
||||
cmake -DBUILD_TESTS=ON -DNO_STL=OFF -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=23 -DETL_OPTIMISATION=-O3 ./
|
||||
gcc --version
|
||||
gcc-14 --version
|
||||
make -j "$(getconf _NPROCESSORS_ONLN)"
|
||||
|
||||
- name: Run tests
|
||||
@ -87,11 +87,11 @@ jobs:
|
||||
- name: Build
|
||||
run: |
|
||||
export ASAN_OPTIONS=alloc_dealloc_mismatch=0,detect_leaks=0
|
||||
export CC=gcc
|
||||
export CXX=g++
|
||||
export CC=gcc-14
|
||||
export CXX=g++-14
|
||||
cmake -DBUILD_TESTS=ON -DNO_STL=ON -DETL_USE_TYPE_TRAITS_BUILTINS=OFF -DETL_USER_DEFINED_TYPE_TRAITS=OFF -DETL_FORCE_TEST_CPP03_IMPLEMENTATION=ON -DETL_CXX_STANDARD=23 -DETL_OPTIMISATION=-O3 ./
|
||||
gcc --version
|
||||
gcc-14 --version
|
||||
make -j "$(getconf _NPROCESSORS_ONLN)"
|
||||
|
||||
|
||||
- name: Run tests
|
||||
run: ./test/etl_tests -v
|
||||
run: ./test/etl_tests -v
|
||||
|
||||
27
BUILD.bazel
27
BUILD.bazel
@ -2,8 +2,35 @@ load("@rules_cc//cc:defs.bzl", "cc_library")
|
||||
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
# ETL can be tailored to a project through an `etl_profile.h` header (see
|
||||
# `include/etl/platform.h`). When no such header is on the include path, ETL
|
||||
# falls back to its built-in defaults via `ETL_NO_PROFILE_HEADER`.
|
||||
#
|
||||
# This label_flag lets a consumer inject that profile as a Bazel target, without
|
||||
# patching this BUILD file:
|
||||
#
|
||||
# bazel build @etl//:etl --@etl//:etl_profile=//path/to:my_etl_profile
|
||||
#
|
||||
# The injected target is a cc_library that exposes a single `etl_profile.h` on
|
||||
# its include path, for example:
|
||||
#
|
||||
# cc_library(
|
||||
# name = "my_etl_profile",
|
||||
# hdrs = ["etl_profile.h"],
|
||||
# strip_include_prefix = ".",
|
||||
# )
|
||||
#
|
||||
# The default is empty, so ETL's built-in defaults are used unless overridden.
|
||||
label_flag(
|
||||
name = "etl_profile",
|
||||
build_setting_default = ":no_profile",
|
||||
)
|
||||
|
||||
cc_library(name = "no_profile")
|
||||
|
||||
cc_library(
|
||||
name = "etl",
|
||||
hdrs = glob(["include/**/*.h"]),
|
||||
includes = ["include"],
|
||||
deps = [":etl_profile"],
|
||||
)
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Embedded Template Library ETL",
|
||||
"version": "20.48.0",
|
||||
"version": "20.48.1",
|
||||
"authors": {
|
||||
"name": "John Wellbelove",
|
||||
"email": "john.wellbelove@etlcpp.com"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library ETL
|
||||
version=20.48.0
|
||||
version=20.48.1
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
@ -39,14 +39,13 @@ type: hextra-home
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<a href="https://github.com/ETLCPP/etl/actions/workflows/coverage.yml"><img src="https://github.com/ETLCPP/etl/actions/workflows/coverage.yml/badge.svg" alt="coverage"></a>
|
||||
<a href="https://etlcpp.github.io/etl/"><img src="https://github.com/ETLCPP/etl/actions/workflows/coverage.yml/badge.svg" alt="coverage"">
|
||||
<a href="https://www.codacy.com/manual/jwellbelove/etl"><img src="https://api.codacy.com/project/badge/Grade/3c14cd918ccf40008d0bcd7b083d5946" alt="Codacy"></a>
|
||||
</div>
|
||||
|
||||
|
||||
<div>
|
||||
<a href="https://www.etlcpp.com/sponsor.html"><img src="https://img.shields.io/static/v1?label=Sponsor&message=%E2%9D%A4&logo=GitHub&color=%23fe8e86" alt="Sponsor"></a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
## Version
|
||||
|
||||
@ -135,4 +135,49 @@ ETL_NOEXCEPT
|
||||
```
|
||||
A specialisation of absolute for `etl::chrono::duration`.
|
||||
**Return**
|
||||
The absolute duration value.
|
||||
The absolute duration value.
|
||||
|
||||
## 12/24 hour functions
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14
|
||||
bool is_am(const etl::chrono::hours& h)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns `true` if `h` is in the range [0h, 11h] (an am hour).
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14
|
||||
bool is_pm(const etl::chrono::hours& h)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns `true` if `h` is in the range [12h, 23h] (a pm hour).
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14
|
||||
etl::chrono::hours make12(const etl::chrono::hours& h)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns the 12-hour equivalent of `h` in the range [1h, 12h].
|
||||
If `h` is not in the range [0h, 23h], the value returned is unspecified.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14
|
||||
etl::chrono::hours make24(const etl::chrono::hours& h, bool is_pm)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Returns the 24-hour equivalent of `h`, which is assumed to represent the hour with the indicated am/pm.
|
||||
If `h` is not in the range [1h, 12h], the value returned is unspecified.
|
||||
@ -100,6 +100,41 @@ ETL_NOEXCEPT
|
||||
**Description**
|
||||
Subtracts a duration.
|
||||
|
||||
## Increment/decrement
|
||||
```cpp
|
||||
ETL_CONSTEXPR14 time_point& operator ++()
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Pre-increments the stored duration by one tick.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR14 time_point operator ++(int)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Post-increments the stored duration by one tick.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR14 time_point& operator --()
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Pre-decrements the stored duration by one tick.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
ETL_CONSTEXPR14 time_point operator --(int)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Post-decrements the stored duration by one tick.
|
||||
|
||||
## Constants
|
||||
```cpp
|
||||
ETL_NODISCARD
|
||||
@ -180,6 +215,65 @@ If time_point < other, returns -1
|
||||
else if time_point > other, returns 1
|
||||
else returns 0
|
||||
|
||||
## Non-member mathematical operators
|
||||
```cpp
|
||||
template <typename TClock, typename TDuration1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::time_point<TClock, typename etl::common_type<TDuration1, etl::chrono::duration<TRep2, TPeriod2> >::type>
|
||||
operator +(const time_point<TClock, TDuration1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Adds a duration to a time_point.
|
||||
**Return**
|
||||
A time_point whose duration is the common type of the two.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TRep1, typename TPeriod1, typename TClock, typename TDuration2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::time_point<TClock, typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, TDuration2>::type>
|
||||
operator +(const etl::chrono::duration<TRep1, TPeriod1>& lhs,
|
||||
const time_point<TClock, TDuration2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Adds a duration to a time_point.
|
||||
**Return**
|
||||
A time_point whose duration is the common type of the two.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TClock, typename TDuration1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14
|
||||
etl::chrono::time_point<TClock, typename etl::common_type<TDuration1, etl::chrono::duration<TRep2, TPeriod2> >::type>
|
||||
operator -(const time_point<TClock, TDuration1>& lhs,
|
||||
const etl::chrono::duration<TRep2, TPeriod2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Subtracts a duration from a time_point.
|
||||
**Return**
|
||||
A time_point whose duration is the common type of the two.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
ETL_CONSTEXPR14
|
||||
typename etl::common_type<TDuration1, TDuration2>::type
|
||||
operator -(const time_point<TClock, TDuration1>& lhs,
|
||||
const time_point<TClock, TDuration2>& rhs)
|
||||
ETL_NOEXCEPT
|
||||
```
|
||||
**Description**
|
||||
Subtracts one time_point from another.
|
||||
**Return**
|
||||
The duration between them as the common type of the two durations.
|
||||
|
||||
## Non-member comparison operators
|
||||
```cpp
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
|
||||
@ -96,10 +96,9 @@ If assert or exceptions are not enabled then undefined behaviour occurs.
|
||||
|
||||
```cpp
|
||||
TMapped& operator[](key_parameter_t key)
|
||||
const TMapped& operator[](key_parameter_t key) const
|
||||
```
|
||||
**Description**
|
||||
Returns a reference or const reference to the indexed element.
|
||||
Returns a reference to the indexed element.
|
||||
If the key does not exist then one is created using the default constructor.
|
||||
If the map is full then asserts an `etl::map_full`. If asserts or exceptions are not enabled then undefined behaviour occurs.
|
||||
|
||||
|
||||
@ -5,6 +5,24 @@ weight: 2002
|
||||
|
||||
Click on the links to see the original Github page.
|
||||
|
||||
## 20.48.1
|
||||
|
||||
**Pull requests:**
|
||||
|
||||
[#1477](https://github.com/ETLCPP/etl/pull/1477) Fix for 1405: etl::exchange doesn't work with unique_ptr
|
||||
[#1484](https://github.com/ETLCPP/etl/pull/1484) Fix `etl::message_timer` firing following timers early on unregister
|
||||
[#1485](https://github.com/ETLCPP/etl/pull/1485) Fix `etl::histogram` copy/move not preserving start_index
|
||||
[#1486](https://github.com/ETLCPP/etl/pull/1486) Fix `etl::bitset` single-element `from_string` shift on empty string
|
||||
[#1487](https://github.com/ETLCPP/etl/pull/1487) Fix `etl::pearson::reset()` not resetting the first-byte flag
|
||||
[#1488](https://github.com/ETLCPP/etl/pull/1488) Fix `etl::mem_cast` cross-size copy constructor and assignment
|
||||
[#1489](https://github.com/ETLCPP/etl/pull/1489) Add missing interfaces to `etl::chrono`
|
||||
[#1490](https://github.com/ETLCPP/etl/pull/1490) Add missing memory functions, according the standard
|
||||
[#1491](https://github.com/ETLCPP/etl/pull/1491) Add optional `etl_profile` `label_flag` for Bazel profile injection
|
||||
[#1492](https://github.com/ETLCPP/etl/pull/1492) Allow `etl::vector` to store pointers to functions and member functions
|
||||
[#1494](https://github.com/ETLCPP/etl/pull/1494) Refactor `variant::emplace` to perfect forward args instead of copy/move construct
|
||||
[#1495](https://github.com/ETLCPP/etl/pull/1495) Separate bit order and endianness in `bit_stream.h`
|
||||
[#1496](https://github.com/ETLCPP/etl/pull/1496) Fix non-assignable alternatives in variant
|
||||
|
||||
## 20.48.0
|
||||
|
||||
**Pull requests:**
|
||||
|
||||
@ -296,3 +296,37 @@ Then use them with `--config`:
|
||||
```sh
|
||||
bazel test //test:etl_tests --config=clang --config=c++20 --config=release
|
||||
```
|
||||
|
||||
### Injecting a Custom Profile Header
|
||||
|
||||
Instead of passing many individual `--copt=-D...` flags, ETL can be configured in bulk through a user-provided `etl_profile.h` header. When such a header is reachable on the include path, `include/etl/platform.h` includes it automatically; otherwise ETL falls back to its built-in defaults (`ETL_NO_PROFILE_HEADER`).
|
||||
|
||||
Because the header must sit on ETL's include path, `BUILD.bazel` exposes an `etl_profile` [`label_flag`](https://bazel.build/extending/config) so you can inject it as a Bazel target — without patching ETL's `BUILD.bazel`.
|
||||
|
||||
First, wrap your profile header in a `cc_library` that places `etl_profile.h` on its include path:
|
||||
|
||||
```python
|
||||
# path/to/BUILD.bazel
|
||||
cc_library(
|
||||
name = "my_etl_profile",
|
||||
hdrs = ["etl_profile.h"],
|
||||
strip_include_prefix = ".",
|
||||
)
|
||||
```
|
||||
|
||||
Then point the `etl_profile` flag at that target when building:
|
||||
|
||||
```sh
|
||||
bazel build @etl//:etl --@etl//:etl_profile=//path/to:my_etl_profile
|
||||
```
|
||||
|
||||
The flag defaults to an empty library (`:no_profile`), so ETL uses its built-in defaults unless you override it. As with any flag, the override can be made permanent in `.bazelrc`:
|
||||
|
||||
```
|
||||
# .bazelrc
|
||||
build --@etl//:etl_profile=//path/to:my_etl_profile
|
||||
```
|
||||
|
||||
> **Note:** Use the repository-qualified form `--@etl//:etl_profile=...` when consuming ETL as an
|
||||
> external dependency. When building from within the ETL repository itself, drop the repository
|
||||
> prefix: `--//:etl_profile=...`.
|
||||
|
||||
@ -3,7 +3,7 @@ title: "type_traits"
|
||||
---
|
||||
|
||||
Reverse engineered types traits classes from C++11 plus several ETL extensions.
|
||||
This file is generated from type_traits_generator.h. See Generators
|
||||
This file is generated from `type_traits_generator.h`. See Generators
|
||||
Not all traits have been defined as some rely on compiler intrinsics that are not available on all compiler platforms.
|
||||
|
||||
`integral_constant`
|
||||
@ -459,3 +459,20 @@ template <typename T, template <typename...> class Template>
|
||||
inline constexpr bool is_specialization_v = etl::is_specialization<T, Template>::value;
|
||||
```
|
||||
C++17
|
||||
|
||||
## is_object_pointer
|
||||
From: `20.49.0`
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
struct is_object_pointer
|
||||
```
|
||||
Checks if `T` is a pointer to an object.
|
||||
Pointers to functions and member functions return `false`.
|
||||
The result is found in the member `value`.
|
||||
|
||||
```cpp
|
||||
template <typename T>
|
||||
inline constexpr bool is_object_pointer_v = etl::is_object_pointer<T>::value;
|
||||
```
|
||||
C++17
|
||||
|
||||
@ -3,11 +3,11 @@ title: "bit_stream_reader"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `bit_stream_reader.h`
|
||||
Header: `bit_stream.h`
|
||||
Since: `TBC`
|
||||
{{< /callout >}}
|
||||
|
||||
A binary streaming utility that allows values to be read from an array of char or unsigned char using custom bits widths for efficient packing. Values may be streamed in either msb or lsb format.
|
||||
A binary streaming utility that allows values to be read from an array of char or unsigned char using custom bits widths for efficient packing. The bit order (MSB or LSB first) and the byte order (endianness) can be configured independently.
|
||||
|
||||
Read functions come in both checked and unchecked forms.
|
||||
- Unchecked reads return a value of the specified type.
|
||||
@ -36,38 +36,42 @@ const_iterator const char*
|
||||
## Member functions
|
||||
|
||||
```cpp
|
||||
bit_stream_reader(etl::span<char> span, etl::endian stream_endianness)
|
||||
bit_stream_reader(etl::span<char> span, etl::bit_order bit_order, etl::endian byte_order = etl::endian::big)
|
||||
```
|
||||
**Parameters**
|
||||
`span` A `char` span of the read buffer.
|
||||
`stream_endianness` The endianness of the stream. `etl::endian::little` or `etl::endian::big`.
|
||||
`bit_order` The bit order of the stream. `etl::bit_order::msb_first` (MSB first) or `etl::bit_order::lsb_first` (LSB first).
|
||||
`byte_order` The byte order (endianness) of the stream. `etl::endian::big` or `etl::endian::little`. Defaults to `etl::endian::big`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bit_stream_reader(etl::span<unsigned char> span, etl::endian stream_endianness)
|
||||
bit_stream_reader(etl::span<unsigned char> span, etl::bit_order bit_order, etl::endian byte_order = etl::endian::big)
|
||||
```
|
||||
**Parameters**
|
||||
`span` `An unsigned char span` of the read buffer.
|
||||
`stream_endianness` The endianness of the stream. `etl::endian::little` or `etl::endian::big`.
|
||||
`bit_order` The bit order of the stream. `etl::bit_order::msb_first` (MSB first) or `etl::bit_order::lsb_first` (LSB first).
|
||||
`byte_order` The byte order (endianness) of the stream. `etl::endian::big` or `etl::endian::little`. Defaults to `etl::endian::big`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bit_stream_reader(void* begin, void* end, etl::endian stream_endianness)
|
||||
bit_stream_reader(const void* begin, const void* end, etl::bit_order bit_order, etl::endian byte_order = etl::endian::big)
|
||||
```
|
||||
`begin` A pointer to the beginning of the read buffer.
|
||||
`end` A pointer to the beginning of the read buffer.
|
||||
`stream_endianness` The endianness of the stream. `etl::endian::little` or `etl::endian::big`.
|
||||
`begin` A const pointer to the beginning of the read buffer.
|
||||
`end` A const pointer to the end of the read buffer.
|
||||
`bit_order` The bit order of the stream. `etl::bit_order::msb_first` (MSB first) or `etl::bit_order::lsb_first` (LSB first).
|
||||
`byte_order` The byte order (endianness) of the stream. `etl::endian::big` or `etl::endian::little`. Defaults to `etl::endian::big`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bit_stream_reader(void* begin, size_t length, etl::endian stream_endianness)
|
||||
bit_stream_reader(const void* begin, size_t length, etl::bit_order bit_order, etl::endian byte_order = etl::endian::big)
|
||||
```
|
||||
`begin` A pointer to the beginning of the read buffer.
|
||||
`begin` A const pointer to the beginning of the read buffer.
|
||||
`length` The length, in char, of the read buffer.
|
||||
`stream_endianness` The endianness of the stream. `etl::endian::little` or `etl::endian::big`.
|
||||
`bit_order` The bit order of the stream. `etl::bit_order::msb_first` (MSB first) or `etl::bit_order::lsb_first` (LSB first).
|
||||
`byte_order` The byte order (endianness) of the stream. `etl::endian::big` or `etl::endian::little`. Defaults to `etl::endian::big`.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -3,11 +3,11 @@ title: "bit_stream_writer"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `bit_stream_writer.h`
|
||||
Header: `bit_stream.h`
|
||||
Since: `TBC`
|
||||
{{< /callout >}}
|
||||
|
||||
A binary streaming utility that allows values to be written to an array of char or unsigned char using custom bits widths for efficient packing. Values may be streamed in either msb or lsb format.
|
||||
A binary streaming utility that allows values to be written to an array of char or unsigned char using custom bits widths for efficient packing. The bit order (MSB or LSB first) and the byte order (endianness) can be configured independently.
|
||||
|
||||
Write functions come in both checked and unchecked forms.
|
||||
- Unchecked writes return `void`.
|
||||
@ -38,51 +38,56 @@ callback_type etl::delegate<void(callback_parameter_type)>
|
||||
|
||||
## Member functions
|
||||
```cpp
|
||||
bit_stream_writer(etl::span<char> span, etl::endian stream_endianness, callback_type callback = callback_type())
|
||||
bit_stream_writer(etl::span<char> span, etl::bit_order bit_order, callback_type callback = callback_type(), etl::endian byte_order = etl::endian::big)
|
||||
```
|
||||
**Description**
|
||||
Construct from span.
|
||||
**Parameters**
|
||||
`span` A char span of the read buffer.
|
||||
`stream_endianness` The endianness of the stream. `etl::endian::little` or `etl::endian::big`.
|
||||
`callback` An optional callback.
|
||||
`span` A char span of the write buffer.
|
||||
`bit_order` The bit order of the stream. `etl::bit_order::msb_first` (MSB first) or `etl::bit_order::lsb_first` (LSB first).
|
||||
`callback` An optional callback.
|
||||
`byte_order` The byte order (endianness) of the stream. `etl::endian::big` or `etl::endian::little`. Defaults to `etl::endian::big`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bit_stream_writer(etl::span<unsigned char> span, etl::endian stream_endianness, callback_type callback = callback_type())
|
||||
bit_stream_writer(etl::span<unsigned char> span, etl::bit_order bit_order, callback_type callback = callback_type(), etl::endian byte_order = etl::endian::big)
|
||||
```
|
||||
**Description**
|
||||
Construct from span.
|
||||
**Parameters**
|
||||
`span` A char span of the read buffer.
|
||||
`stream_endianness` The endianness of the stream. etl::endian::little or etl::endian::big.
|
||||
`callback` An optional callback.
|
||||
`span` An unsigned char span of the write buffer.
|
||||
`bit_order` The bit order of the stream. `etl::bit_order::msb_first` (MSB first) or `etl::bit_order::lsb_first` (LSB first).
|
||||
`callback` An optional callback.
|
||||
`byte_order` The byte order (endianness) of the stream. `etl::endian::big` or `etl::endian::little`. Defaults to `etl::endian::big`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bit_stream_writer(void* begin, void* end, etl::endian stream_endianness, callback_type callback = callback_type())
|
||||
bit_stream_writer(void* begin, void* end, etl::bit_order bit_order, callback_type callback = callback_type(), etl::endian byte_order = etl::endian::big)
|
||||
```
|
||||
**Description**
|
||||
Construct from range.
|
||||
**Parameters**
|
||||
`begin` A pointer to the beginning of the read buffer.
|
||||
`end` A pointer to the beginning of the read buffer.
|
||||
`stream_endianness` The endianness of the stream. `etl::endian::little` or `etl::endian::big`.
|
||||
`callback` An optional callback.
|
||||
`begin` A pointer to the beginning of the write buffer.
|
||||
`end` A pointer to the end of the write buffer.
|
||||
`bit_order` The bit order of the stream. `etl::bit_order::msb_first` (MSB first) or `etl::bit_order::lsb_first` (LSB first).
|
||||
`callback` An optional callback.
|
||||
`byte_order` The byte order (endianness) of the stream. `etl::endian::big` or `etl::endian::little`. Defaults to `etl::endian::big`.
|
||||
|
||||
---
|
||||
|
||||
```cpp
|
||||
bit_stream_writer(void* begin, size_t length_chars, etl::endian stream_endianness, callback_type callback = callback_type())
|
||||
bit_stream_writer(void* begin, size_t length_chars, etl::bit_order bit_order, callback_type callback = callback_type(), etl::endian byte_order = etl::endian::big)
|
||||
```
|
||||
**Description**
|
||||
Construct from begin and length.
|
||||
**Parameters**
|
||||
`begin` A pointer to the beginning of the read buffer.
|
||||
`length` The length, in char, of the read buffer.
|
||||
`stream_endianness` The endianness of the stream. `etl::endian::little` or `etl::endian::big`.
|
||||
`begin` A pointer to the beginning of the write buffer.
|
||||
`length` The length, in char, of the write buffer.
|
||||
`bit_order` The bit order of the stream. `etl::bit_order::msb_first` (MSB first) or `etl::bit_order::lsb_first` (LSB first).
|
||||
`callback` An optional callback.
|
||||
`byte_order` The byte order (endianness) of the stream. `etl::endian::big` or `etl::endian::little`. Defaults to `etl::endian::big`.
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ title: "byte_stream_reader"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `byte_stream_reader.h`
|
||||
Header: `byte_stream.h`
|
||||
From: `20.17.0`
|
||||
{{< /callout >}}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ title: "byte_stream_writer"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `byte_stream_writer.h`
|
||||
Header: `byte_stream.h`
|
||||
From: `20.17.0`
|
||||
{{< /callout >}}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ title: "constant"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `constants.h`
|
||||
Header: `constant.h`
|
||||
Since: `TBC`
|
||||
{{< /callout >}}
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@ title: "endian"
|
||||
---
|
||||
|
||||
{{< callout type="info">}}
|
||||
Header: `endian.h`
|
||||
Header: `endianness.h`
|
||||
Since: `TBC`
|
||||
{{< /callout >}}
|
||||
|
||||
|
||||
@ -1 +1 @@
|
||||
20.48.0
|
||||
20.48.1
|
||||
|
||||
@ -914,6 +914,7 @@ namespace etl
|
||||
TDistance top_index = value_index;
|
||||
TDistance child2nd = (2 * value_index) + 2;
|
||||
|
||||
#include "etl/private/diagnostic_array_bounds_push.h"
|
||||
while (child2nd < length)
|
||||
{
|
||||
if (compare(*(first + child2nd), *(first + (child2nd - 1))))
|
||||
@ -931,6 +932,7 @@ namespace etl
|
||||
*(first + value_index) = ETL_MOVE(*(first + (child2nd - 1)));
|
||||
value_index = child2nd - 1;
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
push_heap(first, value_index, top_index, ETL_MOVE(value), compare);
|
||||
}
|
||||
@ -965,6 +967,12 @@ namespace etl
|
||||
typedef typename etl::iterator_traits<TIterator>::value_type value_t;
|
||||
typedef typename etl::iterator_traits<TIterator>::difference_type distance_t;
|
||||
|
||||
const distance_t n = last - first;
|
||||
if (n <= 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
value_t value = ETL_MOVE(*(last - 1));
|
||||
*(last - 1) = ETL_MOVE(*first);
|
||||
|
||||
@ -5844,6 +5852,8 @@ namespace etl
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_random_access_iterator<I>::value, "partial_sort requires random access iterators");
|
||||
|
||||
#include "etl/private/diagnostic_array_bounds_push.h"
|
||||
|
||||
I last_it = ranges::next(first, last);
|
||||
|
||||
if (first == middle || first == last_it)
|
||||
@ -5880,6 +5890,8 @@ namespace etl
|
||||
}
|
||||
|
||||
return last_it;
|
||||
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
template <class R, class Comp = ranges::less, class Proj = etl::identity, typename = etl::enable_if_t<etl::is_range_v<R>>>
|
||||
@ -5933,6 +5945,8 @@ namespace etl
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_random_access_iterator<I2>::value, "partial_sort_copy requires the output to be random access iterators");
|
||||
|
||||
#include "etl/private/diagnostic_array_bounds_push.h"
|
||||
|
||||
I1 in_last = ranges::next(first, last);
|
||||
I2 out_last = ranges::next(result_first, result_last);
|
||||
|
||||
@ -5970,7 +5984,6 @@ namespace etl
|
||||
}
|
||||
}
|
||||
|
||||
#include "etl/private/diagnostic_array_bounds_push.h"
|
||||
// Sort the heap to produce a sorted output range
|
||||
for (auto heap_end = heap_size - 1; heap_end > 0; --heap_end)
|
||||
{
|
||||
@ -7025,6 +7038,8 @@ namespace etl
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_random_access_iterator<I>::value, "pop_heap requires random access iterators");
|
||||
|
||||
#include "etl/private/diagnostic_array_bounds_push.h"
|
||||
|
||||
I last_it = ranges::next(first, last);
|
||||
|
||||
auto length = etl::distance(first, last_it);
|
||||
@ -7041,6 +7056,8 @@ namespace etl
|
||||
sift_down(first, decltype(length)(0), etl::distance(first, last_it), comp, proj);
|
||||
|
||||
return ranges::next(first, last);
|
||||
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
template <class R, class Comp = ranges::less, class Proj = etl::identity, typename = etl::enable_if_t<etl::is_range_v<R>>>
|
||||
|
||||
@ -31,6 +31,7 @@ SOFTWARE.
|
||||
#include "binary.h"
|
||||
#include "delegate.h"
|
||||
#include "endianness.h"
|
||||
#include "enum_type.h"
|
||||
#include "error_handler.h"
|
||||
#include "exception.h"
|
||||
#include "integral_limits.h"
|
||||
@ -48,6 +49,26 @@ SOFTWARE.
|
||||
|
||||
namespace etl
|
||||
{
|
||||
//***************************************************************************
|
||||
/// Describes the order in which the bits of a value are written to, or read
|
||||
/// from, a bit stream.
|
||||
/// This is deliberately a distinct type from etl::endian (which describes
|
||||
/// byte order) so that bit order cannot be confused with byte order.
|
||||
//***************************************************************************
|
||||
struct bit_order
|
||||
{
|
||||
enum enum_type
|
||||
{
|
||||
lsb_first, ///< Least significant bit first.
|
||||
msb_first ///< Most significant bit first.
|
||||
};
|
||||
|
||||
ETL_DECLARE_ENUM_TYPE(bit_order, int)
|
||||
ETL_ENUM_TYPE(lsb_first, "lsb_first")
|
||||
ETL_ENUM_TYPE(msb_first, "msb_first")
|
||||
ETL_END_ENUM_TYPE
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
/// Encodes and decodes bitstreams.
|
||||
/// Data must be stored in the stream in network order.
|
||||
@ -349,7 +370,8 @@ namespace etl
|
||||
uint32_t mask = ((1U << mask_width) - 1U) << nbits;
|
||||
// uint32_t mask = ((uint32_t(1U) << mask_width) - 1U) << nbits;
|
||||
|
||||
// Move chunk to lowest char bits.
|
||||
// Normalise the chunk to the low bits (>> nbits), then left-align
|
||||
// it within the bits still free in the current char.
|
||||
// Chunks are never larger than one char.
|
||||
uint32_t chunk = ((value & mask) >> nbits) << (bits_available_in_char - mask_width);
|
||||
|
||||
@ -383,7 +405,8 @@ namespace etl
|
||||
nbits -= mask_width;
|
||||
uint64_t mask = ((uint64_t(1U) << mask_width) - 1U) << nbits;
|
||||
|
||||
// Move chunk to lowest char bits.
|
||||
// Normalise the chunk to the low bits (>> nbits), then left-align
|
||||
// it within the bits still free in the current char.
|
||||
// Chunks are never larger than one char.
|
||||
uint64_t chunk = ((value & mask) >> nbits) << (bits_available_in_char - mask_width);
|
||||
|
||||
@ -535,10 +558,12 @@ namespace etl
|
||||
/// Construct from span.
|
||||
//***************************************************************************
|
||||
template <size_t Length>
|
||||
bit_stream_writer(const etl::span<char, Length>& span_, etl::endian stream_endianness_, callback_type callback_ = callback_type())
|
||||
bit_stream_writer(const etl::span<char, Length>& span_, etl::bit_order bit_order_, callback_type callback_ = callback_type(),
|
||||
etl::endian byte_order_ = etl::endian::big)
|
||||
: pdata(span_.begin())
|
||||
, length_chars(span_.size_bytes())
|
||||
, stream_endianness(stream_endianness_)
|
||||
, bit_order(bit_order_)
|
||||
, byte_order(byte_order_)
|
||||
, callback(callback_)
|
||||
{
|
||||
restart();
|
||||
@ -548,10 +573,12 @@ namespace etl
|
||||
/// Construct from span.
|
||||
//***************************************************************************
|
||||
template <size_t Length>
|
||||
bit_stream_writer(const etl::span<unsigned char, Length>& span_, etl::endian stream_endianness_, callback_type callback_ = callback_type())
|
||||
bit_stream_writer(const etl::span<unsigned char, Length>& span_, etl::bit_order bit_order_, callback_type callback_ = callback_type(),
|
||||
etl::endian byte_order_ = etl::endian::big)
|
||||
: pdata(reinterpret_cast<char*>(span_.begin()))
|
||||
, length_chars(span_.size_bytes())
|
||||
, stream_endianness(stream_endianness_)
|
||||
, bit_order(bit_order_)
|
||||
, byte_order(byte_order_)
|
||||
, callback(callback_)
|
||||
{
|
||||
restart();
|
||||
@ -560,10 +587,12 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Construct from range.
|
||||
//***************************************************************************
|
||||
bit_stream_writer(void* begin_, void* end_, etl::endian stream_endianness_, callback_type callback_ = callback_type())
|
||||
bit_stream_writer(void* begin_, void* end_, etl::bit_order bit_order_, callback_type callback_ = callback_type(),
|
||||
etl::endian byte_order_ = etl::endian::big)
|
||||
: pdata(reinterpret_cast<char*>(begin_))
|
||||
, length_chars(static_cast<size_t>(etl::distance(reinterpret_cast<unsigned char*>(begin_), reinterpret_cast<unsigned char*>(end_))))
|
||||
, stream_endianness(stream_endianness_)
|
||||
, bit_order(bit_order_)
|
||||
, byte_order(byte_order_)
|
||||
, callback(callback_)
|
||||
{
|
||||
restart();
|
||||
@ -572,10 +601,12 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Construct from begin and length.
|
||||
//***************************************************************************
|
||||
bit_stream_writer(void* begin_, size_t length_chars_, etl::endian stream_endianness_, callback_type callback_ = callback_type())
|
||||
bit_stream_writer(void* begin_, size_t length_chars_, etl::bit_order bit_order_, callback_type callback_ = callback_type(),
|
||||
etl::endian byte_order_ = etl::endian::big)
|
||||
: pdata(reinterpret_cast<char*>(begin_))
|
||||
, length_chars(length_chars_)
|
||||
, stream_endianness(stream_endianness_)
|
||||
, bit_order(bit_order_)
|
||||
, byte_order(byte_order_)
|
||||
, callback(callback_)
|
||||
{
|
||||
restart();
|
||||
@ -883,10 +914,17 @@ namespace etl
|
||||
template <typename T>
|
||||
void write_data(T value, uint_least8_t nbits)
|
||||
{
|
||||
// Make sure that we are not writing more bits than should be available.
|
||||
nbits = (nbits > (CHAR_BIT * sizeof(T))) ? (CHAR_BIT * sizeof(T)) : nbits;
|
||||
ETL_ASSERT(nbits <= (CHAR_BIT * sizeof(T)), ETL_ERROR_GENERIC("bit_stream_writer::write_data: nbits too large"));
|
||||
|
||||
if (stream_endianness == etl::endian::little)
|
||||
// Apply the byte order (endianness).
|
||||
// Only meaningful when writing the full width of the type.
|
||||
if ((byte_order == etl::endian::little) && (nbits == (CHAR_BIT * sizeof(T))))
|
||||
{
|
||||
value = etl::reverse_bytes(value);
|
||||
}
|
||||
|
||||
// Apply the bit order.
|
||||
if (bit_order == etl::bit_order::lsb_first)
|
||||
{
|
||||
value = etl::reverse_bits(value);
|
||||
value = value >> ((CHAR_BIT * sizeof(T)) - nbits);
|
||||
@ -899,7 +937,8 @@ namespace etl
|
||||
nbits -= mask_width;
|
||||
T mask = ((T(1U) << mask_width) - 1U) << nbits;
|
||||
|
||||
// Move chunk to lowest char bits.
|
||||
// Normalise the chunk to the low bits (>> nbits), then left-align
|
||||
// it within the bits still free in the current char.
|
||||
// Chunks are never larger than one char.
|
||||
T chunk = ((value & mask) >> nbits) << (bits_available_in_char - mask_width);
|
||||
|
||||
@ -968,15 +1007,16 @@ namespace etl
|
||||
bits_available -= nbits;
|
||||
}
|
||||
|
||||
char* const pdata; ///< The start of the bitstream buffer.
|
||||
const size_t length_chars; ///< The length of the bitstream buffer.
|
||||
const etl::endian stream_endianness; ///< The endianness of the stream data.
|
||||
unsigned char bits_available_in_char; ///< The number of available bits in
|
||||
///< the current char.
|
||||
size_t char_index; ///< The index of the current char in the bitstream buffer.
|
||||
size_t bits_available; ///< The number of bits still available in the
|
||||
///< bitstream buffer.
|
||||
callback_type callback; ///< An optional callback on every filled byte in buffer.
|
||||
char* const pdata; ///< The start of the bitstream buffer.
|
||||
const size_t length_chars; ///< The length of the bitstream buffer.
|
||||
const etl::bit_order bit_order; ///< The bit order of the stream data (MSB or LSB first).
|
||||
const etl::endian byte_order; ///< The byte order (endianness) of the stream data.
|
||||
unsigned char bits_available_in_char; ///< The number of available bits in
|
||||
///< the current char.
|
||||
size_t char_index; ///< The index of the current char in the bitstream buffer.
|
||||
size_t bits_available; ///< The number of bits still available in the
|
||||
///< bitstream buffer.
|
||||
callback_type callback; ///< An optional callback on every filled byte in buffer.
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
@ -1035,10 +1075,11 @@ namespace etl
|
||||
/// Construct from span.
|
||||
//***************************************************************************
|
||||
template <size_t Length>
|
||||
bit_stream_reader(const etl::span<char, Length>& span_, etl::endian stream_endianness_)
|
||||
bit_stream_reader(const etl::span<char, Length>& span_, etl::bit_order bit_order_, etl::endian byte_order_ = etl::endian::big)
|
||||
: pdata(span_.begin())
|
||||
, length_chars(span_.size_bytes())
|
||||
, stream_endianness(stream_endianness_)
|
||||
, bit_order(bit_order_)
|
||||
, byte_order(byte_order_)
|
||||
{
|
||||
restart();
|
||||
}
|
||||
@ -1047,10 +1088,11 @@ namespace etl
|
||||
/// Construct from span.
|
||||
//***************************************************************************
|
||||
template <size_t Length>
|
||||
bit_stream_reader(const etl::span<unsigned char, Length>& span_, etl::endian stream_endianness_)
|
||||
bit_stream_reader(const etl::span<unsigned char, Length>& span_, etl::bit_order bit_order_, etl::endian byte_order_ = etl::endian::big)
|
||||
: pdata(reinterpret_cast<const char*>(span_.begin()))
|
||||
, length_chars(span_.size_bytes())
|
||||
, stream_endianness(stream_endianness_)
|
||||
, bit_order(bit_order_)
|
||||
, byte_order(byte_order_)
|
||||
{
|
||||
restart();
|
||||
}
|
||||
@ -1059,10 +1101,11 @@ namespace etl
|
||||
/// Construct from span.
|
||||
//***************************************************************************
|
||||
template <size_t Length>
|
||||
bit_stream_reader(const etl::span<const char, Length>& span_, etl::endian stream_endianness_)
|
||||
bit_stream_reader(const etl::span<const char, Length>& span_, etl::bit_order bit_order_, etl::endian byte_order_ = etl::endian::big)
|
||||
: pdata(span_.begin())
|
||||
, length_chars(span_.size_bytes())
|
||||
, stream_endianness(stream_endianness_)
|
||||
, bit_order(bit_order_)
|
||||
, byte_order(byte_order_)
|
||||
{
|
||||
restart();
|
||||
}
|
||||
@ -1071,10 +1114,11 @@ namespace etl
|
||||
/// Construct from span.
|
||||
//***************************************************************************
|
||||
template <size_t Length>
|
||||
bit_stream_reader(const etl::span<const unsigned char, Length>& span_, etl::endian stream_endianness_)
|
||||
bit_stream_reader(const etl::span<const unsigned char, Length>& span_, etl::bit_order bit_order_, etl::endian byte_order_ = etl::endian::big)
|
||||
: pdata(reinterpret_cast<const char*>(span_.begin()))
|
||||
, length_chars(span_.size_bytes())
|
||||
, stream_endianness(stream_endianness_)
|
||||
, bit_order(bit_order_)
|
||||
, byte_order(byte_order_)
|
||||
{
|
||||
restart();
|
||||
}
|
||||
@ -1082,10 +1126,11 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Construct from range.
|
||||
//***************************************************************************
|
||||
bit_stream_reader(const void* begin_, const void* end_, etl::endian stream_endianness_)
|
||||
bit_stream_reader(const void* begin_, const void* end_, etl::bit_order bit_order_, etl::endian byte_order_ = etl::endian::big)
|
||||
: pdata(reinterpret_cast<const char*>(begin_))
|
||||
, length_chars(static_cast<size_t>(etl::distance(reinterpret_cast<const char*>(begin_), reinterpret_cast<const char*>(end_))))
|
||||
, stream_endianness(stream_endianness_)
|
||||
, bit_order(bit_order_)
|
||||
, byte_order(byte_order_)
|
||||
{
|
||||
restart();
|
||||
}
|
||||
@ -1093,10 +1138,11 @@ namespace etl
|
||||
//***************************************************************************
|
||||
/// Construct from begin and length.
|
||||
//***************************************************************************
|
||||
bit_stream_reader(const void* begin_, size_t length_, etl::endian stream_endianness_)
|
||||
bit_stream_reader(const void* begin_, size_t length_, etl::bit_order bit_order_, etl::endian byte_order_ = etl::endian::big)
|
||||
: pdata(reinterpret_cast<const char*>(begin_))
|
||||
, length_chars(length_)
|
||||
, stream_endianness(stream_endianness_)
|
||||
, bit_order(bit_order_)
|
||||
, byte_order(byte_order_)
|
||||
{
|
||||
restart();
|
||||
}
|
||||
@ -1259,8 +1305,7 @@ namespace etl
|
||||
template <typename T>
|
||||
T read_value(uint_least8_t nbits, bool is_signed)
|
||||
{
|
||||
// Make sure that we are not reading more bits than should be available.
|
||||
nbits = (nbits > (CHAR_BIT * sizeof(T))) ? (CHAR_BIT * sizeof(T)) : nbits;
|
||||
ETL_ASSERT(nbits <= (CHAR_BIT * sizeof(T)), ETL_ERROR_GENERIC("bit_stream_reader::read_value: nbits too large"));
|
||||
|
||||
T value = 0;
|
||||
uint_least8_t bits = nbits;
|
||||
@ -1276,12 +1321,19 @@ namespace etl
|
||||
value |= static_cast<T>(chunk << nbits);
|
||||
}
|
||||
|
||||
if (stream_endianness == etl::endian::little)
|
||||
if (bit_order == etl::bit_order::lsb_first)
|
||||
{
|
||||
value = value << ((CHAR_BIT * sizeof(T)) - bits);
|
||||
value = etl::reverse_bits(value);
|
||||
}
|
||||
|
||||
// Apply the byte order (endianness).
|
||||
// Only meaningful when reading the full width of the type.
|
||||
if ((byte_order == etl::endian::little) && (bits == (CHAR_BIT * sizeof(T))))
|
||||
{
|
||||
value = etl::reverse_bytes(value);
|
||||
}
|
||||
|
||||
if (is_signed && (bits != (CHAR_BIT * sizeof(T))))
|
||||
{
|
||||
value = etl::sign_extend<T, T>(value, bits);
|
||||
@ -1345,14 +1397,15 @@ namespace etl
|
||||
bits_available -= nbits;
|
||||
}
|
||||
|
||||
const char* pdata; ///< The start of the bitstream buffer.
|
||||
size_t length_chars; ///< The length, in char, of the bitstream buffer.
|
||||
const etl::endian stream_endianness; ///< The endianness of the stream data.
|
||||
unsigned char bits_available_in_char; ///< The number of available bits in
|
||||
///< the current char.
|
||||
size_t char_index; ///< The index of the char in the bitstream buffer.
|
||||
size_t bits_available; ///< The number of bits still available in the
|
||||
///< bitstream buffer.
|
||||
const char* pdata; ///< The start of the bitstream buffer.
|
||||
size_t length_chars; ///< The length, in char, of the bitstream buffer.
|
||||
const etl::bit_order bit_order; ///< The bit order of the stream data (MSB or LSB first).
|
||||
const etl::endian byte_order; ///< The byte order (endianness) of the stream data.
|
||||
unsigned char bits_available_in_char; ///< The number of available bits in
|
||||
///< the current char.
|
||||
size_t char_index; ///< The index of the char in the bitstream buffer.
|
||||
size_t bits_available; ///< The number of bits still available in the
|
||||
///< bitstream buffer.
|
||||
};
|
||||
|
||||
//***************************************************************************
|
||||
|
||||
@ -296,6 +296,7 @@ namespace etl
|
||||
histogram(const histogram& other)
|
||||
{
|
||||
this->accumulator = other.accumulator;
|
||||
start_index = other.start_index;
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
@ -305,6 +306,7 @@ namespace etl
|
||||
histogram(histogram&& other)
|
||||
{
|
||||
this->accumulator = etl::move(other.accumulator);
|
||||
start_index = other.start_index;
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -314,6 +316,7 @@ namespace etl
|
||||
histogram& operator=(const histogram& rhs)
|
||||
{
|
||||
this->accumulator = rhs.accumulator;
|
||||
start_index = rhs.start_index;
|
||||
|
||||
return *this;
|
||||
}
|
||||
@ -325,6 +328,7 @@ namespace etl
|
||||
histogram& operator=(histogram&& rhs)
|
||||
{
|
||||
this->accumulator = etl::move(rhs.accumulator);
|
||||
start_index = rhs.start_index;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -227,11 +227,13 @@ namespace etl
|
||||
return ETL_NULLPTR == base::etl_parent;
|
||||
}
|
||||
|
||||
#include "private/diagnostic_null_dereference_push.h"
|
||||
ETL_NODISCARD
|
||||
link_type* get_parent()
|
||||
{
|
||||
return static_cast<link_type*>(base::etl_parent);
|
||||
}
|
||||
#include "private/diagnostic_pop.h"
|
||||
|
||||
ETL_NODISCARD
|
||||
const link_type* get_parent() const
|
||||
|
||||
@ -115,7 +115,7 @@ namespace etl
|
||||
{
|
||||
ETL_STATIC_ASSERT(Size >= Other_Size, "Other size is too large");
|
||||
|
||||
memcpy(buffer, other.buffer, Size_);
|
||||
memcpy(buffer, other.data(), Other_Size);
|
||||
}
|
||||
|
||||
//***********************************
|
||||
@ -126,7 +126,7 @@ namespace etl
|
||||
{
|
||||
ETL_STATIC_ASSERT(Size >= Other_Size, "RHS size is too large");
|
||||
|
||||
memcpy(buffer, rhs.buffer, Size_);
|
||||
memcpy(buffer, rhs.data(), Other_Size);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
@ -74,6 +74,323 @@ namespace etl
|
||||
return etl::to_address(itr.operator->());
|
||||
}
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP17 && defined(__cpp_lib_launder)
|
||||
using std::launder;
|
||||
#else
|
||||
//*****************************************************************************
|
||||
/// Obtains a pointer to the object created in the storage pointed to by p.
|
||||
/// Prevents the compiler from making invalid assumptions when the lifetime of
|
||||
/// an object has ended and a new object has been created in the same storage.
|
||||
/// T must not be a function type nor a (possibly cv-qualified) void type.
|
||||
/// https://en.cppreference.com/w/cpp/utility/launder
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR17 T* launder(T* p) ETL_NOEXCEPT
|
||||
{
|
||||
#if ETL_USING_CPP11
|
||||
// etl::is_function is only defined for C++11 and later.
|
||||
ETL_STATIC_ASSERT(!etl::is_function<T>::value, "etl::launder argument must not be a function type");
|
||||
#endif
|
||||
ETL_STATIC_ASSERT(!etl::is_void<T>::value, "etl::launder argument must not be a void type");
|
||||
|
||||
#if defined(__has_builtin) && !defined(ETL_COMPILER_MICROSOFT)
|
||||
#if __has_builtin(__builtin_launder)
|
||||
return __builtin_launder(p);
|
||||
#else
|
||||
return p;
|
||||
#endif
|
||||
#elif ETL_USING_GCC_COMPILER && (ETL_COMPILER_FULL_VERSION >= 70000)
|
||||
// GCC 7, 8 and 9 provide __builtin_launder but not __has_builtin.
|
||||
return __builtin_launder(p);
|
||||
#else
|
||||
return p;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP23 && defined(__cpp_lib_start_lifetime_as)
|
||||
using std::start_lifetime_as;
|
||||
using std::start_lifetime_as_array;
|
||||
#else
|
||||
namespace private_memory
|
||||
{
|
||||
//*************************************************************************
|
||||
/// Implicitly create the objects in [p, p + n) and return a usable pointer
|
||||
/// to the first one. Used by start_lifetime_as / start_lifetime_as_array.
|
||||
//*************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
inline T* start_lifetime_as_impl(void* p, size_t n) ETL_NOEXCEPT
|
||||
{
|
||||
if (n == 0U)
|
||||
{
|
||||
// No objects are created, so there is nothing to launder.
|
||||
// Return the original pointer to preserve pointer identity.
|
||||
return static_cast<T*>(p);
|
||||
}
|
||||
|
||||
#if ETL_USING_BUILTIN_MEMMOVE
|
||||
void* const q = __builtin_memmove(p, p, sizeof(T) * n);
|
||||
#else
|
||||
void* const q = ::memmove(p, p, sizeof(T) * n);
|
||||
#endif
|
||||
|
||||
return etl::launder(static_cast<T*>(q));
|
||||
}
|
||||
} // namespace private_memory
|
||||
|
||||
//*****************************************************************************
|
||||
/// Implicitly creates an object of type T in the storage pointed to by p and
|
||||
/// starts its lifetime. T must be a trivially copyable (implicit-lifetime)
|
||||
/// type. The storage must be suitably sized and aligned for T.
|
||||
/// https://en.cppreference.com/w/cpp/memory/start_lifetime_as
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
T* start_lifetime_as(void* p) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<T>(p, 1U);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
const T* start_lifetime_as(const void* p) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<const T>(const_cast<void*>(p), 1U);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
volatile T* start_lifetime_as(volatile void* p) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<volatile T>(const_cast<void*>(p), 1U);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
const volatile T* start_lifetime_as(const volatile void* p) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<const volatile T>(const_cast<void*>(p), 1U);
|
||||
}
|
||||
|
||||
//*****************************************************************************
|
||||
/// Implicitly creates an array of n objects of type T in the storage pointed
|
||||
/// to by p and starts their lifetimes. T must be a trivially copyable
|
||||
/// (implicit-lifetime) type. Returns a pointer to the first element, or a
|
||||
/// pointer comparing equal to p when n is zero.
|
||||
/// https://en.cppreference.com/w/cpp/memory/start_lifetime_as
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
T* start_lifetime_as_array(void* p, size_t n) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<T>(p, n);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
const T* start_lifetime_as_array(const void* p, size_t n) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<const T>(const_cast<void*>(p), n);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
volatile T* start_lifetime_as_array(volatile void* p, size_t n) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<volatile T>(const_cast<void*>(p), n);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
ETL_NODISCARD
|
||||
const volatile T* start_lifetime_as_array(const volatile void* p, size_t n) ETL_NOEXCEPT
|
||||
{
|
||||
ETL_STATIC_ASSERT(etl::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
return etl::private_memory::start_lifetime_as_impl<const volatile T>(const_cast<void*>(p), n);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP11
|
||||
using std::pointer_traits;
|
||||
#else
|
||||
#if ETL_USING_CPP11
|
||||
namespace private_memory
|
||||
{
|
||||
//*************************************************************************
|
||||
/// Decomposes a pointer-like class template of the form
|
||||
/// Pointer<Element, Args...> to recover its first template parameter and
|
||||
/// to rebind it to a different first parameter. Left undefined for types
|
||||
/// that are not such a template instantiation.
|
||||
//*************************************************************************
|
||||
template <typename T>
|
||||
struct pointer_traits_template;
|
||||
|
||||
template <template <typename, typename...> class Pointer, typename Element, typename... Args>
|
||||
struct pointer_traits_template<Pointer<Element, Args...> >
|
||||
{
|
||||
typedef Element type;
|
||||
|
||||
template <typename U>
|
||||
struct rebind
|
||||
{
|
||||
typedef Pointer<U, Args...> type;
|
||||
};
|
||||
};
|
||||
|
||||
//*************************************************************************
|
||||
/// Deduces the element_type of a pointer-like type. Prefers a nested
|
||||
/// T::element_type, otherwise falls back to the first template parameter.
|
||||
//*************************************************************************
|
||||
template <typename T, typename = void>
|
||||
struct pointer_traits_element_type
|
||||
{
|
||||
typedef typename pointer_traits_template<T>::type type;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pointer_traits_element_type<T, etl::void_t<typename T::element_type> >
|
||||
{
|
||||
typedef typename T::element_type type;
|
||||
};
|
||||
} // namespace private_memory
|
||||
#endif
|
||||
|
||||
//*****************************************************************************
|
||||
/// Provides information about pointer-like types. General case where the
|
||||
/// type itself models the pointer (fancy / smart pointers).
|
||||
/// https://en.cppreference.com/w/cpp/memory/pointer_traits
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
struct pointer_traits
|
||||
{
|
||||
typedef T pointer;
|
||||
#if ETL_USING_CPP11
|
||||
typedef typename private_memory::pointer_traits_element_type<T>::type element_type;
|
||||
#else
|
||||
typedef typename T::element_type element_type;
|
||||
#endif
|
||||
typedef ptrdiff_t difference_type;
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
template <typename U>
|
||||
using rebind = typename private_memory::pointer_traits_template<T>::template rebind<U>::type;
|
||||
#endif
|
||||
|
||||
ETL_NODISCARD
|
||||
static ETL_CONSTEXPR pointer pointer_to(element_type& r) ETL_NOEXCEPT
|
||||
{
|
||||
return T::pointer_to(r);
|
||||
}
|
||||
};
|
||||
|
||||
//*****************************************************************************
|
||||
/// Provides information about pointer-like types. Raw pointer specialisation.
|
||||
/// https://en.cppreference.com/w/cpp/memory/pointer_traits
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <typename T>
|
||||
struct pointer_traits<T*>
|
||||
{
|
||||
typedef T* pointer;
|
||||
typedef T element_type;
|
||||
typedef ptrdiff_t difference_type;
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
template <typename U>
|
||||
using rebind = U*;
|
||||
#endif
|
||||
|
||||
ETL_NODISCARD
|
||||
static ETL_CONSTEXPR pointer pointer_to(element_type& r) ETL_NOEXCEPT
|
||||
{
|
||||
return etl::addressof(r);
|
||||
}
|
||||
};
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP11
|
||||
using std::align;
|
||||
#else
|
||||
//*****************************************************************************
|
||||
/// Aligns a pointer within a buffer. Advances 'ptr' to the next address with
|
||||
/// the given 'alignment' that can hold 'size' bytes within 'space' bytes,
|
||||
/// shrinking 'space' by the consumed padding. Returns the aligned pointer, or
|
||||
/// ETL_NULLPTR when the buffer is too small. 'alignment' must be a power of 2;
|
||||
/// the behaviour is undefined if it is not.
|
||||
/// https://en.cppreference.com/w/cpp/memory/align
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
inline void* align(size_t alignment, size_t size, void*& ptr, size_t& space) ETL_NOEXCEPT
|
||||
{
|
||||
const uintptr_t p = reinterpret_cast<uintptr_t>(ptr);
|
||||
const uintptr_t aligned = (p + (alignment - 1U)) & ~(static_cast<uintptr_t>(alignment) - 1U);
|
||||
const size_t padding = static_cast<size_t>(aligned - p);
|
||||
|
||||
if ((padding > space) || (size > (space - padding)))
|
||||
{
|
||||
return ETL_NULLPTR;
|
||||
}
|
||||
|
||||
space -= padding;
|
||||
ptr = reinterpret_cast<void*>(aligned);
|
||||
|
||||
return ptr;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP20 && defined(__cpp_lib_assume_aligned)
|
||||
using std::assume_aligned;
|
||||
#else
|
||||
//*****************************************************************************
|
||||
/// Informs the compiler that the pointer 'ptr' is aligned to at least N bytes
|
||||
/// and returns it. N must be a power of 2. Behaviour is undefined if 'ptr' is
|
||||
/// not actually aligned to N.
|
||||
/// https://en.cppreference.com/w/cpp/memory/assume_aligned
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <size_t N, typename T>
|
||||
ETL_NODISCARD ETL_CONSTEXPR T* assume_aligned(T* ptr) ETL_NOEXCEPT
|
||||
{
|
||||
#if defined(__has_builtin) && !defined(ETL_COMPILER_MICROSOFT)
|
||||
#if __has_builtin(__builtin_assume_aligned)
|
||||
return static_cast<T*>(__builtin_assume_aligned(ptr, N));
|
||||
#else
|
||||
return ptr;
|
||||
#endif
|
||||
#else
|
||||
return ptr;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP26 && defined(__cpp_lib_is_sufficiently_aligned)
|
||||
using std::is_sufficiently_aligned;
|
||||
#else
|
||||
//*****************************************************************************
|
||||
/// Checks whether 'ptr' is aligned to at least Alignment bytes.
|
||||
/// Alignment must be a power of 2.
|
||||
/// https://en.cppreference.com/w/cpp/memory/is_sufficiently_aligned
|
||||
///\ingroup memory
|
||||
//*****************************************************************************
|
||||
template <size_t Alignment, typename T>
|
||||
ETL_NODISCARD
|
||||
bool is_sufficiently_aligned(T* ptr) ETL_NOEXCEPT
|
||||
{
|
||||
return (reinterpret_cast<uintptr_t>(ptr) % Alignment) == 0U;
|
||||
}
|
||||
#endif
|
||||
|
||||
#if ETL_USING_STL
|
||||
//*****************************************************************************
|
||||
/// Fills uninitialised memory range with a value.
|
||||
|
||||
@ -379,7 +379,7 @@ namespace etl
|
||||
if (timer.is_active())
|
||||
{
|
||||
ETL_DISABLE_TIMER_UPDATES;
|
||||
active_list.remove(timer.id, true);
|
||||
active_list.remove(timer.id, false);
|
||||
remove_callback.call_if(timer.id);
|
||||
ETL_ENABLE_TIMER_UPDATES;
|
||||
}
|
||||
|
||||
@ -108,7 +108,7 @@ namespace etl
|
||||
if (timer.is_active())
|
||||
{
|
||||
++process_semaphore;
|
||||
active_list.remove(timer.id, true);
|
||||
active_list.remove(timer.id, false);
|
||||
remove_callback.call_if(timer.id);
|
||||
--process_semaphore;
|
||||
}
|
||||
|
||||
@ -114,7 +114,7 @@ namespace etl
|
||||
TInterruptGuard guard;
|
||||
(void)guard; // Silence 'unused variable warnings.
|
||||
|
||||
active_list.remove(timer.id, true);
|
||||
active_list.remove(timer.id, false);
|
||||
remove_callback.call_if(timer.id);
|
||||
}
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ namespace etl
|
||||
if (timer.is_active())
|
||||
{
|
||||
lock();
|
||||
active_list.remove(timer.id, true);
|
||||
active_list.remove(timer.id, false);
|
||||
remove_callback.call_if(timer.id);
|
||||
unlock();
|
||||
}
|
||||
|
||||
@ -93,6 +93,7 @@ namespace etl
|
||||
void reset()
|
||||
{
|
||||
hash.fill(0);
|
||||
first = true;
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -311,6 +311,11 @@ namespace etl
|
||||
// Build from the string.
|
||||
string_length = etl::min(active_bits, string_length);
|
||||
|
||||
if (string_length == 0U)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
element_type mask = element_type(element_type(1) << (string_length - 1U));
|
||||
|
||||
for (size_t i = 0U; i < string_length; ++i)
|
||||
@ -339,6 +344,11 @@ namespace etl
|
||||
// Build from the string.
|
||||
string_length = etl::min(active_bits, string_length);
|
||||
|
||||
if (string_length == 0U)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
element_type mask = element_type(element_type(1) << (string_length - 1U));
|
||||
|
||||
for (size_t i = 0U; i < string_length; ++i)
|
||||
@ -367,6 +377,11 @@ namespace etl
|
||||
// Build from the string.
|
||||
string_length = etl::min(active_bits, string_length);
|
||||
|
||||
if (string_length == 0U)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
element_type mask = element_type(element_type(1) << (string_length - 1U));
|
||||
|
||||
for (size_t i = 0U; i < string_length; ++i)
|
||||
@ -395,6 +410,11 @@ namespace etl
|
||||
// Build from the string.
|
||||
string_length = etl::min(active_bits, string_length);
|
||||
|
||||
if (string_length == 0U)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
element_type mask = element_type(element_type(1) << (string_length - 1U));
|
||||
|
||||
for (size_t i = 0U; i < string_length; ++i)
|
||||
|
||||
@ -184,5 +184,64 @@ namespace etl
|
||||
|
||||
template <typename TDuration>
|
||||
constexpr int etl::chrono::hh_mm_ss<TDuration>::fractional_width;
|
||||
|
||||
//***********************************************************************
|
||||
/// 12/24 hours functions
|
||||
//***********************************************************************
|
||||
|
||||
//***********************************************************************
|
||||
/// Returns true if h is in the range [0h, 11h] (an am hour).
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14 bool is_am(const etl::chrono::hours& h) ETL_NOEXCEPT
|
||||
{
|
||||
return (h >= etl::chrono::hours(0)) && (h <= etl::chrono::hours(11));
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Returns true if h is in the range [12h, 23h] (a pm hour).
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14 bool is_pm(const etl::chrono::hours& h) ETL_NOEXCEPT
|
||||
{
|
||||
return (h >= etl::chrono::hours(12)) && (h <= etl::chrono::hours(23));
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Returns the 12-hour equivalent of h in the range [1h, 12h].
|
||||
/// If h is not in the range [0h, 23h], the value returned is unspecified.
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14 etl::chrono::hours make12(const etl::chrono::hours& h) ETL_NOEXCEPT
|
||||
{
|
||||
if (h == etl::chrono::hours(0))
|
||||
{
|
||||
return etl::chrono::hours(12);
|
||||
}
|
||||
else if (h > etl::chrono::hours(12))
|
||||
{
|
||||
return h - etl::chrono::hours(12);
|
||||
}
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
//***********************************************************************
|
||||
/// Returns the 24-hour equivalent of h, which is assumed to represent the
|
||||
/// hour with the indicated am/pm.
|
||||
/// If h is not in the range [1h, 12h], the value returned is unspecified.
|
||||
//***********************************************************************
|
||||
ETL_NODISCARD
|
||||
inline ETL_CONSTEXPR14 etl::chrono::hours make24(const etl::chrono::hours& h, bool is_pm) ETL_NOEXCEPT
|
||||
{
|
||||
if (is_pm)
|
||||
{
|
||||
return (h == etl::chrono::hours(12)) ? h : (h + etl::chrono::hours(12));
|
||||
}
|
||||
else
|
||||
{
|
||||
return (h == etl::chrono::hours(12)) ? etl::chrono::hours(0) : h;
|
||||
}
|
||||
}
|
||||
} // namespace chrono
|
||||
} // namespace etl
|
||||
|
||||
@ -122,6 +122,48 @@ namespace etl
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Pre-increments the stored duration by one tick.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 time_point& operator++() ETL_NOEXCEPT
|
||||
{
|
||||
++dur;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Post-increments the stored duration by one tick.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 time_point operator++(int) ETL_NOEXCEPT
|
||||
{
|
||||
time_point temp(*this);
|
||||
++dur;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Pre-decrements the stored duration by one tick.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 time_point& operator--() ETL_NOEXCEPT
|
||||
{
|
||||
--dur;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Post-decrements the stored duration by one tick.
|
||||
//***************************************************************************
|
||||
ETL_CONSTEXPR14 time_point operator--(int) ETL_NOEXCEPT
|
||||
{
|
||||
time_point temp(*this);
|
||||
--dur;
|
||||
|
||||
return temp;
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Returns a time_point with the smallest possible duration.
|
||||
//***************************************************************************
|
||||
@ -200,6 +242,59 @@ namespace etl
|
||||
return etl::chrono::time_point<TClock, TToDuration>(dur);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Adds a duration to a time_point.
|
||||
/// Returns a time_point whose duration is the common type of the two.
|
||||
//***************************************************************************
|
||||
template <typename TClock, typename TDuration1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14 etl::chrono::time_point<TClock, typename etl::common_type<TDuration1, etl::chrono::duration<TRep2, TPeriod2> >::type>
|
||||
operator+(const time_point<TClock, TDuration1>& lhs, const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
using common_duration = typename etl::common_type<TDuration1, etl::chrono::duration<TRep2, TPeriod2> >::type;
|
||||
using result_time_point = etl::chrono::time_point<TClock, common_duration>;
|
||||
|
||||
return result_time_point(lhs.time_since_epoch() + rhs);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Adds a time_point to a duration.
|
||||
/// Returns a time_point whose duration is the common type of the two.
|
||||
//***************************************************************************
|
||||
template <typename TRep1, typename TPeriod1, typename TClock, typename TDuration2>
|
||||
ETL_CONSTEXPR14 etl::chrono::time_point<TClock, typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, TDuration2>::type>
|
||||
operator+(const etl::chrono::duration<TRep1, TPeriod1>& lhs, const time_point<TClock, TDuration2>& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
using common_duration = typename etl::common_type<etl::chrono::duration<TRep1, TPeriod1>, TDuration2>::type;
|
||||
using result_time_point = etl::chrono::time_point<TClock, common_duration>;
|
||||
|
||||
return result_time_point(lhs + rhs.time_since_epoch());
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Subtracts a duration from a time_point.
|
||||
/// Returns a time_point whose duration is the common type of the two.
|
||||
//***************************************************************************
|
||||
template <typename TClock, typename TDuration1, typename TRep2, typename TPeriod2>
|
||||
ETL_CONSTEXPR14 etl::chrono::time_point<TClock, typename etl::common_type<TDuration1, etl::chrono::duration<TRep2, TPeriod2> >::type>
|
||||
operator-(const time_point<TClock, TDuration1>& lhs, const etl::chrono::duration<TRep2, TPeriod2>& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
using common_duration = typename etl::common_type<TDuration1, etl::chrono::duration<TRep2, TPeriod2> >::type;
|
||||
using result_time_point = etl::chrono::time_point<TClock, common_duration>;
|
||||
|
||||
return result_time_point(lhs.time_since_epoch() - rhs);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Subtracts one time_point from another.
|
||||
/// Returns the duration between them as the common type of the two durations.
|
||||
//***************************************************************************
|
||||
template <typename TClock, typename TDuration1, typename TDuration2>
|
||||
ETL_CONSTEXPR14 typename etl::common_type<TDuration1, TDuration2>::type operator-(const time_point<TClock, TDuration1>& lhs,
|
||||
const time_point<TClock, TDuration2>& rhs) ETL_NOEXCEPT
|
||||
{
|
||||
return lhs.time_since_epoch() - rhs.time_since_epoch();
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Equality operator
|
||||
//***************************************************************************
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -715,7 +715,7 @@ namespace etl
|
||||
using type = etl::remove_cvref_t<T>;
|
||||
|
||||
do_destroy();
|
||||
do_construct<type>(type(etl::forward<TArgs>(args)...));
|
||||
do_emplace<type>(etl::forward<TArgs>(args)...);
|
||||
|
||||
type_id = index_of_type<T>::value;
|
||||
|
||||
@ -735,7 +735,7 @@ namespace etl
|
||||
using type = etl::remove_cvref_t<T>;
|
||||
|
||||
do_destroy();
|
||||
do_construct<type>(type(il, etl::forward<TArgs>(args)...));
|
||||
do_emplace<type>(il, etl::forward<TArgs>(args)...);
|
||||
|
||||
type_id = index_of_type<T>::value;
|
||||
|
||||
@ -755,7 +755,7 @@ namespace etl
|
||||
using type = type_from_index<Index>;
|
||||
|
||||
do_destroy();
|
||||
do_construct<type>(type(etl::forward<TArgs>(args)...));
|
||||
do_emplace<type>(etl::forward<TArgs>(args)...);
|
||||
|
||||
type_id = Index;
|
||||
|
||||
@ -775,7 +775,7 @@ namespace etl
|
||||
using type = type_from_index<Index>;
|
||||
|
||||
do_destroy();
|
||||
do_construct<type>(type(il, etl::forward<TArgs>(args)...));
|
||||
do_emplace<type>(il, etl::forward<TArgs>(args)...);
|
||||
|
||||
type_id = Index;
|
||||
|
||||
@ -1096,6 +1096,32 @@ namespace etl
|
||||
private_variant::variant_operations<0, TTypes...>::destroy(data, type_id);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Emplace-construct the alternative in place from forwarded args.
|
||||
/// No temporary, so no move/copy is required (works for move-hostile types).
|
||||
//***************************************************************************
|
||||
template <typename T, typename... TArgs>
|
||||
void do_emplace(TArgs&&... args)
|
||||
{
|
||||
do_emplace_impl<T>(etl::integral_constant<bool, Is_Trivially_Destructible_Suite>{}, etl::forward<TArgs>(args)...);
|
||||
}
|
||||
|
||||
// Trivially destructible suite: storage is a variadic_union. The old member is
|
||||
// trivially destructible, so placement-new of the new member is well-defined at
|
||||
// runtime (emplace is not constexpr, so placement-new is permitted here).
|
||||
template <typename T, typename... TArgs>
|
||||
void do_emplace_impl(etl::integral_constant<bool, true>, TArgs&&... args)
|
||||
{
|
||||
::new (static_cast<void*>(etl::addressof(private_variant::variadic_union_get<index_of_type<T>::value>(data)))) T(etl::forward<TArgs>(args)...);
|
||||
}
|
||||
|
||||
// Non-trivially destructible suite: storage is an uninitialized_buffer.
|
||||
template <typename T, typename... TArgs>
|
||||
void do_emplace_impl(etl::integral_constant<bool, false>, TArgs&&... args)
|
||||
{
|
||||
::new (static_cast<char*>(data)) T(etl::forward<TArgs>(args)...);
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Construct a value in the union or buffer storage.
|
||||
//***************************************************************************
|
||||
@ -1108,8 +1134,12 @@ namespace etl
|
||||
template <typename T, typename U>
|
||||
void do_construct_impl(U&& value, etl::integral_constant<bool, true>)
|
||||
{
|
||||
// Trivially destructible: assign directly into the variadic_union.
|
||||
private_variant::variadic_union_get<index_of_type<T>::value>(data) = etl::forward<U>(value);
|
||||
// Begin the lifetime of the new alternative via placement new. The target
|
||||
// union member is not alive after do_destroy(), and the alternative may be
|
||||
// non-assignable (e.g. reference or const members), so assignment would be
|
||||
// both undefined behaviour and ill-formed for such types. Use etl::addressof
|
||||
// so the raw storage address is used even for types that overload operator&.
|
||||
::new (static_cast<void*>(etl::addressof(private_variant::variadic_union_get<index_of_type<T>::value>(data)))) T(etl::forward<U>(value));
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
|
||||
@ -167,6 +167,15 @@ SOFTWARE.
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(ETL_COMPILER_MICROSOFT) // The Microsoft compiler supports the __is_trivially_copyable
|
||||
// intrinsic directly. __has_builtin is not used for Microsoft
|
||||
// (see above) to avoid a VS2022 intellisense issue, so the
|
||||
// intrinsic is enabled here for the no-STL configuration.
|
||||
#if !defined(ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE)
|
||||
#define ETL_USING_BUILTIN_IS_TRIVIALLY_COPYABLE 1
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// The default. Set to 0, if not already set.
|
||||
#if !defined(ETL_USING_BUILTIN_IS_ASSIGNABLE)
|
||||
#define ETL_USING_BUILTIN_IS_ASSIGNABLE 0
|
||||
|
||||
@ -1491,14 +1491,14 @@ namespace etl
|
||||
span(const etl::array<T, Size>&) -> span<const T, Size>;
|
||||
|
||||
// Forward declaration of etl::ivector
|
||||
template <typename T>
|
||||
template <typename T, typename Enable>
|
||||
class ivector;
|
||||
|
||||
template <typename T>
|
||||
span(etl::ivector<T>&) -> span<T>;
|
||||
template <typename T, typename Enable>
|
||||
span(etl::ivector<T, Enable>&) -> span<T>;
|
||||
|
||||
template <typename T>
|
||||
span(const etl::ivector<T>&) -> span<const T>;
|
||||
template <typename T, typename Enable>
|
||||
span(const etl::ivector<T, Enable>&) -> span<const T>;
|
||||
|
||||
#if ETL_USING_STL && ETL_USING_CPP11
|
||||
template <typename T, size_t Size>
|
||||
|
||||
@ -1144,8 +1144,8 @@ namespace etl
|
||||
inline constexpr bool is_class_v = is_class<T>::value;
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// is_base_of
|
||||
//***************************************************************************
|
||||
/// is_base_of
|
||||
#if ETL_USING_CPP11
|
||||
namespace private_type_traits
|
||||
{
|
||||
@ -1358,9 +1358,9 @@ namespace etl
|
||||
};
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// is_convertible
|
||||
///\ingroup type_traits
|
||||
//***************************************************************************
|
||||
/// is_convertible
|
||||
///\ingroup type_traits
|
||||
#if ETL_USING_CPP11
|
||||
namespace private_type_traits
|
||||
{
|
||||
@ -2149,9 +2149,9 @@ namespace etl
|
||||
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// is_convertible
|
||||
///\ingroup type_traits
|
||||
//***************************************************************************
|
||||
/// is_convertible
|
||||
///\ingroup type_traits
|
||||
#if ETL_USING_CPP11
|
||||
template <typename TFrom, typename TTo>
|
||||
struct is_convertible : std::is_convertible<TFrom, TTo>
|
||||
@ -3909,6 +3909,32 @@ namespace etl
|
||||
#endif
|
||||
}
|
||||
|
||||
//***************************************************************************
|
||||
/// Is T a member pointer
|
||||
//***************************************************************************
|
||||
namespace private_type_traits
|
||||
{
|
||||
template <typename T>
|
||||
struct is_member_pointer_helper : etl::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T, typename TObject>
|
||||
struct is_member_pointer_helper<T TObject::*> : etl::true_type
|
||||
{
|
||||
};
|
||||
} // namespace private_type_traits
|
||||
|
||||
template <typename T>
|
||||
struct is_member_pointer : private_type_traits::is_member_pointer_helper< typename etl::remove_cv<T>::type>
|
||||
{
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
template <typename T>
|
||||
inline constexpr bool is_member_pointer_v = etl::is_member_pointer<T>::value;
|
||||
#endif
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//*********************************
|
||||
/// Check if T is a function type
|
||||
@ -4008,6 +4034,15 @@ namespace etl
|
||||
inline constexpr bool is_function_v = etl::is_function<T>::value;
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
template <typename T>
|
||||
struct is_function : etl::bool_constant<!etl::is_member_pointer<T>::value && !etl::is_const<const T>::value && !etl::is_reference<T>::value>
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// is_object
|
||||
//***************************************************************************
|
||||
@ -4016,10 +4051,22 @@ namespace etl
|
||||
{
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
#if ETL_USING_CPP17
|
||||
template <typename T>
|
||||
inline constexpr bool is_object_v = etl::is_object<T>::value;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// is_object_pointer
|
||||
//***************************************************************************
|
||||
template <typename T>
|
||||
struct is_object_pointer : etl::bool_constant<etl::is_pointer<T>::value && etl::is_object<typename etl::remove_pointer<T>::type>::value>
|
||||
{
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
template <typename T>
|
||||
inline constexpr bool is_object_pointer_v = etl::is_object_pointer<T>::value;
|
||||
#endif
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
@ -4075,32 +4122,6 @@ namespace etl
|
||||
#endif
|
||||
#endif
|
||||
|
||||
//***************************************************************************
|
||||
/// Is T a member pointer
|
||||
//***************************************************************************
|
||||
namespace private_type_traits
|
||||
{
|
||||
template <typename T>
|
||||
struct is_member_pointer_helper : etl::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <typename T, typename TObject>
|
||||
struct is_member_pointer_helper<T TObject::*> : etl::true_type
|
||||
{
|
||||
};
|
||||
} // namespace private_type_traits
|
||||
|
||||
template <typename T>
|
||||
struct is_member_pointer : private_type_traits::is_member_pointer_helper< typename etl::remove_cv<T>::type>
|
||||
{
|
||||
};
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
template <typename T>
|
||||
inline constexpr bool is_member_pointer_v = etl::is_member_pointer<T>::value;
|
||||
#endif
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//***************************************************************************
|
||||
/// Is T a member function pointer
|
||||
|
||||
@ -490,6 +490,7 @@ namespace etl
|
||||
};
|
||||
|
||||
#if ETL_NOT_USING_STL || ETL_CPP14_NOT_SUPPORTED
|
||||
#if ETL_CPP11_NOT_SUPPORTED
|
||||
//***************************************************************************
|
||||
/// exchange (const)
|
||||
//***************************************************************************
|
||||
@ -500,7 +501,6 @@ namespace etl
|
||||
object = new_value;
|
||||
return old_value;
|
||||
}
|
||||
|
||||
template <typename T, typename U>
|
||||
T exchange(T& object, const U& new_value)
|
||||
{
|
||||
@ -508,16 +508,30 @@ namespace etl
|
||||
object = new_value;
|
||||
return old_value;
|
||||
}
|
||||
#else
|
||||
#else
|
||||
//***************************************************************************
|
||||
/// exchange (const)
|
||||
/// exchange
|
||||
//***************************************************************************
|
||||
template <typename T, typename U = T>
|
||||
T exchange(T& object, const U& new_value)
|
||||
ETL_CONSTEXPR14 T exchange(T& object, U&& new_value)
|
||||
ETL_NOEXCEPT_IF((etl::is_nothrow_move_constructible<T>::value && etl::is_nothrow_assignable<T&, U>::value))
|
||||
{
|
||||
return std::exchange(object, new_value);
|
||||
T old_value = etl::move(object);
|
||||
object = etl::forward<U>(new_value);
|
||||
return old_value;
|
||||
}
|
||||
#endif
|
||||
#endif // ETL_CPP11_NOT_SUPPORTED
|
||||
#else
|
||||
//***************************************************************************
|
||||
/// exchange
|
||||
//***************************************************************************
|
||||
template <typename T, typename U = T>
|
||||
ETL_CONSTEXPR14 T exchange(T& object, U&& new_value)
|
||||
ETL_NOEXCEPT_IF((etl::is_nothrow_move_constructible<T>::value && etl::is_nothrow_assignable<T&, U>::value))
|
||||
{
|
||||
return std::exchange(object, etl::forward<U>(new_value));
|
||||
}
|
||||
#endif // ETL_NOT_USING_STL || ETL_CPP14_NOT_SUPPORTED
|
||||
|
||||
//***************************************************************************
|
||||
/// as_const
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -40,7 +40,7 @@ SOFTWARE.
|
||||
|
||||
#define ETL_VERSION_MAJOR 20
|
||||
#define ETL_VERSION_MINOR 48
|
||||
#define ETL_VERSION_PATCH 0
|
||||
#define ETL_VERSION_PATCH 1
|
||||
|
||||
#define ETL_VERSION \
|
||||
ETL_STRING(ETL_VERSION_MAJOR) \
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "Embedded Template Library",
|
||||
"version": "20.48.0",
|
||||
"version": "20.48.1",
|
||||
"authors": {
|
||||
"name": "John Wellbelove",
|
||||
"email": "john.wellbelove@etlcpp.com"
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
name=Embedded Template Library
|
||||
version=20.48.0
|
||||
version=20.48.1
|
||||
author= John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
maintainer=John Wellbelove <john.wellbelove@etlcpp.com>
|
||||
license=MIT
|
||||
|
||||
@ -1,4 +1,21 @@
|
||||
===============================================================================
|
||||
20.48.1
|
||||
|
||||
#1477 Fix for 1405: etl::exchange doesn't work with unique_ptr
|
||||
#1484 Fix etl::message_timer firing following timers early on unregister
|
||||
#1485 Fix etl::histogram copy/move not preserving start_index
|
||||
#1486 Fix etl::bitset single-element from_string shift on empty string
|
||||
#1487 Fix etl::pearson::reset() not resetting the first-byte flag
|
||||
#1488 Fix etl::mem_cast cross-size copy constructor and assignment
|
||||
#1489 Add missing interfaces to etl::chrono
|
||||
#1490 Add missing memory functions, according the standard
|
||||
#1491 Add optional etl_profile label_flag for Bazel profile injection
|
||||
#1492 Allow etl::vector to store pointers to functions and member functions
|
||||
#1494 Refactor variant::emplace to perfect forward args instead of copy/move construct
|
||||
#1495 Separate bit order and endianness in bit_stream.h
|
||||
#1496 Fix non-assignable alternatives in variant
|
||||
|
||||
===============================================================================
|
||||
20.48.0
|
||||
|
||||
#1375 Support for C++26
|
||||
|
||||
@ -14,6 +14,7 @@ add_executable(etl_tests
|
||||
main.cpp
|
||||
murmurhash3.cpp
|
||||
test_algorithm.cpp
|
||||
test_algorithm_ranges.cpp
|
||||
test_alignment.cpp
|
||||
test_array.cpp
|
||||
test_array_view.cpp
|
||||
@ -374,6 +375,10 @@ add_executable(etl_tests
|
||||
test_vector_non_trivial.cpp
|
||||
test_vector_pointer.cpp
|
||||
test_vector_pointer_external_buffer.cpp
|
||||
test_vector_function_pointer.cpp
|
||||
test_vector_function_pointer_external_buffer.cpp
|
||||
test_vector_member_function_pointer.cpp
|
||||
test_vector_member_function_pointer_external_buffer.cpp
|
||||
test_visitor.cpp
|
||||
test_xor_checksum.cpp
|
||||
test_xor_rotate_checksum.cpp
|
||||
|
||||
@ -2,6 +2,7 @@ etl_test_sources = files(
|
||||
'main.cpp',
|
||||
'murmurhash3.cpp',
|
||||
'test_algorithm.cpp',
|
||||
'test_algorithm_ranges.cpp',
|
||||
'test_alignment.cpp',
|
||||
'test_array.cpp',
|
||||
'test_array_view.cpp',
|
||||
@ -362,6 +363,10 @@ etl_test_sources = files(
|
||||
'test_vector_non_trivial.cpp',
|
||||
'test_vector_pointer.cpp',
|
||||
'test_vector_pointer_external_buffer.cpp',
|
||||
'test_vector_function_pointer.cpp',
|
||||
'test_vector_function_pointer_external_buffer.cpp',
|
||||
'test_vector_member_function_pointer.cpp',
|
||||
'test_vector_member_function_pointer_external_buffer.cpp',
|
||||
'test_visitor.cpp',
|
||||
'test_xor_checksum.cpp',
|
||||
'test_xor_rotate_checksum.cpp'
|
||||
|
||||
12709
test/test_algorithm.cpp
12709
test/test_algorithm.cpp
File diff suppressed because it is too large
Load Diff
12763
test/test_algorithm_ranges.cpp
Normal file
12763
test/test_algorithm_ranges.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -99,7 +99,7 @@ namespace
|
||||
{
|
||||
char storage = 0x5AU;
|
||||
|
||||
etl::bit_stream_reader bit_stream(&storage, 1, etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(&storage, 1, etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(1U, bit_stream.size_bytes());
|
||||
|
||||
@ -154,7 +154,7 @@ namespace
|
||||
{
|
||||
char storage = 0x5AU;
|
||||
|
||||
etl::bit_stream_reader bit_stream(&storage, 1, etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(&storage, 1, etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(1U, bit_stream.size_bytes());
|
||||
|
||||
@ -210,7 +210,7 @@ namespace
|
||||
std::array<char, 4U> storage = {char(0x01), char(0x5A), char(0xA5), char(0xFF)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -246,7 +246,7 @@ namespace
|
||||
std::array<char, 4U> storage = {char(0x01), char(0x5A), char(0xA5), char(0xFF)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -282,7 +282,7 @@ namespace
|
||||
std::array<char, 4U> storage = {char(0x01), char(0x5A), char(0xA5), char(0xFF)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -307,7 +307,7 @@ namespace
|
||||
std::array<char, 3U> storage = {char(0x0E), char(0x8B), char(0xF0)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0xFA), int8_t(0x05), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -343,7 +343,7 @@ namespace
|
||||
std::array<char, 3U> storage = {char(0x0E), char(0x8B), char(0xF0)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0xFA), int8_t(0x05), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -377,7 +377,7 @@ namespace
|
||||
std::array<char, 3U> storage = {char(0x0E), char(0x8B), char(0xF0)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0xFA), int8_t(0x05), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -413,7 +413,7 @@ namespace
|
||||
std::array<char, 3U> storage = {char(0x0E), char(0x8B), char(0xF0)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0xFA), int8_t(0x05), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -438,7 +438,7 @@ namespace
|
||||
std::array<char, 4U> storage = {char(0x01), char(0x5A), char(0xA5), char(0xFF)};
|
||||
std::array<uint8_t, 4U> expected = {uint8_t(0x01), uint8_t(0x5A), uint8_t(0xA5), uint8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -474,7 +474,7 @@ namespace
|
||||
std::array<char, 3U> storage = {char(0x0E), char(0x8B), char(0xF0)};
|
||||
std::array<char, 4U> expected = {uint8_t(0x01), uint8_t(0x1A), uint8_t(0x05), uint8_t(0x1F)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -510,7 +510,7 @@ namespace
|
||||
std::array<char, 8U> storage = {char(0x00), char(0x01), char(0xA5), char(0x5A), char(0x5A), char(0xA5), char(0xFF), char(0xFF)};
|
||||
std::array<int16_t, 4U> expected = {int16_t(0x0001), int16_t(0xA55A), int16_t(0x5AA5), int16_t(0xFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -546,7 +546,7 @@ namespace
|
||||
std::array<char, 5U> storage = {char(0x00), char(0x55), char(0xAA), char(0x97), char(0xFF)};
|
||||
std::array<int16_t, 4U> expected = {int16_t(0x0001), int16_t(0x015A), int16_t(0xFEA5), int16_t(0xFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -582,7 +582,7 @@ namespace
|
||||
std::array<char, 8U> storage = {char(0x00), char(0x01), char(0xA5), char(0x5A), char(0x5A), char(0xA5), char(0xFF), char(0xFF)};
|
||||
std::array<uint16_t, 4U> expected = {uint16_t(0x0001), uint16_t(0xA55A), uint16_t(0x5AA5), uint16_t(0xFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -618,7 +618,7 @@ namespace
|
||||
std::array<char, 5U> storage = {char(0x00), char(0x55), char(0xAA), char(0x97), char(0xFF)};
|
||||
std::array<uint16_t, 4U> expected = {uint16_t(0x0001), uint16_t(0x015A), uint16_t(0x02A5), uint16_t(0x03FF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -655,7 +655,7 @@ namespace
|
||||
char(0x5A), char(0xA5), char(0x5A), char(0xA5), char(0xFF), char(0xFF), char(0xFF), char(0xFF)};
|
||||
std::array<int32_t, 4U> expected = {int32_t(0x00000001), int32_t(0xA55AA55A), int32_t(0x5AA55AA5), int32_t(0xFFFFFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -692,7 +692,7 @@ namespace
|
||||
char(0x56), char(0xA9), char(0x7F), char(0xFF), char(0xFF)};
|
||||
std::array<int32_t, 4U> expected = {int32_t(0x00000001), int32_t(0x001AA55A), int32_t(0xFFE55AA5), int32_t(0xFFFFFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -729,7 +729,7 @@ namespace
|
||||
char(0x5A), char(0xA5), char(0x5A), char(0xA5), char(0xFF), char(0xFF), char(0xFF), char(0xFF)};
|
||||
std::array<uint32_t, 4U> expected = {uint32_t(0x00000001), uint32_t(0xA55AA55A), uint32_t(0x5AA55AA5), uint32_t(0xFFFFFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -766,7 +766,7 @@ namespace
|
||||
char(0x56), char(0xA9), char(0x7F), char(0xFF), char(0xFF)};
|
||||
std::array<uint32_t, 4U> expected = {uint32_t(0x00000001), uint32_t(0x001AA55A), uint32_t(0x00255AA5), uint32_t(0x003FFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -806,7 +806,7 @@ namespace
|
||||
std::array<int64_t, 4U> expected = {int64_t(0x0000000000000001), int64_t(0xA55AA55AA55AA55A), int64_t(0x5AA55AA55AA55AA5),
|
||||
int64_t(0xFFFFFFFFFFFFFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -845,7 +845,7 @@ namespace
|
||||
std::array<int64_t, 4U> expected = {int64_t(0x0000000000000001), int64_t(0x0000255AA55AA55A), int64_t(0xFFFFDAA55AA55AA5),
|
||||
int64_t(0xFFFFFFFFFFFFFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -885,7 +885,7 @@ namespace
|
||||
std::array<uint64_t, 4U> expected = {uint64_t(0x0000000000000001), uint64_t(0xA55AA55AA55AA55A), uint64_t(0x5AA55AA55AA55AA5),
|
||||
uint64_t(0xFFFFFFFFFFFFFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -924,7 +924,7 @@ namespace
|
||||
std::array<uint64_t, 4U> expected = {uint64_t(0x0000000000000001), uint64_t(0x0000255AA55AA55A), uint64_t(0x00005AA55AA55AA5),
|
||||
uint64_t(0x00007FFFFFFFFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -967,7 +967,7 @@ namespace
|
||||
std::array<char, 14U> storage = {char(0x5A), char(0x12), char(0x34), char(0x89), char(0xAB), char(0xCD), char(0xEF),
|
||||
char(0xFE), char(0xDC), char(0xBA), char(0x98), char(0x56), char(0x78), char(0xA5)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1009,7 +1009,7 @@ namespace
|
||||
std::array<char, 11U> storage = {char(0x6A), char(0x46), char(0x8A), char(0xF3), char(0x7B), char(0xDB),
|
||||
char(0x97), char(0x53), char(0x19), char(0xE1), char(0x28)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1053,7 +1053,7 @@ namespace
|
||||
|
||||
auto storage_span = etl::span<char, etl::dynamic_extent>(storage.data(), storage.size());
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1098,7 +1098,7 @@ namespace
|
||||
|
||||
auto storage_span = etl::span<unsigned char, etl::dynamic_extent>(storage.data(), storage.size());
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1142,7 +1142,7 @@ namespace
|
||||
|
||||
auto storage_span = etl::span<char, 11U>(storage.data(), storage.size());
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1187,7 +1187,7 @@ namespace
|
||||
|
||||
auto storage_span = etl::span<unsigned char, 11U>(storage.data(), storage.size());
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1231,7 +1231,7 @@ namespace
|
||||
|
||||
auto storage_span = etl::span<const char, etl::dynamic_extent>(storage.data(), storage.size());
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1276,7 +1276,7 @@ namespace
|
||||
|
||||
auto storage_span = etl::span<const unsigned char, etl::dynamic_extent>(storage.data(), storage.size());
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1320,7 +1320,7 @@ namespace
|
||||
|
||||
auto storage_span = etl::span<const char, 11U>(storage.data(), storage.size());
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1365,7 +1365,7 @@ namespace
|
||||
|
||||
auto storage_span = etl::span<const unsigned char, 11U>(storage.data(), storage.size());
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage_span, etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1407,7 +1407,7 @@ namespace
|
||||
std::array<char, 11U> storage = {char(0x6A), char(0x46), char(0x8A), char(0xF3), char(0x7B), char(0xDB),
|
||||
char(0x97), char(0x53), char(0x19), char(0xE1), char(0x28)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1442,7 +1442,7 @@ namespace
|
||||
std::array<char, 12U> storage = {char(0xEC), char(0xBA), char(0xDE), char(0x68), char(0xAF), char(0xD2),
|
||||
char(0xC5), char(0xC8), char(0x65), char(0xD3), char(0xDF), char(0x80)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1470,7 +1470,7 @@ namespace
|
||||
std::array<char, 12U> storage = {char(0xEC), char(0xBA), char(0xDE), char(0x68), char(0xAF), char(0xD2),
|
||||
char(0xC5), char(0xC8), char(0x65), char(0xD3), char(0xDF), char(0x80)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
|
||||
@ -100,7 +100,7 @@ namespace
|
||||
{
|
||||
char storage = 0x5AU;
|
||||
|
||||
etl::bit_stream_reader bit_stream(&storage, 1, etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(&storage, 1, etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(1U, bit_stream.size_bytes());
|
||||
|
||||
@ -157,7 +157,7 @@ namespace
|
||||
{
|
||||
char storage = 0x5AU;
|
||||
|
||||
etl::bit_stream_reader bit_stream(&storage, 1, etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(&storage, 1, etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(1U, bit_stream.size_bytes());
|
||||
|
||||
@ -215,7 +215,7 @@ namespace
|
||||
std::array<char, 4U> storage = {char(0x80), char(0x5A), char(0xA5), char(0xFF)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -253,7 +253,7 @@ namespace
|
||||
std::array<char, 4U> storage = {char(0x80), char(0x5A), char(0xA5), char(0xFF)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -291,7 +291,7 @@ namespace
|
||||
std::array<char, 4U> storage = {char(0x80), char(0x5A), char(0xA5), char(0xFF)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0x5A), int8_t(0xA5), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -313,7 +313,7 @@ namespace
|
||||
std::array<char, 3U> storage = {char(0x85), char(0x69), char(0xF0)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0xF5), int8_t(0x05), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -351,7 +351,7 @@ namespace
|
||||
std::array<char, 3U> storage = {char(0x85), char(0x69), char(0xF0)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0xF5), int8_t(0x05), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -389,7 +389,7 @@ namespace
|
||||
std::array<char, 4U> storage = {char(0x85), char(0x69), char(0xF0)};
|
||||
std::array<int8_t, 4U> expected = {int8_t(0x01), int8_t(0xF5), int8_t(0x05), int8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -414,7 +414,7 @@ namespace
|
||||
std::array<char, 4U> storage = {char(0x80), char(0x5A), char(0xA5), char(0xFF)};
|
||||
std::array<uint8_t, 4U> expected = {uint8_t(0x01), uint8_t(0x5A), uint8_t(0xA5), uint8_t(0xFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -452,7 +452,7 @@ namespace
|
||||
std::array<char, 3U> storage = {char(0x85), char(0x69), char(0xF0)};
|
||||
std::array<int8_t, 4U> expected = {uint8_t(0x01), uint8_t(0x15), uint8_t(0x05), uint8_t(0x1F)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -490,7 +490,7 @@ namespace
|
||||
std::array<char, 3U> storage = {char(0x85), char(0x69), char(0xF0)};
|
||||
std::array<int8_t, 4U> expected = {uint8_t(0x01), uint8_t(0x15), uint8_t(0x05), uint8_t(0x1F)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -526,7 +526,7 @@ namespace
|
||||
std::array<char, 8U> storage = {char(0x80), char(0x00), char(0xA5), char(0x5A), char(0x5A), char(0xA5), char(0xFF), char(0xFF)};
|
||||
std::array<int16_t, 4U> expected = {int16_t(0x0001), int16_t(0x5AA5), int16_t(0xA55A), int16_t(0xFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -564,7 +564,7 @@ namespace
|
||||
std::array<char, 5U> storage = {char(0x80), char(0x16), char(0xAA), char(0x57), char(0xFF)};
|
||||
std::array<int16_t, 4U> expected = {int16_t(0x0001), int16_t(0x015A), int16_t(0xFEA5), int16_t(0xFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -602,7 +602,7 @@ namespace
|
||||
std::array<char, 8U> storage = {char(0x80), char(0x00), char(0xA5), char(0x5A), char(0x5A), char(0xA5), char(0xFF), char(0xFF)};
|
||||
std::array<uint16_t, 4U> expected = {uint16_t(0x0001), uint16_t(0x5AA5), uint16_t(0xA55A), uint16_t(0xFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -640,7 +640,7 @@ namespace
|
||||
std::array<char, 5U> storage = {char(0x80), char(0x16), char(0xAA), char(0x57), char(0xFF)};
|
||||
std::array<uint16_t, 4U> expected = {uint16_t(0x0001), uint16_t(0x015A), uint16_t(0x02A5), uint16_t(0x03FF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -679,7 +679,7 @@ namespace
|
||||
char(0xA5), char(0x5A), char(0x5A), char(0xA5), char(0xFF), char(0xFF), char(0xFF), char(0xFF)};
|
||||
std::array<int32_t, 4U> expected = {int32_t(0x00000001), int32_t(0x5AA5A55A), int32_t(0xA55A5AA5), int32_t(0xFFFFFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -718,7 +718,7 @@ namespace
|
||||
char(0x55), char(0xAA), char(0x7F), char(0xFF), char(0xFF)};
|
||||
std::array<int32_t, 4U> expected = {int32_t(0x00000001), int32_t(0x001AA55A), int32_t(0xFFE55AA5), int32_t(0xFFFFFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -757,7 +757,7 @@ namespace
|
||||
char(0xA5), char(0x5A), char(0x5A), char(0xA5), char(0xFF), char(0xFF), char(0xFF), char(0xFF)};
|
||||
std::array<int32_t, 4U> expected = {int32_t(0x00000001), int32_t(0x5AA5A55A), int32_t(0xA55A5AA5), int32_t(0xFFFFFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -796,7 +796,7 @@ namespace
|
||||
char(0x55), char(0xAA), char(0x7F), char(0xFF), char(0xFF)};
|
||||
std::array<int32_t, 4U> expected = {uint32_t(0x00000001), uint32_t(0x001AA55A), uint32_t(0x00255AA5), uint32_t(0x003FFFFF)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -838,7 +838,7 @@ namespace
|
||||
std::array<int64_t, 4U> expected = {int64_t(0x0000000000000001LL), int64_t(0x5AA5A55AA55A5AA5LL), int64_t(0xA55A5AA55AA5A55ALL),
|
||||
int64_t(0xFFFFFFFFFFFFFFFFLL)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -879,7 +879,7 @@ namespace
|
||||
std::array<int64_t, 4U> expected = {int64_t(0x0000000000000001LL), int64_t(0x0000255AA55AA55ALL), int64_t(0xFFFFDAA55AA55AA5LL),
|
||||
int64_t(0xFFFFFFFFFFFFFFFFLL)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -921,7 +921,7 @@ namespace
|
||||
std::array<uint64_t, 4U> expected = {uint64_t(0x0000000000000001ULL), uint64_t(0x5AA5A55AA55A5AA5ULL), uint64_t(0xA55A5AA55AA5A55AULL),
|
||||
uint64_t(0xFFFFFFFFFFFFFFFFULL)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -962,7 +962,7 @@ namespace
|
||||
std::array<uint64_t, 4U> expected = {uint64_t(0x0000000000000001ULL), uint64_t(0x0000255AA55AA55AULL), uint64_t(0x00005AA55AA55AA5ULL),
|
||||
uint64_t(0x00007FFFFFFFFFFFULL)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1007,7 +1007,7 @@ namespace
|
||||
std::array<char, 14U> storage = {char(0x5A), char(0x2C), char(0x48), char(0xF7), char(0xB3), char(0xD5), char(0x91),
|
||||
char(0x19), char(0x5D), char(0x3B), char(0x7F), char(0x1E), char(0x6A), char(0xA5)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1049,7 +1049,7 @@ namespace
|
||||
std::array<char, 11U> storage = {char(0x58), char(0xB1), char(0x3E), char(0xF6), char(0x7A), char(0x86),
|
||||
char(0x57), char(0x4E), char(0xC3), char(0xCE), char(0x90)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1091,7 +1091,7 @@ namespace
|
||||
std::array<char, 11U> storage = {char(0x58), char(0xB1), char(0x3E), char(0xF6), char(0x7A), char(0x86),
|
||||
char(0x57), char(0x4E), char(0xC3), char(0xCE), char(0x90)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1126,7 +1126,7 @@ namespace
|
||||
std::array<char, 12U> storage = {char(0x74), char(0xDE), char(0xA2), char(0xCF), char(0x6A), char(0xFB),
|
||||
char(0xA3), char(0x5E), char(0x5D), char(0x30), char(0x9F), char(0x80)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
@ -1154,7 +1154,7 @@ namespace
|
||||
std::array<char, 12U> storage = {char(0x74), char(0xDE), char(0xA2), char(0xCF), char(0x6A), char(0xFB),
|
||||
char(0xA3), char(0x5E), char(0x5D), char(0x30), char(0x9F), char(0x80)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.size_bytes());
|
||||
|
||||
|
||||
@ -119,7 +119,7 @@ namespace
|
||||
{
|
||||
std::array<char, 256> storage;
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.available(CHAR_BIT));
|
||||
CHECK_EQUAL(storage.size(), bit_stream.available<CHAR_BIT>());
|
||||
@ -140,7 +140,7 @@ namespace
|
||||
unsigned char storage = 0;
|
||||
unsigned char expected = 0x5AU;
|
||||
|
||||
etl::bit_stream_writer bit_stream(&storage, 1U, etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(&storage, 1U, etl::bit_order::msb_first);
|
||||
|
||||
CHECK(bit_stream.write(false));
|
||||
CHECK_EQUAL(1U, bit_stream.used_data().size());
|
||||
@ -176,7 +176,7 @@ namespace
|
||||
std::array<char, 256U> expected;
|
||||
std::iota(expected.begin(), expected.end(), 0);
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
for (size_t i = 0UL; i < 256UL; ++i)
|
||||
{
|
||||
@ -204,7 +204,7 @@ namespace
|
||||
std::array<char, 256> expected;
|
||||
std::iota(expected.begin(), expected.end(), 0);
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
for (size_t i = 0UL; i < 256UL; ++i)
|
||||
{
|
||||
@ -233,7 +233,7 @@ namespace
|
||||
|
||||
CHECK(expected.size() == storage.size());
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK(bit_stream.write(int16_t(0x0001)));
|
||||
CHECK_EQUAL(sizeof(int16_t) * 1, bit_stream.used_data().size());
|
||||
@ -265,7 +265,7 @@ namespace
|
||||
|
||||
CHECK(expected.size() == storage.size());
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK(bit_stream.write(uint16_t(0x0001)));
|
||||
CHECK_EQUAL(sizeof(uint16_t) * 1, bit_stream.used_data().size());
|
||||
@ -298,7 +298,7 @@ namespace
|
||||
|
||||
CHECK(expected.size() == storage.size());
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK(bit_stream.write(int32_t(0x00000001)));
|
||||
CHECK_EQUAL(sizeof(int32_t) * 1, bit_stream.used_data().size());
|
||||
@ -331,7 +331,7 @@ namespace
|
||||
|
||||
CHECK(expected.size() == storage.size());
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK(bit_stream.write(uint32_t(0x00000001)));
|
||||
CHECK_EQUAL(sizeof(uint32_t) * 1, bit_stream.used_data().size());
|
||||
@ -365,7 +365,7 @@ namespace
|
||||
|
||||
CHECK(expected.size() == storage.size());
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK(bit_stream.write(int64_t(0x0000000000000001LL)));
|
||||
CHECK_EQUAL(sizeof(int64_t) * 1, bit_stream.used_data().size());
|
||||
@ -399,7 +399,7 @@ namespace
|
||||
|
||||
CHECK(expected.size() == storage.size());
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK(bit_stream.write(uint64_t(0x0000000000000001LL)));
|
||||
CHECK_EQUAL(sizeof(uint64_t) * 1, bit_stream.used_data().size());
|
||||
@ -429,7 +429,7 @@ namespace
|
||||
std::array<int8_t, 4> write_data = {int8_t(0x01), int8_t(0xF5), int8_t(0x05), int8_t(0xFF)}; // 1, -11, 10, -1
|
||||
std::array<char, 4> expected = {char(0x0D), char(0x4B), char(0xF0), char(0x00)}; // 1, -11, 10, -1
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(bit_stream.write(write_data[0], 5));
|
||||
@ -455,7 +455,7 @@ namespace
|
||||
std::array<char, 4 * sizeof(int16_t)> expected = {char(0x00), char(0x55), char(0xAA), char(0x97),
|
||||
char(0xFF), char(0x00), char(0x00), char(0x00)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(bit_stream.write(write_data[0], 10));
|
||||
@ -484,7 +484,7 @@ namespace
|
||||
char(0x56), char(0xA9), char(0x7F), char(0xFF), char(0xFF), char(0x00),
|
||||
char(0x00), char(0x00), char(0x00), char(0x00)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(bit_stream.write(write_data[0], 22));
|
||||
@ -521,7 +521,7 @@ namespace
|
||||
char(0xD5), char(0x2A), char(0xD5), char(0x2A), char(0xD5), char(0x2F),
|
||||
char(0xFF), char(0xFF), char(0xFF), char(0xFF), char(0xFF), char(0xF0)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
// Insert into the stream
|
||||
bit_stream.write(write_data[0], 47);
|
||||
@ -571,7 +571,7 @@ namespace
|
||||
char(0xD5), char(0x2A), char(0xD5), char(0x2A), char(0xD5), char(0x2F),
|
||||
char(0xFF), char(0xFF), char(0xFF), char(0xFF), char(0xFF), char(0xF0)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
// Insert into the stream
|
||||
bit_stream.write(write_data[0], 47);
|
||||
@ -624,7 +624,7 @@ namespace
|
||||
std::array<char, 14> expected = {char(0x5A), char(0x12), char(0x34), char(0x89), char(0xAB), char(0xCD), char(0xEF),
|
||||
char(0xFE), char(0xDC), char(0xBA), char(0x98), char(0x56), char(0x78), char(0xA5)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
// Insert into the stream.
|
||||
bit_stream.write(c1);
|
||||
@ -670,7 +670,7 @@ namespace
|
||||
std::array<char, 14> expected = {char(0x6A), char(0x46), char(0x8A), char(0xF3), char(0x7B), char(0xDB),
|
||||
char(0x97), char(0x53), char(0x19), char(0xE1), char(0x28)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
// Insert into the stream.
|
||||
bit_stream.write(c1, 6);
|
||||
@ -718,7 +718,7 @@ namespace
|
||||
|
||||
auto callback = etl::bit_stream_writer::callback_type::create< Accumulator, &Accumulator::Add>(accumulator);
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big, callback);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first, callback);
|
||||
|
||||
// Insert into the stream.
|
||||
bit_stream.write(c1, 6);
|
||||
@ -754,7 +754,7 @@ namespace
|
||||
std::array<char, 12U> expected{char(0xEC), char(0xBA), char(0xDE), char(0x68), char(0xAF), char(0xD2),
|
||||
char(0xC5), char(0xC8), char(0x65), char(0xD3), char(0xDF), char(0x80)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
Object object1 = {-1234, 123456789, 250};
|
||||
Object object2 = {5678, -987654321, 126};
|
||||
@ -781,7 +781,7 @@ namespace
|
||||
{
|
||||
std::array<char, 2U> storage;
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::big);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first);
|
||||
|
||||
CHECK_EQUAL(bit_stream.empty(), true);
|
||||
CHECK_EQUAL(bit_stream.full(), false);
|
||||
@ -797,6 +797,181 @@ namespace
|
||||
CHECK_EQUAL(bit_stream.full(), true);
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Tests for the separately configurable byte order (endianness).
|
||||
/// bit_order controls MSB/LSB-first bit ordering.
|
||||
/// byte_order controls big/little-endian byte ordering.
|
||||
//*************************************************************************
|
||||
SUITE(test_bit_stream_byte_order)
|
||||
{
|
||||
//*************************************************************************
|
||||
/// bit_order = big (MSB first), byte_order = little.
|
||||
/// The value's bytes are reversed but the bit order is unchanged.
|
||||
//*************************************************************************
|
||||
TEST(test_write_uint16_t_little_byte_order)
|
||||
{
|
||||
std::array<char, sizeof(uint16_t)> storage;
|
||||
storage.fill(0);
|
||||
std::array<char, sizeof(uint16_t)> expected = {char(0x34), char(0x12)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first, etl::bit_stream_writer::callback_type(),
|
||||
etl::endian::little);
|
||||
|
||||
CHECK(bit_stream.write(uint16_t(0x1234)));
|
||||
|
||||
for (size_t i = 0UL; i < storage.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(int(expected[i]), int(storage[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_write_uint32_t_little_byte_order)
|
||||
{
|
||||
std::array<char, sizeof(uint32_t)> storage;
|
||||
storage.fill(0);
|
||||
std::array<char, sizeof(uint32_t)> expected = {char(0x78), char(0x56), char(0x34), char(0x12)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first, etl::bit_stream_writer::callback_type(),
|
||||
etl::endian::little);
|
||||
|
||||
CHECK(bit_stream.write(uint32_t(0x12345678)));
|
||||
|
||||
for (size_t i = 0UL; i < storage.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(int(expected[i]), int(storage[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// byte_order = big must match the default (no byte swap).
|
||||
//*************************************************************************
|
||||
TEST(test_write_uint16_t_big_byte_order_matches_default)
|
||||
{
|
||||
std::array<char, sizeof(uint16_t)> storage;
|
||||
storage.fill(0);
|
||||
std::array<char, sizeof(uint16_t)> expected = {char(0x12), char(0x34)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first, etl::bit_stream_writer::callback_type(),
|
||||
etl::endian::big);
|
||||
|
||||
CHECK(bit_stream.write(uint16_t(0x1234)));
|
||||
|
||||
for (size_t i = 0UL; i < storage.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(int(expected[i]), int(storage[i]));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// The reader must undo the byte order applied by the writer.
|
||||
//*************************************************************************
|
||||
TEST(test_read_uint32_t_little_byte_order)
|
||||
{
|
||||
std::array<char, sizeof(uint32_t)> storage = {char(0x78), char(0x56), char(0x34), char(0x12)};
|
||||
|
||||
etl::bit_stream_reader bit_stream(storage.data(), storage.size(), etl::bit_order::msb_first, etl::endian::little);
|
||||
|
||||
etl::optional<uint32_t> result = bit_stream.read<uint32_t>();
|
||||
CHECK(result.has_value());
|
||||
CHECK_EQUAL(uint32_t(0x12345678), result.value());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Round-trip writer -> reader for every combination of bit order and
|
||||
/// byte order, for an unsigned type.
|
||||
//*************************************************************************
|
||||
TEST(test_round_trip_all_orders_uint16_t)
|
||||
{
|
||||
const etl::bit_order bit_orders[2] = {etl::bit_order::msb_first, etl::bit_order::lsb_first};
|
||||
const etl::endian byte_orders[2] = {etl::endian::big, etl::endian::little};
|
||||
const std::array<uint16_t, 8U> values = {uint16_t(0x0000), uint16_t(0x0001), uint16_t(0x1234), uint16_t(0x5AA5),
|
||||
uint16_t(0xA55A), uint16_t(0x00FF), uint16_t(0xFF00), uint16_t(0xFFFF)};
|
||||
|
||||
for (size_t b = 0UL; b < 2UL; ++b)
|
||||
{
|
||||
for (size_t y = 0UL; y < 2UL; ++y)
|
||||
{
|
||||
for (size_t v = 0UL; v < values.size(); ++v)
|
||||
{
|
||||
std::array<char, sizeof(uint16_t)> storage;
|
||||
storage.fill(0);
|
||||
|
||||
etl::bit_stream_writer writer(storage.data(), storage.size(), bit_orders[b], etl::bit_stream_writer::callback_type(), byte_orders[y]);
|
||||
CHECK(writer.write(values[v]));
|
||||
|
||||
etl::bit_stream_reader reader(storage.data(), storage.size(), bit_orders[b], byte_orders[y]);
|
||||
etl::optional<uint16_t> result = reader.read<uint16_t>();
|
||||
CHECK(result.has_value());
|
||||
CHECK_EQUAL(values[v], result.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Round-trip writer -> reader for every combination of bit order and
|
||||
/// byte order, for a signed type.
|
||||
//*************************************************************************
|
||||
TEST(test_round_trip_all_orders_int32_t)
|
||||
{
|
||||
const etl::bit_order bit_orders[2] = {etl::bit_order::msb_first, etl::bit_order::lsb_first};
|
||||
const etl::endian byte_orders[2] = {etl::endian::big, etl::endian::little};
|
||||
const std::array<int32_t, 6U> values = {int32_t(0x00000000), int32_t(0x00000001), int32_t(0x12345678),
|
||||
int32_t(-1234), int32_t(-1), int32_t(0x7FFFFFFF)};
|
||||
|
||||
for (size_t b = 0UL; b < 2UL; ++b)
|
||||
{
|
||||
for (size_t y = 0UL; y < 2UL; ++y)
|
||||
{
|
||||
for (size_t v = 0UL; v < values.size(); ++v)
|
||||
{
|
||||
std::array<char, sizeof(int32_t)> storage;
|
||||
storage.fill(0);
|
||||
|
||||
etl::bit_stream_writer writer(storage.data(), storage.size(), bit_orders[b], etl::bit_stream_writer::callback_type(), byte_orders[y]);
|
||||
CHECK(writer.write(values[v]));
|
||||
|
||||
etl::bit_stream_reader reader(storage.data(), storage.size(), bit_orders[b], byte_orders[y]);
|
||||
etl::optional<int32_t> result = reader.read<int32_t>();
|
||||
CHECK(result.has_value());
|
||||
CHECK_EQUAL(values[v], result.value());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
/// Byte order is only meaningful for full-width values, so it has no
|
||||
/// effect on a sub-width field. The data must still round-trip.
|
||||
//*************************************************************************
|
||||
TEST(test_byte_order_ignored_for_sub_width_write)
|
||||
{
|
||||
std::array<char, sizeof(uint16_t)> storage_big;
|
||||
std::array<char, sizeof(uint16_t)> storage_little;
|
||||
storage_big.fill(0);
|
||||
storage_little.fill(0);
|
||||
|
||||
etl::bit_stream_writer writer_big(storage_big.data(), storage_big.size(), etl::bit_order::msb_first, etl::bit_stream_writer::callback_type(),
|
||||
etl::endian::big);
|
||||
etl::bit_stream_writer writer_little(storage_little.data(), storage_little.size(), etl::bit_order::msb_first,
|
||||
etl::bit_stream_writer::callback_type(), etl::endian::little);
|
||||
|
||||
CHECK(writer_big.write(uint16_t(0x0ABC), 12));
|
||||
CHECK(writer_little.write(uint16_t(0x0ABC), 12));
|
||||
|
||||
for (size_t i = 0UL; i < storage_big.size(); ++i)
|
||||
{
|
||||
CHECK_EQUAL(int(storage_big[i]), int(storage_little[i]));
|
||||
}
|
||||
|
||||
etl::bit_stream_reader reader(storage_little.data(), storage_little.size(), etl::bit_order::msb_first, etl::endian::little);
|
||||
etl::optional<uint16_t> result = reader.read<uint16_t>(12);
|
||||
CHECK(result.has_value());
|
||||
CHECK_EQUAL(uint16_t(0x0ABC), result.value());
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
@ -119,7 +119,7 @@ namespace
|
||||
{
|
||||
std::array<char, 256> storage;
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(storage.size(), bit_stream.available(CHAR_BIT));
|
||||
CHECK_EQUAL(storage.size(), bit_stream.available<CHAR_BIT>());
|
||||
@ -140,7 +140,7 @@ namespace
|
||||
unsigned char storage = 0;
|
||||
unsigned char expected = 0x5AU;
|
||||
|
||||
etl::bit_stream_writer bit_stream(&storage, 1U, etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(&storage, 1U, etl::bit_order::lsb_first);
|
||||
|
||||
CHECK(bit_stream.write(false));
|
||||
CHECK_EQUAL(1U, bit_stream.used_data().size());
|
||||
@ -176,7 +176,7 @@ namespace
|
||||
std::array<char, 256U> expected;
|
||||
std::iota(expected.begin(), expected.end(), 0);
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
for (size_t i = 0UL; i < 256UL; ++i)
|
||||
{
|
||||
@ -204,7 +204,7 @@ namespace
|
||||
std::array<char, 256> expected;
|
||||
std::iota(expected.begin(), expected.end(), 0);
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
for (size_t i = 0UL; i < 256UL; ++i)
|
||||
{
|
||||
@ -233,7 +233,7 @@ namespace
|
||||
|
||||
CHECK(expected.size() == storage.size());
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK(bit_stream.write(int16_t(0x0001)));
|
||||
CHECK_EQUAL(sizeof(int16_t) * 1, bit_stream.used_data().size());
|
||||
@ -265,7 +265,7 @@ namespace
|
||||
|
||||
CHECK(expected.size() == storage.size());
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK(bit_stream.write(uint16_t(0x0001)));
|
||||
CHECK_EQUAL(sizeof(uint16_t) * 1, bit_stream.used_data().size());
|
||||
@ -298,7 +298,7 @@ namespace
|
||||
|
||||
CHECK(expected.size() == storage.size());
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK(bit_stream.write(int32_t(0x00000001)));
|
||||
CHECK_EQUAL(sizeof(int32_t) * 1, bit_stream.used_data().size());
|
||||
@ -331,7 +331,7 @@ namespace
|
||||
|
||||
CHECK(expected.size() == storage.size());
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK(bit_stream.write(uint32_t(0x00000001)));
|
||||
CHECK_EQUAL(sizeof(uint32_t) * 1, bit_stream.used_data().size());
|
||||
@ -365,7 +365,7 @@ namespace
|
||||
|
||||
CHECK(expected.size() == storage.size());
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK(bit_stream.write(int64_t(0x0000000000000001LL)));
|
||||
CHECK_EQUAL(sizeof(int64_t) * 1, bit_stream.used_data().size());
|
||||
@ -399,7 +399,7 @@ namespace
|
||||
|
||||
CHECK(expected.size() == storage.size());
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK(bit_stream.write(uint64_t(0x0000000000000001LL)));
|
||||
CHECK_EQUAL(sizeof(uint64_t) * 1, bit_stream.used_data().size());
|
||||
@ -429,7 +429,7 @@ namespace
|
||||
std::array<int8_t, 4> write_data = {int8_t(0x01), int8_t(0xF5), int8_t(0x05), int8_t(0xFF)}; // 1, -11, 10, -1
|
||||
std::array<char, 4> expected = {char(0x85), char(0x69), char(0xF0), char(0x00)}; // 1, -11, 10, -1
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(bit_stream.write(write_data[0], 5));
|
||||
@ -454,7 +454,7 @@ namespace
|
||||
std::array<uint8_t, 4> write_data = {uint8_t(0x01), uint8_t(0xF5), uint8_t(0x05), uint8_t(0xFF)}; // 1, -11, 10, -1
|
||||
std::array<char, 4> expected = {char(0x85), char(0x69), char(0xF0), char(0x00)}; // 1, -11, 10, -1
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(bit_stream.write(write_data[0], 5));
|
||||
@ -480,7 +480,7 @@ namespace
|
||||
std::array<char, 4 * sizeof(int16_t)> expected = {char(0x80), char(0x16), char(0xAA), char(0x57),
|
||||
char(0xFF), char(0x00), char(0x00), char(0x00)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(bit_stream.write(write_data[0], 10));
|
||||
@ -508,7 +508,7 @@ namespace
|
||||
std::array<char, 4 * sizeof(uint16_t)> expected = {char(0x80), char(0x16), char(0xAA), char(0x57),
|
||||
char(0xFF), char(0x00), char(0x00), char(0x00)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(bit_stream.write(write_data[0], 10));
|
||||
@ -537,7 +537,7 @@ namespace
|
||||
char(0x55), char(0xAA), char(0x7F), char(0xFF), char(0xFF), char(0x00),
|
||||
char(0x00), char(0x00), char(0x00), char(0x00)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(bit_stream.write(write_data[0], 22));
|
||||
@ -572,7 +572,7 @@ namespace
|
||||
char(0x55), char(0xAA), char(0x7F), char(0xFF), char(0xFF), char(0x00),
|
||||
char(0x00), char(0x00), char(0x00), char(0x00)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
// Insert into the stream
|
||||
CHECK(bit_stream.write(write_data[0], 22));
|
||||
@ -609,7 +609,7 @@ namespace
|
||||
char(0x95), char(0x6A), char(0x95), char(0x6A), char(0x95), char(0x6F),
|
||||
char(0xFF), char(0xFF), char(0xFF), char(0xFF), char(0xFF), char(0xF0)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
// Insert into the stream
|
||||
bit_stream.write(write_data[0], 47);
|
||||
@ -659,7 +659,7 @@ namespace
|
||||
char(0x95), char(0x6A), char(0x95), char(0x6A), char(0x95), char(0x6F),
|
||||
char(0xFF), char(0xFF), char(0xFF), char(0xFF), char(0xFF), char(0xF0)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
// Insert into the stream
|
||||
bit_stream.write(write_data[0], 47);
|
||||
@ -712,7 +712,7 @@ namespace
|
||||
std::array<char, 14> expected = {char(0x5A), char(0x2C), char(0x48), char(0xF7), char(0xB3), char(0xD5), char(0x91),
|
||||
char(0x19), char(0x5D), char(0x3B), char(0x7F), char(0x1E), char(0x6A), char(0xA5)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
// Insert into the stream.
|
||||
bit_stream.write(c1);
|
||||
@ -758,7 +758,7 @@ namespace
|
||||
std::array<char, 14> expected = {char(0x58), char(0xB1), char(0x3E), char(0xF6), char(0x7A), char(0x86),
|
||||
char(0x57), char(0x4E), char(0xC3), char(0xCE), char(0x90)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
// Insert into the stream.
|
||||
bit_stream.write(c1, 6);
|
||||
@ -805,7 +805,7 @@ namespace
|
||||
|
||||
auto callback = etl::bit_stream_writer::callback_type::create< Accumulator, &Accumulator::Add>(accumulator);
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little, callback);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first, callback);
|
||||
|
||||
// Insert into the stream.
|
||||
bit_stream.write(c1, 6);
|
||||
@ -841,7 +841,7 @@ namespace
|
||||
std::array<char, 12U> expected{char(0x74), char(0xDE), char(0xA2), char(0xCF), char(0x6A), char(0xFB),
|
||||
char(0xA3), char(0x5E), char(0x5D), char(0x30), char(0x9F), char(0x80)};
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
Object object1 = {-1234, 123456789, 250};
|
||||
Object object2 = {5678, -987654321, 126};
|
||||
@ -868,7 +868,7 @@ namespace
|
||||
{
|
||||
std::array<char, 2U> storage;
|
||||
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::endian::little);
|
||||
etl::bit_stream_writer bit_stream(storage.data(), storage.size(), etl::bit_order::lsb_first);
|
||||
|
||||
CHECK_EQUAL(bit_stream.empty(), true);
|
||||
CHECK_EQUAL(bit_stream.full(), false);
|
||||
|
||||
@ -398,6 +398,22 @@ namespace
|
||||
CHECK_EQUAL(0, data.count());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Empty strings exercise the string_length == 0 path in from_string,
|
||||
// which must not shift by (0 - 1U).
|
||||
TEST(test_construct_from_empty_string)
|
||||
{
|
||||
etl::bitset<64, uint64_t> data_char("");
|
||||
etl::bitset<64, uint64_t> data_wchar(L"");
|
||||
etl::bitset<64, uint64_t> data_u16(u"");
|
||||
etl::bitset<64, uint64_t> data_u32(U"");
|
||||
|
||||
CHECK_EQUAL(0U, data_char.count());
|
||||
CHECK_EQUAL(0U, data_wchar.count());
|
||||
CHECK_EQUAL(0U, data_u16.count());
|
||||
CHECK_EQUAL(0U, data_u32.count());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_construct_from_excess_string)
|
||||
{
|
||||
|
||||
@ -286,5 +286,86 @@ namespace
|
||||
CHECK_EQUAL(0, time.fractional_width);
|
||||
CHECK_TRUE((std::is_same<duration_type, Chrono::hh_mm_ss<duration_type>::precision>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_is_am)
|
||||
{
|
||||
for (int h = 0; h <= 11; ++h)
|
||||
{
|
||||
CHECK_TRUE(Chrono::is_am(Chrono::hours(h)));
|
||||
}
|
||||
|
||||
for (int h = 12; h <= 23; ++h)
|
||||
{
|
||||
CHECK_FALSE(Chrono::is_am(Chrono::hours(h)));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_is_pm)
|
||||
{
|
||||
for (int h = 0; h <= 11; ++h)
|
||||
{
|
||||
CHECK_FALSE(Chrono::is_pm(Chrono::hours(h)));
|
||||
}
|
||||
|
||||
for (int h = 12; h <= 23; ++h)
|
||||
{
|
||||
CHECK_TRUE(Chrono::is_pm(Chrono::hours(h)));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_make12)
|
||||
{
|
||||
// Midnight (0h) maps to 12h.
|
||||
CHECK_EQUAL(12, Chrono::make12(Chrono::hours(0)).count());
|
||||
|
||||
// 1h..12h are unchanged.
|
||||
for (int h = 1; h <= 12; ++h)
|
||||
{
|
||||
CHECK_EQUAL(h, Chrono::make12(Chrono::hours(h)).count());
|
||||
}
|
||||
|
||||
// 13h..23h map to 1h..11h.
|
||||
for (int h = 13; h <= 23; ++h)
|
||||
{
|
||||
CHECK_EQUAL(h - 12, Chrono::make12(Chrono::hours(h)).count());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_make24)
|
||||
{
|
||||
// am: 12h maps to 0h, 1h..11h are unchanged.
|
||||
CHECK_EQUAL(0, Chrono::make24(Chrono::hours(12), false).count());
|
||||
|
||||
for (int h = 1; h <= 11; ++h)
|
||||
{
|
||||
CHECK_EQUAL(h, Chrono::make24(Chrono::hours(h), false).count());
|
||||
}
|
||||
|
||||
// pm: 12h stays 12h, 1h..11h map to 13h..23h.
|
||||
CHECK_EQUAL(12, Chrono::make24(Chrono::hours(12), true).count());
|
||||
|
||||
for (int h = 1; h <= 11; ++h)
|
||||
{
|
||||
CHECK_EQUAL(h + 12, Chrono::make24(Chrono::hours(h), true).count());
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_make12_make24_round_trip)
|
||||
{
|
||||
// For every 24-hour value, make12 plus its am/pm flag round-trips via make24.
|
||||
for (int h = 0; h <= 23; ++h)
|
||||
{
|
||||
Chrono::hours h24(h);
|
||||
bool pm = Chrono::is_pm(h24);
|
||||
Chrono::hours h12 = Chrono::make12(h24);
|
||||
|
||||
CHECK_EQUAL(h, Chrono::make24(h12, pm).count());
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -185,6 +185,99 @@ namespace
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_operator_plus_time_point_duration)
|
||||
{
|
||||
TimePoint tp{Chrono::hours(10)};
|
||||
|
||||
// Same duration type.
|
||||
auto result = tp + Chrono::hours(5);
|
||||
CHECK_EQUAL(15, result.time_since_epoch().count());
|
||||
|
||||
// Mixed duration types resolve to the common (finer) type.
|
||||
auto result_mixed = tp + Chrono::days(1); // 10 hours + 24 hours
|
||||
CHECK_EQUAL(34, result_mixed.time_since_epoch().count());
|
||||
CHECK_TRUE((std::is_same<decltype(result_mixed)::duration, Chrono::hours>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_operator_plus_duration_time_point)
|
||||
{
|
||||
TimePoint tp{Chrono::hours(10)};
|
||||
|
||||
// Same duration type.
|
||||
auto result = Chrono::hours(5) + tp;
|
||||
CHECK_EQUAL(15, result.time_since_epoch().count());
|
||||
|
||||
// Mixed duration types resolve to the common (finer) type.
|
||||
auto result_mixed = Chrono::days(1) + tp; // 24 hours + 10 hours
|
||||
CHECK_EQUAL(34, result_mixed.time_since_epoch().count());
|
||||
CHECK_TRUE((std::is_same<decltype(result_mixed)::duration, Chrono::hours>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_operator_minus_time_point_duration)
|
||||
{
|
||||
TimePoint tp{Chrono::hours(50)};
|
||||
|
||||
// Same duration type.
|
||||
auto result = tp - Chrono::hours(5);
|
||||
CHECK_EQUAL(45, result.time_since_epoch().count());
|
||||
|
||||
// Mixed duration types resolve to the common (finer) type.
|
||||
auto result_mixed = tp - Chrono::days(1); // 50 hours - 24 hours
|
||||
CHECK_EQUAL(26, result_mixed.time_since_epoch().count());
|
||||
CHECK_TRUE((std::is_same<decltype(result_mixed)::duration, Chrono::hours>::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_operator_minus_time_point_time_point)
|
||||
{
|
||||
TimePoint tp1{Chrono::hours(50)};
|
||||
TimePoint tp2{Chrono::hours(20)};
|
||||
|
||||
// Subtracting two time_points yields the duration between them.
|
||||
auto diff = tp1 - tp2;
|
||||
CHECK_EQUAL(30, diff.count());
|
||||
CHECK_TRUE((std::is_same<decltype(diff), Chrono::hours>::value));
|
||||
|
||||
// Mixed duration types resolve to the common (finer) duration.
|
||||
Chrono::time_point<test_clock, Chrono::days> tp_days{Chrono::days(2)}; // 48 hours
|
||||
auto diff_mixed = tp1 - tp_days; // 50 hours - 48 hours
|
||||
CHECK_EQUAL(2, diff_mixed.count());
|
||||
CHECK_TRUE((std::is_same<decltype(diff_mixed), Chrono::hours>::value));
|
||||
|
||||
// The reverse difference is negative.
|
||||
auto diff_negative = tp2 - tp1;
|
||||
CHECK_EQUAL(-30, diff_negative.count());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_increment_decrement_operators)
|
||||
{
|
||||
TimePoint tp{Chrono::hours(10)};
|
||||
|
||||
// Pre-increment.
|
||||
auto& pre_inc = ++tp;
|
||||
CHECK_EQUAL(11, tp.time_since_epoch().count());
|
||||
CHECK_EQUAL(11, pre_inc.time_since_epoch().count());
|
||||
|
||||
// Post-increment returns the previous value.
|
||||
TimePoint post_inc = tp++;
|
||||
CHECK_EQUAL(11, post_inc.time_since_epoch().count());
|
||||
CHECK_EQUAL(12, tp.time_since_epoch().count());
|
||||
|
||||
// Pre-decrement.
|
||||
auto& pre_dec = --tp;
|
||||
CHECK_EQUAL(11, tp.time_since_epoch().count());
|
||||
CHECK_EQUAL(11, pre_dec.time_since_epoch().count());
|
||||
|
||||
// Post-decrement returns the previous value.
|
||||
TimePoint post_dec = tp--;
|
||||
CHECK_EQUAL(11, post_dec.time_since_epoch().count());
|
||||
CHECK_EQUAL(10, tp.time_since_epoch().count());
|
||||
}
|
||||
|
||||
#if ETL_USING_ETL_CHRONO
|
||||
//*************************************************************************
|
||||
TEST(test_min_max_time_point)
|
||||
|
||||
@ -593,6 +593,7 @@ namespace
|
||||
//*************************************************************************
|
||||
TEST(test_conversion_operator_for_forward_iterator)
|
||||
{
|
||||
#include "etl/private/diagnostic_null_dereference_push.h"
|
||||
DataF data = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
|
||||
|
||||
etl::circular_iterator<DataF::const_iterator> ci(std::begin(data), std::end(data));
|
||||
@ -607,6 +608,7 @@ namespace
|
||||
++itr;
|
||||
++ci;
|
||||
CHECK(itr == ci.current());
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -2306,7 +2306,9 @@ namespace
|
||||
|
||||
data.fill(N999);
|
||||
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
CHECK(std::equal(blank_data.begin(), blank_data.end(), data.begin()));
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
@ -2319,6 +2321,7 @@ namespace
|
||||
// Access via const_iterator operator[]
|
||||
DataNDC::const_iterator cit = cdata.begin();
|
||||
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
// Verify operator[] returns values matching sequential access
|
||||
for (size_t i = 0; i < cdata.size(); ++i)
|
||||
{
|
||||
@ -2330,6 +2333,7 @@ namespace
|
||||
// the type would be non-const reference which is incorrect for const_iterator)
|
||||
const NDC& ref = cit[0];
|
||||
CHECK(ref == cdata[0]);
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
}
|
||||
}
|
||||
} // namespace
|
||||
|
||||
@ -248,6 +248,68 @@ namespace
|
||||
CHECK_EQUAL(0U, histogram2.count());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// operator[] of the run time offset histogram uses the stored start index,
|
||||
// so copying/moving must preserve it. Regression test: the copy/move
|
||||
// constructors and assignment operators used to forget to copy start_index.
|
||||
//*************************************************************************
|
||||
TEST(test_int_runtime_offset_copy_constructor_preserves_start_index)
|
||||
{
|
||||
IntRuntimeOffsetHistogram histogram1(Start, input2.begin(), input2.end());
|
||||
|
||||
IntRuntimeOffsetHistogram histogram2(histogram1);
|
||||
|
||||
for (int key = Start; key < Start + static_cast<int>(Size); ++key)
|
||||
{
|
||||
CHECK_EQUAL(static_cast<int>(histogram1[key]), static_cast<int>(histogram2[key]));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_int_runtime_offset_copy_assignment_preserves_start_index)
|
||||
{
|
||||
IntRuntimeOffsetHistogram histogram1(Start, input2.begin(), input2.end());
|
||||
|
||||
IntRuntimeOffsetHistogram histogram2(Start);
|
||||
histogram2 = histogram1;
|
||||
|
||||
for (int key = Start; key < Start + static_cast<int>(Size); ++key)
|
||||
{
|
||||
CHECK_EQUAL(static_cast<int>(histogram1[key]), static_cast<int>(histogram2[key]));
|
||||
}
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP11
|
||||
//*************************************************************************
|
||||
TEST(test_int_runtime_offset_move_constructor_preserves_start_index)
|
||||
{
|
||||
IntRuntimeOffsetHistogram histogram1(Start, input2.begin(), input2.end());
|
||||
IntRuntimeOffsetHistogram histogram_source(Start, input2.begin(), input2.end());
|
||||
|
||||
IntRuntimeOffsetHistogram histogram2(etl::move(histogram_source));
|
||||
|
||||
for (int key = Start; key < Start + static_cast<int>(Size); ++key)
|
||||
{
|
||||
CHECK_EQUAL(static_cast<int>(histogram1[key]), static_cast<int>(histogram2[key]));
|
||||
}
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_int_runtime_offset_move_assignment_preserves_start_index)
|
||||
{
|
||||
IntRuntimeOffsetHistogram histogram1(Start, input2.begin(), input2.end());
|
||||
IntRuntimeOffsetHistogram histogram_source(Start, input2.begin(), input2.end());
|
||||
|
||||
IntRuntimeOffsetHistogram histogram2(Start);
|
||||
histogram2 = etl::move(histogram_source);
|
||||
|
||||
for (int key = Start; key < Start + static_cast<int>(Size); ++key)
|
||||
{
|
||||
CHECK_EQUAL(static_cast<int>(histogram1[key]), static_cast<int>(histogram2[key]));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_string_histogram_constructor)
|
||||
{
|
||||
|
||||
@ -1720,6 +1720,7 @@ namespace
|
||||
{
|
||||
using Pair = std::pair<const std::string, int>;
|
||||
|
||||
#include "etl/private/diagnostic_null_dereference_push.h"
|
||||
etl::map data{Pair{"0", 0}, Pair{"1", 1}, Pair{"2", 2}, Pair{"3", 3}, Pair{"4", 4}, Pair{"5", 5}};
|
||||
|
||||
auto v = *data.begin();
|
||||
@ -1732,6 +1733,7 @@ namespace
|
||||
CHECK_EQUAL(3, data.at("3"));
|
||||
CHECK_EQUAL(4, data.at("4"));
|
||||
CHECK_EQUAL(5, data.at("5"));
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
||||
}
|
||||
@ -1743,6 +1745,7 @@ namespace
|
||||
{
|
||||
using Pair = ETL_OR_STD::pair<const std::string, int>;
|
||||
|
||||
#include "etl/private/diagnostic_null_dereference_push.h"
|
||||
auto data = etl::make_map<const std::string, int, std::less<std::string>>(Pair{"0", 0}, Pair{"1", 1}, Pair{"2", 2}, Pair{"3", 3}, Pair{"4", 4},
|
||||
Pair{"5", 5});
|
||||
|
||||
@ -1756,6 +1759,7 @@ namespace
|
||||
CHECK_EQUAL(3, data.at("3"));
|
||||
CHECK_EQUAL(4, data.at("4"));
|
||||
CHECK_EQUAL(5, data.at("5"));
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
CHECK_TRUE(std::is_sorted(data.begin(), data.end(), data.value_comp()));
|
||||
}
|
||||
|
||||
@ -152,6 +152,24 @@ namespace
|
||||
CHECK_EQUAL(3, memCast.ref<Data>().a[2]);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Cross-size copy/assignment must copy only the source's bytes and must
|
||||
// not read past the end of the (smaller) source buffer.
|
||||
TEST(test_mem_cast_copy_and_assign_from_smaller)
|
||||
{
|
||||
etl::mem_cast<sizeof(uint32_t), alignof(uint32_t)> smaller;
|
||||
smaller.assign<uint32_t>(0x12345678UL);
|
||||
|
||||
// Cross-size copy construct (destination larger than source).
|
||||
etl::mem_cast<sizeof(uint32_t) * 2U, alignof(uint32_t)> larger_copy(smaller);
|
||||
CHECK_EQUAL(0x12345678UL, larger_copy.ref<uint32_t>());
|
||||
|
||||
// Cross-size assignment (destination larger than source).
|
||||
etl::mem_cast<sizeof(uint32_t) * 2U, alignof(uint32_t)> larger_assign;
|
||||
larger_assign = smaller;
|
||||
CHECK_EQUAL(0x12345678UL, larger_assign.ref<uint32_t>());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_mem_cast_assign_type_at_dynamic_offset)
|
||||
{
|
||||
|
||||
@ -158,6 +158,33 @@ namespace
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
// A minimal fancy pointer with a nested element_type and a static
|
||||
// pointer_to. Used to exercise etl::pointer_traits' primary template.
|
||||
template <typename T>
|
||||
struct fancy_pointer
|
||||
{
|
||||
typedef T element_type;
|
||||
|
||||
T* raw;
|
||||
|
||||
static fancy_pointer pointer_to(T& r)
|
||||
{
|
||||
fancy_pointer p;
|
||||
p.raw = etl::addressof(r);
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
//***********************************
|
||||
// A fancy pointer without a nested element_type, so pointer_traits must
|
||||
// deduce the element type from the first template parameter.
|
||||
template <typename T>
|
||||
struct bare_pointer
|
||||
{
|
||||
T* raw;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
namespace
|
||||
@ -1808,6 +1835,157 @@ namespace
|
||||
CHECK_EQUAL(plist_item, etl::to_address(itr));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_launder)
|
||||
{
|
||||
int i = 42;
|
||||
int* p = etl::launder(&i);
|
||||
CHECK_EQUAL(&i, p);
|
||||
CHECK_EQUAL(42, *p);
|
||||
|
||||
// Launder a new object created in reused storage.
|
||||
struct quad_t
|
||||
{
|
||||
uint8_t a;
|
||||
uint8_t b;
|
||||
uint8_t c;
|
||||
uint8_t d;
|
||||
};
|
||||
|
||||
alignas(quad_t) unsigned char buffer[sizeof(quad_t)];
|
||||
quad_t* q = ::new (buffer) quad_t{1, 2, 3, 4};
|
||||
quad_t* lq = etl::launder(q);
|
||||
CHECK(reinterpret_cast<unsigned char*>(lq) == buffer);
|
||||
CHECK_EQUAL(1, lq->a);
|
||||
CHECK_EQUAL(2, lq->b);
|
||||
CHECK_EQUAL(3, lq->c);
|
||||
CHECK_EQUAL(4, lq->d);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_start_lifetime_as)
|
||||
{
|
||||
struct quad_t
|
||||
{
|
||||
uint8_t a;
|
||||
uint8_t b;
|
||||
uint8_t c;
|
||||
uint8_t d;
|
||||
};
|
||||
|
||||
alignas(quad_t) unsigned char buffer[sizeof(quad_t)] = {1, 2, 3, 4};
|
||||
|
||||
quad_t* p = etl::start_lifetime_as<quad_t>(buffer);
|
||||
CHECK(reinterpret_cast<unsigned char*>(p) == buffer);
|
||||
CHECK_EQUAL(1, p->a);
|
||||
CHECK_EQUAL(2, p->b);
|
||||
CHECK_EQUAL(3, p->c);
|
||||
CHECK_EQUAL(4, p->d);
|
||||
|
||||
const void* cbuffer = buffer;
|
||||
const quad_t* cp = etl::start_lifetime_as<quad_t>(cbuffer);
|
||||
CHECK(reinterpret_cast<const unsigned char*>(cp) == buffer);
|
||||
CHECK_EQUAL(1, cp->a);
|
||||
CHECK_EQUAL(4, cp->d);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_start_lifetime_as_array)
|
||||
{
|
||||
alignas(uint16_t) unsigned char buffer[sizeof(uint16_t) * 3] = {0, 0, 0, 0, 0, 0};
|
||||
|
||||
uint16_t* p = etl::start_lifetime_as_array<uint16_t>(buffer, 3);
|
||||
CHECK(reinterpret_cast<unsigned char*>(p) == buffer);
|
||||
p[0] = 1;
|
||||
p[2] = 2;
|
||||
CHECK_EQUAL(1, p[0]);
|
||||
CHECK_EQUAL(2, p[2]);
|
||||
|
||||
// n == 0 returns a pointer comparing equal to p.
|
||||
uint16_t* p0 = etl::start_lifetime_as_array<uint16_t>(buffer, 0);
|
||||
CHECK(reinterpret_cast<unsigned char*>(p0) == buffer);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pointer_traits)
|
||||
{
|
||||
typedef etl::pointer_traits<int*> traits;
|
||||
|
||||
CHECK((std::is_same<int*, traits::pointer>::value));
|
||||
CHECK((std::is_same<int, traits::element_type>::value));
|
||||
CHECK((std::is_same<ptrdiff_t, traits::difference_type>::value));
|
||||
#if ETL_USING_CPP11
|
||||
CHECK((std::is_same<char*, traits::rebind<char> >::value));
|
||||
#endif
|
||||
|
||||
int i = 42;
|
||||
int* p = traits::pointer_to(i);
|
||||
CHECK_EQUAL(&i, p);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pointer_traits_fancy_pointer)
|
||||
{
|
||||
typedef etl::pointer_traits<fancy_pointer<int> > traits;
|
||||
|
||||
CHECK((std::is_same<fancy_pointer<int>, traits::pointer>::value));
|
||||
CHECK((std::is_same<int, traits::element_type>::value));
|
||||
CHECK((std::is_same<ptrdiff_t, traits::difference_type>::value));
|
||||
CHECK((std::is_same<fancy_pointer<char>, traits::rebind<char> >::value));
|
||||
|
||||
int i = 42;
|
||||
fancy_pointer<int> p = traits::pointer_to(i);
|
||||
CHECK_EQUAL(&i, p.raw);
|
||||
|
||||
// element_type and rebind are deduced from the first template parameter
|
||||
// when there is no nested element_type.
|
||||
CHECK((std::is_same<int, etl::pointer_traits<bare_pointer<int> >::element_type>::value));
|
||||
CHECK((std::is_same<bare_pointer<char>, etl::pointer_traits<bare_pointer<int> >::rebind<char> >::value));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_align)
|
||||
{
|
||||
alignas(16) unsigned char buffer[64];
|
||||
|
||||
void* ptr = buffer + 1; // Deliberately misaligned.
|
||||
size_t space = sizeof(buffer) - 1;
|
||||
|
||||
void* aligned = etl::align(16, 8, ptr, space);
|
||||
|
||||
// 'buffer' is 16-aligned, so aligning 'buffer + 1' to 16 skips 15 bytes of
|
||||
// padding, landing on 'buffer + 16' and shrinking 'space' by that padding.
|
||||
CHECK(aligned != ETL_NULLPTR);
|
||||
CHECK(reinterpret_cast<unsigned char*>(aligned) == buffer + 16);
|
||||
CHECK(reinterpret_cast<unsigned char*>(ptr) == buffer + 16);
|
||||
CHECK_EQUAL(sizeof(buffer) - 1 - 15, space);
|
||||
|
||||
// Not enough space returns nullptr.
|
||||
void* small_ptr = buffer + 1;
|
||||
size_t small_space = 2;
|
||||
CHECK(etl::align(16, 8, small_ptr, small_space) == ETL_NULLPTR);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_assume_aligned)
|
||||
{
|
||||
alignas(16) int data[4] = {1, 2, 3, 4};
|
||||
|
||||
int* p = etl::assume_aligned<16>(&data[0]);
|
||||
CHECK_EQUAL(&data[0], p);
|
||||
CHECK_EQUAL(1, *p);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_is_sufficiently_aligned)
|
||||
{
|
||||
alignas(16) unsigned char buffer[32];
|
||||
|
||||
CHECK(etl::is_sufficiently_aligned<16>(buffer));
|
||||
CHECK(etl::is_sufficiently_aligned<8>(buffer));
|
||||
CHECK(!etl::is_sufficiently_aligned<16>(buffer + 1));
|
||||
}
|
||||
|
||||
#if ETL_USING_CPP17
|
||||
//*************************************************************************
|
||||
TEST(test_ranges_uninitialized_copy_iterator_trivial)
|
||||
|
||||
@ -433,6 +433,52 @@ namespace
|
||||
CHECK_ARRAY_EQUAL(compare3.data(), router1.message3.data(), compare3.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Unregistering an active timer that is not at the tail of the active list
|
||||
// must preserve the absolute timeout of the timers that follow it.
|
||||
// Regression test: unregister_timer used to pass has_expired = true, which
|
||||
// skipped the delta adjustment of the next timer, making it fire early.
|
||||
//*************************************************************************
|
||||
TEST(message_timer_unregister_active_timer_preserves_following_timer_timing)
|
||||
{
|
||||
etl::message_timer<2> timer_controller;
|
||||
|
||||
// id1 (period 10) becomes the active list head, id2 (period 20) follows it.
|
||||
etl::timer::id::type id1 = timer_controller.register_timer(message1, router1, 10, etl::timer::mode::Single_Shot);
|
||||
etl::timer::id::type id2 = timer_controller.register_timer(message2, router1, 20, etl::timer::mode::Single_Shot);
|
||||
|
||||
router1.clear();
|
||||
|
||||
timer_controller.start(id1);
|
||||
timer_controller.start(id2);
|
||||
|
||||
timer_controller.enable(true);
|
||||
|
||||
ticks = 0;
|
||||
|
||||
const uint32_t step = 1UL;
|
||||
|
||||
while (ticks <= 30U)
|
||||
{
|
||||
if (ticks == 5U)
|
||||
{
|
||||
// id1 is the active head and still has a 'next' (id2).
|
||||
timer_controller.unregister_timer(id1);
|
||||
}
|
||||
|
||||
ticks += step;
|
||||
timer_controller.tick(step);
|
||||
}
|
||||
|
||||
// id1 was unregistered before it could fire.
|
||||
CHECK_EQUAL(0U, router1.message1.size());
|
||||
|
||||
// id2 must still fire at its original absolute time of 20, not earlier.
|
||||
std::vector<uint64_t> compare2 = {20ULL};
|
||||
CHECK_EQUAL(compare2.size(), router1.message2.size());
|
||||
CHECK_ARRAY_EQUAL(compare2.data(), router1.message2.data(), compare2.size());
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(message_timer_repeating_clear)
|
||||
{
|
||||
|
||||
@ -144,6 +144,25 @@ namespace
|
||||
CHECK(compare == hash);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pearson_reset)
|
||||
{
|
||||
std::string data("123456789");
|
||||
|
||||
etl::pearson<HASH_SIZE> pearson_calculator;
|
||||
|
||||
// Use the calculator, then reset it and reuse it for the same data.
|
||||
pearson_calculator.add(data.begin(), data.end());
|
||||
pearson_calculator.reset();
|
||||
pearson_calculator.add(data.begin(), data.end());
|
||||
|
||||
hash_t compare = Pearson_Compare(data);
|
||||
hash_t hash = pearson_calculator.value();
|
||||
|
||||
// A reset calculator must produce the same hash as a fresh one.
|
||||
CHECK(compare == hash);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_pearson_add_range_endian)
|
||||
{
|
||||
|
||||
@ -28,6 +28,7 @@ SOFTWARE.
|
||||
|
||||
#include "unit_test_framework.h"
|
||||
|
||||
#include "etl/memory.h"
|
||||
#include "etl/utility.h"
|
||||
|
||||
#include <algorithm>
|
||||
@ -315,6 +316,32 @@ namespace
|
||||
CHECK_EQUAL(1, c);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_exchange_unique_ptr)
|
||||
{
|
||||
etl::unique_ptr<int> p1(new int(1));
|
||||
etl::unique_ptr<int> p2 = etl::exchange(p1, nullptr);
|
||||
|
||||
CHECK_FALSE(p1);
|
||||
CHECK_TRUE(p2);
|
||||
CHECK_EQUAL(*p2, 1);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_exchange_unique_ptr_move_in)
|
||||
{
|
||||
etl::unique_ptr<int> a(new int(10));
|
||||
etl::unique_ptr<int> b(new int(20));
|
||||
|
||||
etl::unique_ptr<int> old = etl::exchange(a, etl::move(b));
|
||||
|
||||
CHECK_TRUE(old);
|
||||
CHECK_EQUAL(*old, 10);
|
||||
CHECK_TRUE(a);
|
||||
CHECK_EQUAL(*a, 20);
|
||||
CHECK_FALSE(b);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_as_const)
|
||||
{
|
||||
|
||||
@ -320,6 +320,106 @@ namespace
|
||||
bool moved_to;
|
||||
bool copied_to;
|
||||
};
|
||||
|
||||
//*********************************************
|
||||
// Trivially destructible, but non-copyable and non-movable.
|
||||
// Exercises the trivially-destructible (variadic_union) emplace path.
|
||||
struct TrivialNonMovable
|
||||
{
|
||||
TrivialNonMovable(int a_, int b_)
|
||||
: a(a_)
|
||||
, b(b_)
|
||||
{
|
||||
}
|
||||
|
||||
TrivialNonMovable(const TrivialNonMovable&) = delete;
|
||||
TrivialNonMovable(TrivialNonMovable&&) = delete;
|
||||
TrivialNonMovable& operator=(const TrivialNonMovable&) = delete;
|
||||
TrivialNonMovable& operator=(TrivialNonMovable&&) = delete;
|
||||
|
||||
int a;
|
||||
int b;
|
||||
};
|
||||
|
||||
//*********************************************
|
||||
// Non-trivially destructible, non-copyable and non-movable.
|
||||
// Exercises the non-trivially-destructible (uninitialized_buffer) emplace path,
|
||||
// including the initializer_list overload.
|
||||
struct NonTrivialNonMovable
|
||||
{
|
||||
NonTrivialNonMovable(int a_, int b_)
|
||||
: a(a_)
|
||||
, b(b_)
|
||||
, sum_of_list(0)
|
||||
{
|
||||
}
|
||||
|
||||
NonTrivialNonMovable(std::initializer_list<int> il, int b_)
|
||||
: a(0)
|
||||
, b(b_)
|
||||
, sum_of_list(0)
|
||||
{
|
||||
for (int value : il)
|
||||
{
|
||||
sum_of_list += value;
|
||||
}
|
||||
}
|
||||
|
||||
~NonTrivialNonMovable() // Makes it non-trivially destructible.
|
||||
{
|
||||
}
|
||||
|
||||
NonTrivialNonMovable(const NonTrivialNonMovable&) = delete;
|
||||
NonTrivialNonMovable(NonTrivialNonMovable&&) = delete;
|
||||
NonTrivialNonMovable& operator=(const NonTrivialNonMovable&) = delete;
|
||||
NonTrivialNonMovable& operator=(NonTrivialNonMovable&&) = delete;
|
||||
|
||||
int a;
|
||||
int b;
|
||||
int sum_of_list;
|
||||
};
|
||||
|
||||
// Trivially destructible but not assignable (deleted copy and move
|
||||
// assignment). Constructing an alternative of this type exercises the
|
||||
// trivially-destructible-suite path, which must begin the alternative's
|
||||
// lifetime with placement new rather than assigning into the union member.
|
||||
struct NonAssignable
|
||||
{
|
||||
explicit NonAssignable(int value_)
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
|
||||
NonAssignable(const NonAssignable&) = default;
|
||||
NonAssignable(NonAssignable&&) = default;
|
||||
NonAssignable& operator=(const NonAssignable&) = delete;
|
||||
NonAssignable& operator=(NonAssignable&&) = delete;
|
||||
|
||||
int value;
|
||||
};
|
||||
|
||||
//*********************************************
|
||||
// Trivially destructible type that overloads operator& (here by deleting it).
|
||||
// Constructing an alternative of this type must obtain the placement-new
|
||||
// target with etl::addressof, not the built-in unary operator&: taking the
|
||||
// address with & would be ill-formed (deleted) or, for an operator& that
|
||||
// returns something other than the object's address, would construct into the
|
||||
// wrong storage.
|
||||
struct NonAddressable
|
||||
{
|
||||
explicit NonAddressable(int value_)
|
||||
: value(value_)
|
||||
{
|
||||
}
|
||||
|
||||
NonAddressable(const NonAddressable&) = default;
|
||||
NonAddressable(NonAddressable&&) = default;
|
||||
|
||||
NonAddressable* operator&() = delete;
|
||||
const NonAddressable* operator&() const = delete;
|
||||
|
||||
int value;
|
||||
};
|
||||
} // namespace
|
||||
|
||||
// Moved from the top of the file otherwise clang has issues with
|
||||
@ -418,6 +518,48 @@ struct etl::is_copy_constructible<MoveableCopyable> : public etl::true_type
|
||||
template <>
|
||||
struct etl::is_move_constructible<MoveableCopyable> : public etl::true_type
|
||||
{
|
||||
};
|
||||
|
||||
//*************************
|
||||
template <>
|
||||
struct etl::is_copy_constructible<TrivialNonMovable> : public etl::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct etl::is_copy_constructible<NonAssignable> : public etl::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct etl::is_move_constructible<TrivialNonMovable> : public etl::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct etl::is_move_constructible<NonAssignable> : public etl::true_type
|
||||
{
|
||||
};
|
||||
|
||||
//*************************
|
||||
template <>
|
||||
struct etl::is_copy_constructible<NonTrivialNonMovable> : public etl::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct etl::is_copy_constructible<NonAddressable> : public etl::true_type
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct etl::is_move_constructible<NonTrivialNonMovable> : public etl::false_type
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct etl::is_move_constructible<NonAddressable> : public etl::true_type
|
||||
{
|
||||
};
|
||||
#endif
|
||||
|
||||
@ -732,6 +874,86 @@ namespace
|
||||
CHECK_EQUAL(text, etl::get<std::string>(variant_text_etl));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// emplace must construct the alternative in place from the forwarded
|
||||
// arguments, without requiring the alternative to be copyable or movable
|
||||
// (see issue #1493).
|
||||
TEST(test_emplace_non_movable_type)
|
||||
{
|
||||
// Trivially destructible suite (variadic_union storage).
|
||||
{
|
||||
etl::variant<int, TrivialNonMovable> v;
|
||||
|
||||
TrivialNonMovable& r1 = v.emplace<TrivialNonMovable>(3, 4);
|
||||
CHECK(etl::holds_alternative<TrivialNonMovable>(v));
|
||||
CHECK_EQUAL(3, r1.a);
|
||||
CHECK_EQUAL(4, r1.b);
|
||||
CHECK_EQUAL(&r1, &etl::get<TrivialNonMovable>(v));
|
||||
|
||||
// Emplace by index over the existing alternative.
|
||||
TrivialNonMovable& r2 = v.emplace<1>(5, 6);
|
||||
CHECK_EQUAL(5, r2.a);
|
||||
CHECK_EQUAL(6, r2.b);
|
||||
|
||||
// Switch to the trivial alternative and back again.
|
||||
v.emplace<int>(42);
|
||||
CHECK(etl::holds_alternative<int>(v));
|
||||
CHECK_EQUAL(42, etl::get<int>(v));
|
||||
|
||||
TrivialNonMovable& r3 = v.emplace<TrivialNonMovable>(7, 8);
|
||||
CHECK(etl::holds_alternative<TrivialNonMovable>(v));
|
||||
CHECK_EQUAL(7, r3.a);
|
||||
CHECK_EQUAL(8, r3.b);
|
||||
}
|
||||
|
||||
// Non-trivially destructible suite (uninitialized_buffer storage).
|
||||
{
|
||||
etl::variant<std::string, NonTrivialNonMovable> v;
|
||||
|
||||
NonTrivialNonMovable& r1 = v.emplace<NonTrivialNonMovable>(1, 2);
|
||||
CHECK(etl::holds_alternative<NonTrivialNonMovable>(v));
|
||||
CHECK_EQUAL(1, r1.a);
|
||||
CHECK_EQUAL(2, r1.b);
|
||||
CHECK_EQUAL(&r1, &etl::get<NonTrivialNonMovable>(v));
|
||||
|
||||
// Emplace by index over the existing alternative.
|
||||
NonTrivialNonMovable& r2 = v.emplace<1>(9, 10);
|
||||
CHECK_EQUAL(9, r2.a);
|
||||
CHECK_EQUAL(10, r2.b);
|
||||
|
||||
// Switch to the std::string alternative and back again.
|
||||
v.emplace<std::string>("Some Text");
|
||||
CHECK(etl::holds_alternative<std::string>(v));
|
||||
CHECK_EQUAL(std::string("Some Text"), etl::get<std::string>(v));
|
||||
|
||||
NonTrivialNonMovable& r3 = v.emplace<NonTrivialNonMovable>(11, 12);
|
||||
CHECK(etl::holds_alternative<NonTrivialNonMovable>(v));
|
||||
CHECK_EQUAL(11, r3.a);
|
||||
CHECK_EQUAL(12, r3.b);
|
||||
}
|
||||
}
|
||||
|
||||
#if ETL_HAS_INITIALIZER_LIST
|
||||
//*************************************************************************
|
||||
// The initializer_list emplace overloads must also construct in place,
|
||||
// without requiring the alternative to be copyable or movable (#1493).
|
||||
TEST(test_emplace_non_movable_type_with_initializer_list)
|
||||
{
|
||||
etl::variant<std::string, NonTrivialNonMovable> v;
|
||||
|
||||
// By type.
|
||||
NonTrivialNonMovable& r1 = v.emplace<NonTrivialNonMovable>({10, 20, 30}, 99);
|
||||
CHECK(etl::holds_alternative<NonTrivialNonMovable>(v));
|
||||
CHECK_EQUAL(60, r1.sum_of_list);
|
||||
CHECK_EQUAL(99, r1.b);
|
||||
|
||||
// By index.
|
||||
NonTrivialNonMovable& r2 = v.emplace<1>({1, 2, 3, 4}, 7);
|
||||
CHECK_EQUAL(10, r2.sum_of_list);
|
||||
CHECK_EQUAL(7, r2.b);
|
||||
}
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_copy_constructor)
|
||||
{
|
||||
@ -896,6 +1118,81 @@ namespace
|
||||
CHECK_EQUAL(D4("1", "2", "3", "4"), etl::get<D4>(variant_etl));
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Constructing an alternative must begin the object's lifetime with
|
||||
// placement new, not assign into the (inactive) union member. A trivially
|
||||
// destructible but non-assignable type would fail to compile (deleted
|
||||
// assignment) or invoke undefined behaviour if assignment were used.
|
||||
// (The trivially-destructible-suite union path is taken when the STL or the
|
||||
// compiler type-trait built-ins are available; otherwise construction goes
|
||||
// through the buffer path, which is exercised here just the same.)
|
||||
TEST(test_construct_trivially_destructible_non_assignable_type)
|
||||
{
|
||||
using variant_type = etl::variant<int, NonAssignable>;
|
||||
|
||||
// Emplace by type.
|
||||
variant_type variant_by_type;
|
||||
variant_by_type.emplace<NonAssignable>(42);
|
||||
CHECK(etl::holds_alternative<NonAssignable>(variant_by_type));
|
||||
CHECK_EQUAL(42, etl::get<NonAssignable>(variant_by_type).value);
|
||||
|
||||
// Emplace by index.
|
||||
variant_type variant_by_index;
|
||||
variant_by_index.emplace<1>(43);
|
||||
CHECK(etl::holds_alternative<NonAssignable>(variant_by_index));
|
||||
CHECK_EQUAL(43, etl::get<NonAssignable>(variant_by_index).value);
|
||||
|
||||
// Assignment from a value (operator=(T&&)).
|
||||
variant_type variant_by_assignment;
|
||||
variant_by_assignment = NonAssignable(44);
|
||||
CHECK(etl::holds_alternative<NonAssignable>(variant_by_assignment));
|
||||
CHECK_EQUAL(44, etl::get<NonAssignable>(variant_by_assignment).value);
|
||||
|
||||
// Re-emplace over an already-active alternative (do_destroy then
|
||||
// placement new into the same union member).
|
||||
variant_by_assignment.emplace<NonAssignable>(45);
|
||||
CHECK(etl::holds_alternative<NonAssignable>(variant_by_assignment));
|
||||
CHECK_EQUAL(45, etl::get<NonAssignable>(variant_by_assignment).value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
// Constructing an alternative must take the raw storage address for
|
||||
// placement new via etl::addressof, not the built-in unary operator&.
|
||||
// NonAddressable deletes operator&, so the old `&variadic_union_get(...)`
|
||||
// form would be ill-formed. Read-back uses by-index etl::get (which returns
|
||||
// a reference) and the reference returned by emplace, so it never invokes
|
||||
// operator&. (The trivially-destructible-suite union path is taken when the
|
||||
// STL or the compiler built-ins are available; otherwise construction goes
|
||||
// through the buffer path, which is exercised here just the same.)
|
||||
TEST(test_construct_type_with_overloaded_address_of_operator)
|
||||
{
|
||||
using variant_type = etl::variant<int, NonAddressable>;
|
||||
|
||||
// Emplace by type (returns a reference, so no operator& on read-back).
|
||||
variant_type variant_by_type;
|
||||
NonAddressable& by_type = variant_by_type.emplace<NonAddressable>(42);
|
||||
CHECK(etl::holds_alternative<NonAddressable>(variant_by_type));
|
||||
CHECK_EQUAL(42, by_type.value);
|
||||
CHECK_EQUAL(42, etl::get<1>(variant_by_type).value);
|
||||
|
||||
// Emplace by index.
|
||||
variant_type variant_by_index;
|
||||
variant_by_index.emplace<1>(43);
|
||||
CHECK(etl::holds_alternative<NonAddressable>(variant_by_index));
|
||||
CHECK_EQUAL(43, etl::get<1>(variant_by_index).value);
|
||||
|
||||
// Assignment from a value (operator=(T&&)).
|
||||
variant_type variant_by_assignment;
|
||||
variant_by_assignment = NonAddressable(44);
|
||||
CHECK(etl::holds_alternative<NonAddressable>(variant_by_assignment));
|
||||
CHECK_EQUAL(44, etl::get<1>(variant_by_assignment).value);
|
||||
|
||||
// Re-emplace over an already-active alternative.
|
||||
variant_by_assignment.emplace<1>(45);
|
||||
CHECK(etl::holds_alternative<NonAddressable>(variant_by_assignment));
|
||||
CHECK_EQUAL(45, etl::get<1>(variant_by_assignment).value);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_variant_accept_visitor)
|
||||
{
|
||||
@ -1007,6 +1304,7 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
TEST(test_const_variant_accept_visitor)
|
||||
{
|
||||
struct Visitor : public etl::visitor<const char&, const int&, const std::string&>
|
||||
@ -1057,8 +1355,10 @@ namespace
|
||||
const_variant_etl3.accept(visitor);
|
||||
CHECK_EQUAL("3", visitor.result_s);
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
//*************************************************************************
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
TEST(test_const_variant_accept_visitor_deprecated)
|
||||
{
|
||||
struct Visitor : public etl::visitor<char, int, const std::string&>
|
||||
@ -1111,6 +1411,7 @@ namespace
|
||||
const_variant_etl3.accept(visitor);
|
||||
CHECK_EQUAL("3", visitor.result_s);
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
//*************************************************************************
|
||||
TEST(test_variant_accept_functor_with_functor_class)
|
||||
@ -1218,6 +1519,7 @@ namespace
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
TEST(test_const_variant_accept_functor_with_functor_class)
|
||||
{
|
||||
struct Visitor
|
||||
@ -1268,8 +1570,10 @@ namespace
|
||||
const_variant_etl3.accept(visitor);
|
||||
CHECK_EQUAL("3", visitor.result_s);
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
//*************************************************************************
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
TEST(test_const_variant_accept_functor_with_functor_class_deprecated)
|
||||
{
|
||||
struct Visitor
|
||||
@ -1320,6 +1624,7 @@ namespace
|
||||
const_variant_etl3.accept(visitor);
|
||||
CHECK_EQUAL("3", visitor.result_s);
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
//*************************************************************************
|
||||
#if ETL_USING_CPP17
|
||||
@ -1389,7 +1694,8 @@ namespace
|
||||
CHECK_EQUAL("3", result_s);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
//*************************************************************************
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
TEST(test_const_variant_accept_functor_with_overload)
|
||||
{
|
||||
char result_c;
|
||||
@ -1416,8 +1722,10 @@ namespace
|
||||
const_variant_etl3.accept(visitor);
|
||||
CHECK_EQUAL("3", result_s);
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
|
||||
//*************************************************************************
|
||||
//*************************************************************************
|
||||
#include "etl/private/diagnostic_uninitialized_push.h"
|
||||
TEST(test_const_variant_accept_functor_with_overload_deprecated)
|
||||
{
|
||||
char result_c;
|
||||
@ -1444,6 +1752,7 @@ namespace
|
||||
const_variant_etl3.accept(visitor);
|
||||
CHECK_EQUAL("3", result_s);
|
||||
}
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
#endif
|
||||
|
||||
//*************************************************************************
|
||||
|
||||
@ -1077,13 +1077,15 @@ namespace
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::iterator const_cdi = compare_data.begin() + 2U;
|
||||
int compare_value = *(const_cdi + 1U);
|
||||
Compare_Data::iterator cdi = compare_data.erase(const_cdi);
|
||||
Compare_Data::iterator const_cdi = compare_data.begin() + 2U;
|
||||
#include "etl/private/diagnostic_null_dereference_push.h"
|
||||
int compare_value = compare_data[3];
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
Compare_Data::iterator cdi = compare_data.erase(const_cdi);
|
||||
CHECK_EQUAL(compare_value, *cdi);
|
||||
|
||||
Data::iterator const_di = data.begin() + 2U;
|
||||
int data_value = *(const_di + 1U);
|
||||
int data_value = data[3];
|
||||
Data::iterator di = data.erase(const_di);
|
||||
CHECK_EQUAL(data_value, *di);
|
||||
|
||||
@ -1108,13 +1110,15 @@ namespace
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::const_iterator const_cdi = compare_data.cbegin() + 2U;
|
||||
int compare_value = *(const_cdi + 1U);
|
||||
Compare_Data::iterator cdi = compare_data.erase(const_cdi);
|
||||
Compare_Data::const_iterator const_cdi = compare_data.cbegin() + 2U;
|
||||
#include "etl/private/diagnostic_null_dereference_push.h"
|
||||
int compare_value = compare_data[3];
|
||||
#include "etl/private/diagnostic_pop.h"
|
||||
Compare_Data::iterator cdi = compare_data.erase(const_cdi);
|
||||
CHECK_EQUAL(compare_value, *cdi);
|
||||
|
||||
Data::const_iterator const_di = data.cbegin() + 2U;
|
||||
int data_value = *(const_di + 1U);
|
||||
int data_value = data[3];
|
||||
Data::iterator di = data.erase(const_di);
|
||||
CHECK_EQUAL(data_value, *di);
|
||||
|
||||
@ -1139,15 +1143,9 @@ namespace
|
||||
Compare_Data compare_data(initial_data.begin(), initial_data.end());
|
||||
Data data(initial_data.begin(), initial_data.end());
|
||||
|
||||
Compare_Data::const_iterator const_cdi = compare_data.cbegin() + 2U;
|
||||
int compare_value = *(const_cdi + 2U);
|
||||
Compare_Data::iterator cdi = compare_data.erase(const_cdi, const_cdi + 2U);
|
||||
CHECK_EQUAL(compare_value, *cdi);
|
||||
compare_data.erase(compare_data.begin() + 2, compare_data.begin() + 4);
|
||||
|
||||
Data::const_iterator const_di = data.cbegin() + 2U;
|
||||
int data_value = *(const_di + 2U);
|
||||
Data::iterator di = data.erase(const_di, const_di + 2U);
|
||||
CHECK_EQUAL(data_value, *di);
|
||||
data.erase(data.begin() + 2, data.begin() + 4);
|
||||
|
||||
CHECK_EQUAL(compare_data.size(), data.size());
|
||||
|
||||
|
||||
@ -46,6 +46,8 @@ namespace
|
||||
int buffer4[SIZE];
|
||||
int buffer5[SIZE];
|
||||
|
||||
int bufferLarger[SIZE + 1];
|
||||
|
||||
SUITE(test_vector_external_buffer)
|
||||
{
|
||||
typedef etl::vector_ext<int> Data;
|
||||
@ -183,6 +185,14 @@ namespace
|
||||
CHECK(data2 != data);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_copy_construct_from_larger_vector_ext)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end(), bufferLarger, SIZE + 1);
|
||||
data.resize(SIZE + 1, 0);
|
||||
CHECK_THROW(Data data2(data, buffer1, SIZE), etl::vector_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_move_constructor)
|
||||
{
|
||||
@ -193,6 +203,14 @@ namespace
|
||||
CHECK(data2 != data);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_move_construct_from_larger_vector_ext)
|
||||
{
|
||||
Data data(initial_data.begin(), initial_data.end(), bufferLarger, SIZE + 1);
|
||||
data.resize(SIZE + 1, 0);
|
||||
CHECK_THROW(Data data2(etl::move(data), buffer1, SIZE), etl::vector_full);
|
||||
}
|
||||
|
||||
//*************************************************************************
|
||||
TEST_FIXTURE(SetupFixture, test_assignment)
|
||||
{
|
||||
|
||||
1321
test/test_vector_function_pointer.cpp
Normal file
1321
test/test_vector_function_pointer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1301
test/test_vector_function_pointer_external_buffer.cpp
Normal file
1301
test/test_vector_function_pointer_external_buffer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1330
test/test_vector_member_function_pointer.cpp
Normal file
1330
test/test_vector_member_function_pointer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
1329
test/test_vector_member_function_pointer_external_buffer.cpp
Normal file
1329
test/test_vector_member_function_pointer_external_buffer.cpp
Normal file
File diff suppressed because it is too large
Load Diff
@ -3700,7 +3700,6 @@
|
||||
<ClInclude Include="..\..\include\etl\mutex\mutex_std.h" />
|
||||
<ClInclude Include="..\..\include\etl\packet.h" />
|
||||
<ClInclude Include="..\..\include\etl\permutations.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\ivectorpointer.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\minmax_pop.h" />
|
||||
<ClInclude Include="..\..\include\etl\private\minmax_push.h" />
|
||||
<ClInclude Include="..\..\include\etl\profiles\arduino_arm.h" />
|
||||
@ -10219,6 +10218,7 @@
|
||||
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug MSVC C++20 - Force C++03 - No virtual messages|Win32'">true</ExcludedFromBuild>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_algorithm.cpp" />
|
||||
<ClCompile Include="..\test_algorithm_ranges.cpp" />
|
||||
<ClCompile Include="..\test_alignment.cpp" />
|
||||
<ClCompile Include="..\test_atomic.cpp" />
|
||||
<ClCompile Include="..\test_base64_RFC2152_decoder.cpp" />
|
||||
@ -11462,6 +11462,10 @@
|
||||
<ClCompile Include="..\test_variant_pool.cpp" />
|
||||
<ClCompile Include="..\test_vector.cpp" />
|
||||
<ClCompile Include="..\test_vector_external_buffer.cpp" />
|
||||
<ClCompile Include="..\test_vector_function_pointer.cpp" />
|
||||
<ClCompile Include="..\test_vector_function_pointer_external_buffer.cpp" />
|
||||
<ClCompile Include="..\test_vector_member_function_pointer.cpp" />
|
||||
<ClCompile Include="..\test_vector_member_function_pointer_external_buffer.cpp" />
|
||||
<ClCompile Include="..\test_vector_non_trivial.cpp" />
|
||||
<ClCompile Include="..\test_vector_pointer.cpp" />
|
||||
<ClCompile Include="..\test_vector_pointer_external_buffer.cpp" />
|
||||
@ -11497,19 +11501,32 @@
|
||||
<None Include="..\..\.clang-format" />
|
||||
<None Include="..\..\.coderabbit.yaml" />
|
||||
<None Include="..\..\.gitattributes" />
|
||||
<None Include="..\..\.github\workflows\bazel-gcc-c++23-no-stl.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-c++11.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-c++14.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-c++17.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-c++20.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-c++23.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-c++26.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-format.yaml" />
|
||||
<None Include="..\..\.github\workflows\clang-format_update.yaml" />
|
||||
<None Include="..\..\.github\workflows\clang-syntax-checks.yml" />
|
||||
<None Include="..\..\.github\workflows\clang-tidy.yaml" />
|
||||
<None Include="..\..\.github\workflows\coverage.yml" />
|
||||
<None Include="..\..\.github\workflows\deploy-etl-documentation.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++11.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++14.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++17.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++20.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-armhf.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-i386.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-powerpc.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-riscv64.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-s390x.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++23.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-c++26.yml" />
|
||||
<None Include="..\..\.github\workflows\generator.yml" />
|
||||
<None Include="..\..\.github\workflows\meson-gcc-c++23-no-stl.yml" />
|
||||
<None Include="..\..\.github\workflows\msvc.yml" />
|
||||
<None Include="..\..\.github\workflows\gcc-syntax-checks.yml" />
|
||||
<None Include="..\..\.github\workflows\platformio-update.yml" />
|
||||
|
||||
@ -597,9 +597,6 @@
|
||||
<ClInclude Include="..\..\include\etl\bit_stream.h">
|
||||
<Filter>ETL\Utilities</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\private\ivectorpointer.h">
|
||||
<Filter>ETL\Private</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\private\minmax_pop.h">
|
||||
<Filter>ETL\Private</Filter>
|
||||
</ClInclude>
|
||||
@ -1569,6 +1566,9 @@
|
||||
<ClInclude Include="..\..\include\etl\generators\message_router_cpp03_generator.h">
|
||||
<Filter>ETL\Messaging\Generators</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\include\etl\format.h">
|
||||
<Filter>UnitTest++\Header Files</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\test_string_char.cpp">
|
||||
@ -2075,6 +2075,9 @@
|
||||
<ClCompile Include="..\test_algorithm.cpp">
|
||||
<Filter>Tests\Algorithms</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_algorithm_ranges.cpp">
|
||||
<Filter>Tests\Algorithms</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_correlation.cpp">
|
||||
<Filter>Tests\Algorithms</Filter>
|
||||
</ClCompile>
|
||||
@ -3815,6 +3818,18 @@
|
||||
<ClCompile Include="..\test_closure_with_inplace_function.cpp">
|
||||
<Filter>Tests\Callbacks & Delegates</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_vector_function_pointer.cpp">
|
||||
<Filter>Tests\Containers</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_vector_member_function_pointer.cpp">
|
||||
<Filter>Tests\Containers</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_vector_function_pointer_external_buffer.cpp">
|
||||
<Filter>Tests\Containers</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\test_vector_member_function_pointer_external_buffer.cpp">
|
||||
<Filter>Tests\Containers</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="..\..\library.properties">
|
||||
@ -3999,6 +4014,45 @@
|
||||
<None Include="..\run-coverage.sh">
|
||||
<Filter>Tests\Scripts</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\bazel-gcc-c++23-no-stl.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\clang-c++26.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\clang-tidy.yaml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\coverage.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\deploy-etl-documentation.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-armhf.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-i386.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-powerpc.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-riscv64.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\gcc-c++23-s390x.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\gcc-c++26.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\generator.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
<None Include="..\..\.github\workflows\meson-gcc-c++23-no-stl.yml">
|
||||
<Filter>Resource Files\CI\Github</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Text Include="..\..\support\Release notes.txt">
|
||||
|
||||
@ -1 +1 @@
|
||||
20.48.0
|
||||
20.48.1
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user