iceoryx_doc  1.0.1
generic_memory_block.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 #ifndef IOX_POSH_ROUDI_MEMORY_GENERIC_MEMORY_BLOCK_HPP
17 #define IOX_POSH_ROUDI_MEMORY_GENERIC_MEMORY_BLOCK_HPP
18 
19 #include "iceoryx_posh/roudi/memory/memory_block.hpp"
20 
21 #include "iceoryx_utils/cxx/optional.hpp"
22 
23 #include <cstdint>
24 
25 namespace iox
26 {
27 namespace roudi
28 {
30 template <typename T>
31 class GenericMemoryBlock final : public MemoryBlock
32 {
33  friend class MemoryProvider;
34 
35  public:
36  GenericMemoryBlock() noexcept = default;
37  ~GenericMemoryBlock() noexcept;
38 
39  GenericMemoryBlock(const GenericMemoryBlock&) = delete;
41  GenericMemoryBlock& operator=(const GenericMemoryBlock&) = delete;
42  GenericMemoryBlock& operator=(GenericMemoryBlock&&) = delete;
43 
46  uint64_t size() const noexcept override;
47 
50  uint64_t alignment() const noexcept override;
51 
53  void destroy() noexcept override;
54 
59  template <typename... Targs>
60  cxx::optional<T*> emplace(Targs&&... args) noexcept;
61 
64  cxx::optional<T*> value() const noexcept;
65 
66  private:
67  T* m_value{nullptr};
68 };
69 
70 } // namespace roudi
71 } // namespace iox
72 
73 #include "iceoryx_posh/internal/roudi/memory/generic_memory_block.inl"
74 
75 #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:32
cxx::optional< T * > emplace(Targs &&... args) noexcept
A new element is constructed by forwarding the arguments to the constructor of T. If the MemoryBlock ...
Definition: generic_memory_block.inl:53
uint64_t size() const noexcept override
Implementation of MemoryBlock::size.
Definition: generic_memory_block.inl:30
uint64_t alignment() const noexcept override
Implementation of MemoryBlock::alignment.
Definition: generic_memory_block.inl:36
void destroy() noexcept override
Implementation of MemoryBlock::destroy.
Definition: generic_memory_block.inl:42
cxx::optional< T * > value() const noexcept
This function enables the access to the underlying type.
Definition: generic_memory_block.inl:67
The MemoryBlock is a container for general purpose memory. It is used to request some memory from a M...
Definition: memory_block.hpp:32
This class creates memory which is requested by the MemoryBlocks. Once the memory is available,...
Definition: memory_provider.hpp:72
Definition: service_description.hpp:29