iceoryx_posh 2.0.3
generic_memory_block.hpp
1// Copyright (c) 2020 by Robert Bosch GmbH. All rights reserved.
2// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15//
16// SPDX-License-Identifier: Apache-2.0
17#ifndef IOX_POSH_ROUDI_MEMORY_GENERIC_MEMORY_BLOCK_HPP
18#define IOX_POSH_ROUDI_MEMORY_GENERIC_MEMORY_BLOCK_HPP
19
20#include "iceoryx_posh/roudi/memory/memory_block.hpp"
21
22#include "iceoryx_hoofs/cxx/optional.hpp"
23
24#include <cstdint>
25
26namespace iox
27{
28namespace roudi
29{
31template <typename T>
32class GenericMemoryBlock final : public MemoryBlock
33{
34 friend class MemoryProvider;
35
36 public:
37 GenericMemoryBlock() noexcept = default;
38 ~GenericMemoryBlock() noexcept;
39
42 GenericMemoryBlock& operator=(const GenericMemoryBlock&) = delete;
43 GenericMemoryBlock& operator=(GenericMemoryBlock&&) = delete;
44
47 uint64_t size() const noexcept override;
48
51 uint64_t alignment() const noexcept override;
52
57 template <typename... Targs>
58 cxx::optional<T*> emplace(Targs&&... args) noexcept;
59
62 cxx::optional<T*> value() const noexcept;
63
64 protected:
67 void destroy() noexcept override;
68
69 private:
70 T* m_value{nullptr};
71};
72
73} // namespace roudi
74} // namespace iox
75
76#include "iceoryx_posh/internal/roudi/memory/generic_memory_block.inl"
77
78#endif // IOX_POSH_ROUDI_MEMORY_GENERIC_MEMORY_BLOCK_HPP
The GenericMemoryBlock is an implementation of a MemoryBlock for a common use case.
Definition: generic_memory_block.hpp:33
cxx::optional< T * > emplace(Targs &&... args) noexcept
A new element is constructed by forwarding the arguments to the constructor of T. If the MemoryBlock ...
uint64_t size() const noexcept override
This function provides the size of the required memory for the underlying data. It is needed for the ...
uint64_t alignment() const noexcept override
This function provides the alignment of the memory for the underlying data. This information is neede...
void destroy() noexcept override
The MemoryProvider calls this either when MemoryProvider::destroy is called or in its destructor.
cxx::optional< T * > value() const noexcept
This function enables the access to the underlying type.
The MemoryBlock is a container for general purpose memory. It is used to request some memory from a M...
Definition: memory_block.hpp:34
This class creates memory which is requested by the MemoryBlocks. Once the memory is available,...
Definition: memory_provider.hpp:69