From 213d6616500129c559b554ffc0797942bc95d38b Mon Sep 17 00:00:00 2001 From: Ziad Mostafa Date: Mon, 20 Feb 2023 13:35:12 +0100 Subject: [PATCH] iox-#1900 Refactor byte_t to be a distinct type Signed-off-by: Ziad Mostafa --- doc/website/release-notes/iceoryx-unreleased.md | 13 +++++++++++++ iceoryx_hoofs/README.md | 2 +- .../container/include/iox/uninitialized_array.hpp | 4 ++-- .../include/iox/detail/storable_function.hpp | 2 +- .../internal/posix_wrapper/shared_memory_object.hpp | 1 - .../include/iceoryx_hoofs/iceoryx_hoofs_types.hpp | 5 +++-- .../primitives/include/iox/iceoryx_hoofs_types.hpp | 5 ++++- .../include/iox/detail/variant_internal.hpp | 1 - iceoryx_hoofs/vocabulary/include/iox/optional.hpp | 2 +- iceoryx_hoofs/vocabulary/include/iox/variant.hpp | 3 ++- 10 files changed, 27 insertions(+), 11 deletions(-) diff --git a/doc/website/release-notes/iceoryx-unreleased.md b/doc/website/release-notes/iceoryx-unreleased.md index c5fd40effa..1eeb183971 100644 --- a/doc/website/release-notes/iceoryx-unreleased.md +++ b/doc/website/release-notes/iceoryx-unreleased.md @@ -119,6 +119,7 @@ - Remove `algorithm::uniqueMergeSortedContainers` from `algorithm.hpp` - Move `std::string` conversion function to `iceoryx_dust` [\#1612](https://github.com/eclipse-iceoryx/iceoryx/issues/1612) - The posix call `unlink` is directly used in `UnixDomainSocket` [\#1622](https://github.com/eclipse-iceoryx/iceoryx/issues/1622) +- Make iox::byte_t a distinct type [\#1900](https://github.com/eclipse-iceoryx/iceoryx/issues/1900) **Workflow:** @@ -1033,3 +1034,15 @@ // after iox::access_rights foo { iox::perms::owner_all | iox::perms::group_read }; ``` +47. Renaming `byte_t` to `byte` + `byte` is not a simple type alias, now it is a distinct type like c++17 `std::byte`. + The type `byte` does not support any arithmetic operations nor has member functions. + + ```cpp + //before + iox::byte_t m_size; + + //after + iox::byte m_size; + ``` + diff --git a/iceoryx_hoofs/README.md b/iceoryx_hoofs/README.md index a225680e8f..dc231640da 100644 --- a/iceoryx_hoofs/README.md +++ b/iceoryx_hoofs/README.md @@ -83,7 +83,7 @@ The module structure is a logical grouping. It is replicated for `concurrent` an | class | internal | description | |:---------------------:|:--------:|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |`type_traits` | | Extended support for evaluating types on compile-time. | -|`types` | | Declares essential building block types like `byte_t`. | +|`types` | | Declares essential building block types like `byte`. | |`attributes` | | C++17 and C++20 attributes are sometimes available through compiler extensions. The attribute macros defined in here (like `IOX_FALLTHROUGH`, `IOX_MAYBE_UNUSED` ... ) make sure that we are able to use them if the compiler supports it. | |`algorithm` | | Implements `min` and `max` for an arbitrary number of values of the same type. For instance `min(1,2,3,4,5);` | |`size` | | Helper functions to determine the size in generic ways | diff --git a/iceoryx_hoofs/container/include/iox/uninitialized_array.hpp b/iceoryx_hoofs/container/include/iox/uninitialized_array.hpp index bdf87fb2ef..64b3d65f27 100644 --- a/iceoryx_hoofs/container/include/iox/uninitialized_array.hpp +++ b/iceoryx_hoofs/container/include/iox/uninitialized_array.hpp @@ -37,7 +37,7 @@ struct ZeroedBuffer // AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays) - byte_t data[sizeof(ElementType)]; + byte data[sizeof(ElementType)]; }; // AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used @@ -57,7 +57,7 @@ struct NonZeroedBuffer // AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays) - byte_t data[sizeof(ElementType)]; + byte data[sizeof(ElementType)]; }; // AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used diff --git a/iceoryx_hoofs/functional/include/iox/detail/storable_function.hpp b/iceoryx_hoofs/functional/include/iox/detail/storable_function.hpp index e575ebb3ee..a462707ef0 100644 --- a/iceoryx_hoofs/functional/include/iox/detail/storable_function.hpp +++ b/iceoryx_hoofs/functional/include/iox/detail/storable_function.hpp @@ -154,7 +154,7 @@ class storable_function> final // AXIVION Next Construct AutosarC++19_03-A18.1.1 : safe access is guaranteed since the c-array is wrapped inside the storable_function // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays) - byte_t m_storage[Capacity]; // storage for the callable + byte m_storage[Capacity]; // storage for the callable void* m_callable{nullptr}; // pointer to stored type-erased callable ReturnType (*m_invoker)(void*, Args&&...){nullptr}; // indirection to invoke the stored callable, // nullptr if no callable is stored diff --git a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp index 9ff0587536..8adb48be47 100644 --- a/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp +++ b/iceoryx_hoofs/include/iceoryx_hoofs/internal/posix_wrapper/shared_memory_object.hpp @@ -31,7 +31,6 @@ namespace iox { namespace posix { -using byte_t = uint8_t; enum class SharedMemoryObjectError { diff --git a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/iceoryx_hoofs_types.hpp b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/iceoryx_hoofs_types.hpp index dc725fa00e..18be176f36 100644 --- a/iceoryx_hoofs/legacy/include/iceoryx_hoofs/iceoryx_hoofs_types.hpp +++ b/iceoryx_hoofs/legacy/include/iceoryx_hoofs/iceoryx_hoofs_types.hpp @@ -25,8 +25,9 @@ namespace iox /// [[deprecated("Deprecated in 3.0, removed in 4.0, please include 'iox/iceoryx_hoofs_types.hpp' instead")]] namespace cxx { -/// @deprecated use 'iox::byte_t' instead of 'iox::cxx::byte_t' -using iox::byte_t; +/// @deprecated use `iox::byte` instead of `iox::cxx::byte_t` +using byte_t = byte; + } // namespace cxx namespace log { diff --git a/iceoryx_hoofs/primitives/include/iox/iceoryx_hoofs_types.hpp b/iceoryx_hoofs/primitives/include/iox/iceoryx_hoofs_types.hpp index d1fed5d69d..6dd7477864 100644 --- a/iceoryx_hoofs/primitives/include/iox/iceoryx_hoofs_types.hpp +++ b/iceoryx_hoofs/primitives/include/iox/iceoryx_hoofs_types.hpp @@ -24,7 +24,10 @@ namespace iox { -using byte_t = uint8_t; + +enum class byte : uint8_t +{ +}; // AXIVION Next Construct AutosarC++19_03-M2.10.1 : log is a sensible namespace for a logger; furthermore it is in the // iox namespace and when used as function the compiler will complain diff --git a/iceoryx_hoofs/vocabulary/include/iox/detail/variant_internal.hpp b/iceoryx_hoofs/vocabulary/include/iox/detail/variant_internal.hpp index 63778e13f5..105ac0a970 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/detail/variant_internal.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/detail/variant_internal.hpp @@ -52,7 +52,6 @@ struct is_in_place_type> : std::true_type { }; -using byte_t = uint8_t; template struct does_contain_type { diff --git a/iceoryx_hoofs/vocabulary/include/iox/optional.hpp b/iceoryx_hoofs/vocabulary/include/iox/optional.hpp index 52398dd742..887d5fd62f 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/optional.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/optional.hpp @@ -237,7 +237,7 @@ class optional final : public FunctionalInterface, T, void> // AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used // NOLINTNEXTLINE(hicpp-avoid-c-arrays, cppcoreguidelines-avoid-c-arrays) - byte_t data[sizeof(T)]; + byte data[sizeof(T)]; }; // AXIVION Next Construct AutosarC++19_03-A1.1.1 : object size depends on template parameter and has to be taken care of at the specific template instantiation element_t m_data; diff --git a/iceoryx_hoofs/vocabulary/include/iox/variant.hpp b/iceoryx_hoofs/vocabulary/include/iox/variant.hpp index 14e2ef8146..aa8d540618 100644 --- a/iceoryx_hoofs/vocabulary/include/iox/variant.hpp +++ b/iceoryx_hoofs/vocabulary/include/iox/variant.hpp @@ -19,6 +19,7 @@ #include "iox/algorithm.hpp" #include "iox/detail/variant_internal.hpp" +#include "iox/iceoryx_hoofs_types.hpp" #include #include @@ -265,7 +266,7 @@ class variant final // AXIVION Next Construct AutosarC++19_03-M0.1.3 : data provides the actual storage and is accessed via m_storage since &m_storage.data = &m_storage // AXIVION Next Construct AutosarC++19_03-A18.1.1 : safe access is guaranteed since the c-array is wrapped inside the variant class // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays) - internal::byte_t data[TYPE_SIZE]; + iox::byte data[TYPE_SIZE]; }; storage_t m_storage{}; uint64_t m_type_index{INVALID_VARIANT_INDEX};