Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
optional_resetter.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_OPTIONAL_OPTIONAL_RESETTER_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_OPTIONAL_OPTIONAL_RESETTER_HPP_
7
8// IWYU pragma: private, include "arene/base/optional.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "False Positive: header exports optional, used below"
12#include "arene/base/optional/optional.hpp"
13// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
14
15// parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
16
17namespace arene {
18namespace base {
19
20// IWYU pragma: begin_keep
21template <typename T>
22class optional;
23// IWYU pragma: end_keep
24
25// parasoft-begin-suppress AUTOSAR-A2_7_3-a "False positive: '@brief' tags are present for all declarations"
26/// @brief A simple class that resets an @c optional value in its destructor, unless dismissed.
27/// @tparam Value the type of the @c optional's data
28template <typename Value>
30 /// @brief The optional to reset
31 optional<Value>* op_;
32
33 public:
34 // parasoft-begin-suppress AUTOSAR-A2_7_3-b "False positive: An '@param' tag is present for 'opt'"
35 /// @brief Construct an instance and specify the @c optional object to reset
36 /// @param opt The optional to reset
37 explicit optional_resetter(optional<Value>& opt) noexcept
38 : op_(&opt) {}
39 // parasoft-end-suppress AUTOSAR-A2_7_3-b
40
41 /// @brief Not copyable
43 /// @brief Not copyable
44 auto operator=(optional_resetter const&) -> optional_resetter& = delete;
45 /// @brief Not movable
47 /// @brief Not movable
49 /// @brief Reset the @c optional if not dismissed
51 if (op_ != nullptr) {
52 op_->reset();
53 }
54 }
55 /// @brief Dismiss the resetter, so it no longer resets the @c optional in the
56 /// destructor
57 void dismiss() noexcept { op_ = nullptr; }
58};
59// parasoft-end-suppress AUTOSAR-A2_7_3-a
60
61} // namespace base
62} // namespace arene
63
64#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_OPTIONAL_OPTIONAL_RESETTER_HPP_
A simple class that resets an optional value in its destructor, unless dismissed.
Definition optional_resetter.hpp:29
auto operator=(optional_resetter &&) -> optional_resetter &=delete
Not movable.
optional_resetter(optional_resetter const &)=delete
Not copyable.
~optional_resetter()
Reset the optional if not dismissed.
Definition optional_resetter.hpp:50
auto operator=(optional_resetter const &) -> optional_resetter &=delete
Not copyable.
optional_resetter(optional_resetter &&)=delete
Not movable.
void dismiss() noexcept
Dismiss the resetter, so it no longer resets the optional in the destructor.
Definition optional_resetter.hpp:57
optional_resetter(optional< Value > &opt) noexcept
Construct an instance and specify the optional object to reset.
Definition optional_resetter.hpp:37
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10