iceoryx_hoofs/cxx/poor_mans_heap.hpp🔗
Namespaces🔗
Name |
---|
iox building block to easily create free function for logging in a library context |
iox::cxx |
Classes🔗
Name | |
---|---|
class | iox::cxx::PoorMansHeapType This is a proxy which must be used for the non default PoorMansHeap ctor. |
class | iox::cxx::PoorMansHeap Reserves space on stack for placement new instatiation. |
Source code🔗
// Copyright (c) 2019 by Robert Bosch GmbH. All rights reserved.
// Copyright (c) 2021 by Apex.AI Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// SPDX-License-Identifier: Apache-2.0
#ifndef IOX_HOOFS_CXX_POOR_MANS_HEAP_HPP
#define IOX_HOOFS_CXX_POOR_MANS_HEAP_HPP
#include <cstddef>
#include <cstdint>
#include <utility>
namespace iox
{
namespace cxx
{
template <typename Type>
class PoorMansHeapType
{
};
template <typename Interface, size_t TypeSize, size_t TypeAlignment = 8>
class PoorMansHeap
{
public:
PoorMansHeap() = default;
~PoorMansHeap() noexcept;
template <typename Type, typename... CTorArgs>
PoorMansHeap(PoorMansHeapType<Type>, CTorArgs&&... ctorArgs) noexcept;
PoorMansHeap(PoorMansHeap&& other) = delete;
PoorMansHeap& operator=(PoorMansHeap&& rhs) = delete;
PoorMansHeap(const PoorMansHeap&) = delete;
PoorMansHeap& operator=(const PoorMansHeap&) = delete;
template <typename Type, typename... CTorArgs>
void newInstance(CTorArgs&&... ctorArgs) noexcept;
void deleteInstance() noexcept;
bool hasInstance() const noexcept;
Interface* operator->() const noexcept;
Interface& operator*() const noexcept;
private:
Interface* m_instance{nullptr};
alignas(TypeAlignment) uint8_t m_heap[TypeSize];
};
} // namespace cxx
} // namespace iox
#include "iceoryx_hoofs/internal/cxx/poor_mans_heap.inl"
#endif // IOX_HOOFS_CXX_POOR_MANS_HEAP_HPP
Updated on 31 May 2022 at 11:34:55 CEST