iceoryx2
C++ Language Bindings
Loading...
Searching...
No Matches
polymorphic_handler.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 by Apex.AI Inc. All rights reserved.
2// Copyright (c) 2025 Contributors to the Eclipse Foundation
3//
4// See the NOTICE file(s) distributed with this work for additional
5// information regarding copyright ownership.
6//
7// This program and the accompanying materials are made available under the
8// terms of the Apache Software License 2.0 which is available at
9// https://www.apache.org/licenses/LICENSE-2.0, or the MIT license
10// which is available at https://opensource.org/licenses/MIT.
11//
12// SPDX-License-Identifier: Apache-2.0 OR MIT
13
14#ifndef IOX2_BB_DESIGN_POLYMORPHIC_HANDLER_HPP
15#define IOX2_BB_DESIGN_POLYMORPHIC_HANDLER_HPP
16
19
20#include <type_traits>
21
22namespace iox2 {
23namespace legacy {
24namespace detail {
25
29template <typename Interface>
37
38} // namespace detail
39
56template <typename Interface, typename Default, typename Hooks = detail::DefaultHooks<Interface>>
58 static_assert(std::is_base_of<Interface, Default>::value, "Interface must be a base class of Default");
59
61 friend class StaticLifetimeGuard<Self>;
62
63 public:
70
82
87
92
99
100 private:
102
104
105 static Default& getDefault() noexcept;
106
107 static Interface* getCurrentRelaxed() noexcept;
108
109 static Interface* getCurrentSync() noexcept;
110
111 static bool setHandler(Interface& handler) noexcept;
112
113 // should a defaultHandler be created, the guard prevents its destruction
114 StaticLifetimeGuard<Default> m_defaultGuard;
115 concurrent::Atomic<bool> m_isFinal { false };
116 concurrent::Atomic<Interface*> m_current { nullptr };
117};
118
119} // namespace legacy
120} // namespace iox2
121
122#include "iox2/legacy/detail/polymorphic_handler.inl"
123
124#endif // IOX2_BB_DESIGN_POLYMORPHIC_HANDLER_HPP
Implements a singleton handler that has a default instance and can be changed to another instance at ...
static bool reset() noexcept
reset the current singleton instance to the default instance
static StaticLifetimeGuard< Self > guard() noexcept
returns a lifetime guard whose existence guarantees the created PolymorphicHandler singleton instance...
static Interface & get() noexcept
obtain the current singleton instance
static void finalize() noexcept
finalizes the instance, afterwards Hooks::onSetAfterFinalize will be called during the remaining prog...
static bool set(StaticLifetimeGuard< Handler > handlerGuard) noexcept
set the current singleton instance
Manages a static instance of type T in a way so that each existing StaticLifetimeGuard prevents the d...
A thin wrapper for a 'std::atomic' which ensures that all atomic operations are always lock-free in o...
Definition atomic.hpp:32
constexpr bool always_false_v
Helper value to bind a static_assert to a type.
default hooks for the PolymorphicHandler
static void onSetAfterFinalize(Interface &currentInstance, Interface &newInstance) noexcept
called if the polymorphic handler is set or reset after finalize