iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
uninitialized_array.hpp
Go to the documentation of this file.
1// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2// Copyright (c) 2021 - 2022 by Apex.AI Inc. All rights reserved.
3// Copyright (c) 2025 Contributors to the Eclipse Foundation
4//
5// See the NOTICE file(s) distributed with this work for additional
6// information regarding copyright ownership.
7//
8// This program and the accompanying materials are made available under the
9// terms of the Apache Software License 2.0 which is available at
10// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
11// which is available at https://opensource.org/licenses/MIT.
12//
13// SPDX-License-Identifier: Apache-2.0 OR MIT
14
15#ifndef IOX2_BB_CONTAINER_UNINITIALIZED_ARRAY_HPP
16#define IOX2_BB_CONTAINER_UNINITIALIZED_ARRAY_HPP
17
18#include <cstdint>
19
20namespace iox2 {
21namespace legacy {
25// AXIVION DISABLE STYLE AutosarC++19_03-A9.6.1 : False positive. Used ElementTypes have defined size.
26template <typename ElementType, uint64_t Capacity>
28 struct alignas(ElementType) element_t {
29 // AXIVION Next Construct AutosarC++19_03-M0.1.3 : the field is intentionally unused and serves as a mean to provide memory
30 // 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
31 // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used
32 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
33 char data[sizeof(ElementType)];
34 };
35 // 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
36 // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used
37 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
38 element_t value[Capacity] {};
39};
40
44template <typename ElementType, uint64_t Capacity>
46 struct alignas(ElementType) element_t {
47 // AXIVION Next Construct AutosarC++19_03-M0.1.3 : the field is intentionally unused and serves as a mean to provide memory
48 // 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
49 // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used
50 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
51 char data[sizeof(ElementType)];
52 };
53 // 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
54 // AXIVION Next Construct AutosarC++19_03-A18.1.1 : required as low level building block, encapsulated in abstraction and not directly used
55 // NOLINTNEXTLINE(cppcoreguidelines-avoid-c-arrays, hicpp-avoid-c-arrays)
56 element_t value[Capacity];
57};
58// AXIVION ENABLE STYLE AutosarC++19_03-A9.6.1
66// AXIVION Next Construct AutosarC++19_03-A9.6.1 : type contains a single member that is a byte array whos size is defined by ElementType and Capacity
67template <typename ElementType, uint64_t Capacity, template <typename, uint64_t> class Buffer = NonZeroedBuffer>
68class UninitializedArray final {
69 static_assert(Capacity > 0U, "The size of the UninitializedArray must be greater than 0!");
70
71 public:
72 using value_type = ElementType;
73 using iterator = ElementType*;
74 using const_iterator = const ElementType*;
75
76 // The (empty) user-defined constructor is required.
77 // Use of "= default" leads to value-initialization of class members.
78 // AXIVION Next Construct AutosarC++19_03-A12.6.1 : This is a low-level building block which is supposed to provide uninitialized memory
79 // NOLINTNEXTLINE(hicpp-use-equals-default)
80 constexpr UninitializedArray() noexcept { };
86
91 constexpr ElementType& operator[](const uint64_t index) noexcept;
92
97 constexpr const ElementType& operator[](const uint64_t index) const noexcept;
98
100 iterator begin() noexcept;
101
103 const_iterator begin() const noexcept;
104
106 iterator end() noexcept;
107
109 const_iterator end() const noexcept;
110
112 static constexpr uint64_t capacity() noexcept;
113
114 private:
115 // 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
116 Buffer<ElementType, Capacity> m_buffer;
117};
118
124template <typename T, uint64_t N, template <typename, uint64_t> class Buffer>
125constexpr uint64_t size(const UninitializedArray<T, N, Buffer>&) noexcept;
126
127} // namespace legacy
128} // namespace iox2
129
130#include "iox2/legacy/detail/uninitialized_array.inl"
131
132#endif // IOX2_BB_CONTAINER_UNINITIALIZED_ARRAY_HPP
Wrapper class for a C-style array of type ElementType and size Capacity. Per default it is uninitiali...
UninitializedArray & operator=(UninitializedArray &&)=delete
constexpr ElementType & operator[](const uint64_t index) noexcept
returns a reference to the element stored at index
iterator begin() noexcept
returns an iterator to the beginning of the UninitializedArray
UninitializedArray(const UninitializedArray &)=delete
UninitializedArray(UninitializedArray &&)=delete
UninitializedArray & operator=(const UninitializedArray &)=delete
constexpr const ElementType & operator[](const uint64_t index) const noexcept
returns a const reference to the element stored at index
struct used as policy parameter in UninitializedArray to wrap an uninitialized array
struct used as policy parameter in UninitializedArray to wrap an array with all elements zeroed