Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
binary_tree_node.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INTRUSIVE_BINARY_TREE_NODE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INTRUSIVE_BINARY_TREE_NODE_HPP_
7
8#include "arene/base/intrusive/detail/default_tag.hpp"
9
10// parasoft-begin-suppress AUTOSAR-A7_1_5-a "Trailing return syntax permitted by A7-1-5 Permit #1 v1.0.0"
11
12namespace arene {
13namespace base {
14namespace intrusive {
15
16// Forward declare
17// IWYU pragma: begin_keep
18template <typename T, typename Tag, typename Comp>
19class priority_queue;
20// IWYU pragma: end_keep
21
22namespace detail {
23/// @brief Pass-key type for controlling access to specific binary tree members
24class binary_tree_node_pass_key {
25 /// @brief Private constructor, so only friends can construct instances
26 constexpr explicit binary_tree_node_pass_key() = default;
27
28 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "Passkey idiom permitted by by A11-3-1 Permit #1 v1.0.0"
29 template <typename T, typename Tag, typename Comp>
30 friend class intrusive::priority_queue;
31 // parasoft-end-suppress AUTOSAR-A11_3_1-a
32};
33} // namespace detail
34
35/// @brief The tree node of the intrusive container.
36/// User type can be derived from this class to support intrusive containers.
37/// The @c parent_ points to itself for the root of a tree an indicator.
38/// @tparam Tag The tag of the element. Used to support adding the same
39/// element to multiple intrusive containers.
40template <typename Tag = detail::default_tag>
42 /// @brief parent node
43 binary_tree_node* parent_{nullptr};
44 // parasoft-begin-suppress AUTOSAR-M0_1_3-c "False positive: member 'left_' is used"
45 /// @brief left child node
46 binary_tree_node* left_{nullptr};
47 // parasoft-end-suppress AUTOSAR-M0_1_3-c
48 // parasoft-begin-suppress AUTOSAR-M0_1_3-c "False positive: member 'right_' is used"
49 /// @brief right child node
50 binary_tree_node* right_{nullptr};
51 // parasoft-end-suppress AUTOSAR-M0_1_3-c
52
53 public:
54 /// @brief Check if the element is linked to a container.
55 /// @return @c true if the element is linked to a container, @c false
56 constexpr auto is_linked() const noexcept -> bool { return parent_ != nullptr; }
57
58 // parasoft-begin-suppress AUTOSAR-A7_1_1-a "Declaring 'element' as reference to const changes semantics"
59 // parasoft-begin-suppress AUTOSAR-M7_1_2-c "Declaring 'element' as reference to const changes semantics"
60 // parasoft-begin-suppress AUTOSAR-A8_4_9-a "Declaring 'element' as reference to const changes semantics"
61 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "Hidden friends permitted by A11-3-1 Permit #2 v1.0.0"
62 // parasoft-begin-suppress AUTOSAR-A0_1_3-a "False positive: Function is namespace scope and used in other
63 // translation units"
64 /// @brief Getter to the parent_ member. pass_key idiom is used to grant
65 /// access only to the intrusive priority queue.
66 /// @param element The element to get the parent_ member from
67 /// @return Reference to the parent_ member
68 friend constexpr auto get_parent_link(binary_tree_node& element, Tag, detail::binary_tree_node_pass_key) noexcept
69 -> binary_tree_node*& {
70 return element.binary_tree_node<Tag>::parent_;
71 }
72 // parasoft-end-suppress AUTOSAR-A0_1_3-a
73 // parasoft-end-suppress AUTOSAR-A11_3_1-a
74 // parasoft-end-suppress AUTOSAR-A8_4_9-a
75 // parasoft-end-suppress AUTOSAR-M7_1_2-c
76 // parasoft-end-suppress AUTOSAR-A7_1_1-a
77
78 // parasoft-begin-suppress AUTOSAR-A7_1_1-a "Declaring 'element' as reference to const changes semantics"
79 // parasoft-begin-suppress AUTOSAR-M7_1_2-c "Declaring 'element' as reference to const changes semantics"
80 // parasoft-begin-suppress AUTOSAR-A8_4_9-a "Declaring 'element' as reference to const changes semantics"
81 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "Hidden friends permitted by A11-3-1 Permit #2 v1.0.0"
82 // parasoft-begin-suppress AUTOSAR-A0_1_3-a "False positive: Function is namespace scope and used in other
83 // translation units"
84 /// @brief Getter to the left_ member. pass_key idiom is used to grant access
85 /// only to the intrusive priority queue.
86 /// @param element The element to get the left_ member from
87 /// @return Reference to the left_ member
88 friend constexpr auto get_left_link(binary_tree_node& element, Tag, detail::binary_tree_node_pass_key) noexcept
89 -> binary_tree_node*& {
90 return element.binary_tree_node<Tag>::left_;
91 }
92 // parasoft-end-suppress AUTOSAR-A0_1_3-a
93 // parasoft-end-suppress AUTOSAR-A11_3_1-a
94 // parasoft-end-suppress AUTOSAR-A8_4_9-a
95 // parasoft-end-suppress AUTOSAR-M7_1_2-c
96 // parasoft-end-suppress AUTOSAR-A7_1_1-a
97
98 // parasoft-begin-suppress AUTOSAR-A7_1_1-a "Declaring 'element' as reference to const changes semantics"
99 // parasoft-begin-suppress AUTOSAR-M7_1_2-c "Declaring 'element' as reference to const changes semantics"
100 // parasoft-begin-suppress AUTOSAR-A8_4_9-a "Declaring 'element' as reference to const changes semantics"
101 // parasoft-begin-suppress AUTOSAR-A11_3_1-a "Hidden friends permitted by A11-3-1 Permit #2 v1.0.0"
102 // parasoft-begin-suppress AUTOSAR-A0_1_3-a "False positive: Function is namespace scope and used in other
103 // translation units"
104 /// @brief Getter to the right_ member. pass_key idiom is used to grant access
105 /// only to the intrusive priority queue.
106 /// @param element The element to get the right_ member from
107 /// @return Reference to the right_ member
108 friend constexpr auto get_right_link(binary_tree_node& element, Tag, detail::binary_tree_node_pass_key) noexcept
109 -> binary_tree_node*& {
110 return element.binary_tree_node<Tag>::right_;
111 }
112 // parasoft-end-suppress AUTOSAR-A0_1_3-a
113 // parasoft-end-suppress AUTOSAR-A11_3_1-a
114 // parasoft-end-suppress AUTOSAR-A8_4_9-a
115 // parasoft-end-suppress AUTOSAR-M7_1_2-c
116 // parasoft-end-suppress AUTOSAR-A7_1_1-a
117};
118
119} // namespace intrusive
120} // namespace base
121} // namespace arene
122
123#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_INTRUSIVE_BINARY_TREE_NODE_HPP_
The tree node of the intrusive container. User type can be derived from this class to support intrusi...
Definition binary_tree_node.hpp:41
constexpr auto is_linked() const noexcept -> bool
Check if the element is linked to a container.
Definition binary_tree_node.hpp:56
friend constexpr auto get_parent_link(binary_tree_node &element, Tag, detail::binary_tree_node_pass_key) noexcept -> binary_tree_node *&
Getter to the parent_ member. pass_key idiom is used to grant access only to the intrusive priority q...
Definition binary_tree_node.hpp:68
friend constexpr auto get_right_link(binary_tree_node &element, Tag, detail::binary_tree_node_pass_key) noexcept -> binary_tree_node *&
Getter to the right_ member. pass_key idiom is used to grant access only to the intrusive priority qu...
Definition binary_tree_node.hpp:108
friend constexpr auto get_left_link(binary_tree_node &element, Tag, detail::binary_tree_node_pass_key) noexcept -> binary_tree_node *&
Getter to the left_ member. pass_key idiom is used to grant access only to the intrusive priority que...
Definition binary_tree_node.hpp:88
Compare value_compare
value comparison type
Definition priority_queue.hpp:51
Definition binary_tree_node.hpp:14
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10