iceoryx_doc  1.0.1
buffer.hpp
1 // Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // SPDX-License-Identifier: Apache-2.0
16 
17 #ifndef IOX_UTILS_CONCURRENT_LOCKFREE_QUEUE_BUFFER_HPP
18 #define IOX_UTILS_CONCURRENT_LOCKFREE_QUEUE_BUFFER_HPP
19 
20 #include <stdint.h>
21 
22 namespace iox
23 {
24 namespace concurrent
25 {
26 // remark: we can add more functionality (policies for cache line size, redzoning)
27 
28 template <typename ElementType, uint64_t Capacity, typename index_t = uint64_t>
29 class Buffer
30 {
31  public:
32  Buffer() = default;
33  ~Buffer() = default;
34 
35  Buffer(const Buffer&) = delete;
36  Buffer(Buffer&&) = delete;
37  Buffer& operator=(const Buffer&) = delete;
38  Buffer& operator=(Buffer&&) = delete;
39 
40  ElementType& operator[](const index_t index) noexcept;
41 
42  const ElementType& operator[](const index_t index) const noexcept;
43 
44  ElementType* ptr(const index_t index) noexcept;
45 
46  const ElementType* ptr(const index_t index) const noexcept;
47 
48  uint64_t capacity() const noexcept;
49 
50  private:
51  using byte_t = uint8_t;
52 
53  alignas(ElementType) byte_t m_buffer[Capacity * sizeof(ElementType)];
54 
55  ElementType* toPtr(index_t index) const noexcept;
56 };
57 
58 } // namespace concurrent
59 } // namespace iox
60 
61 #include "buffer.inl"
62 
63 #endif // IOX_UTILS_CONCURRENT_LOCKFREE_QUEUE_BUFFER_HPP
Definition: buffer.hpp:30
building block to easily create free function for logging in a library context
Definition: lockfree_queue.hpp:28