Skip to content

iceoryx_hoofs/cxx/unique_ptr.hpp🔗

Namespaces🔗

Name
iox
building block to easily create free function for logging in a library context
iox::cxx

Classes🔗

Name
class iox::cxx::unique_ptr
The unique_ptr class is a heap-less unique ptr implementation, unlike the STL.

Source code🔗

// Copyright (c) 2020 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_UNIQUE_PTR_HPP
#define IOX_HOOFS_CXX_UNIQUE_PTR_HPP

#include "iceoryx_hoofs/cxx/function_ref.hpp"

namespace iox
{
namespace cxx
{
template <typename T>
class unique_ptr
{
  public:
    unique_ptr() = delete;

    unique_ptr(function_ref<void(T*)>&& deleter) noexcept;

    unique_ptr(T* const ptr, function_ref<void(T*)>&& deleter) noexcept;

    unique_ptr(const unique_ptr& other) = delete;
    unique_ptr& operator=(const unique_ptr&) = delete;
    unique_ptr(unique_ptr&& rhs) noexcept;
    unique_ptr& operator=(unique_ptr&& rhs) noexcept;

    ~unique_ptr() noexcept;


    unique_ptr<T>& operator=(std::nullptr_t) noexcept;

    T* operator->() noexcept;

    const T* operator->() const noexcept;

    explicit operator bool() const noexcept;

    T* get() noexcept;

    const T* get() const noexcept;

    T* release() noexcept;

    void reset(T* const ptr = nullptr) noexcept;

    void swap(unique_ptr& other) noexcept;

  private:
    T* m_ptr = nullptr;
    function_ref<void(T* const)> m_deleter;
};

} // namespace cxx
} // namespace iox

#include "iceoryx_hoofs/internal/cxx/unique_ptr.inl"

#endif // IOX_HOOFS_CXX_UNIQUE_PTR_HPP

Updated on 18 December 2023 at 13:11:42 CET