version GIT relicensing-7278-g091132d5eb 2026-12-02 03:10:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
sundials_handle.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_sundials_sundials_handle_h
14#define dealii_sundials_sundials_handle_h
15
16#include <deal.II/base/config.h>
17
18#ifdef DEAL_II_WITH_SUNDIALS
19
21
22# ifdef DEAL_II_HAVE_CXX20
23# include <concepts>
24# endif
25# include <utility>
26
27#endif
28
30
31#ifdef DEAL_II_WITH_SUNDIALS
32namespace SUNDIALS
33{
34 namespace internal
35 {
36# if defined(DEAL_II_HAVE_CXX20)
45 template <typename T>
46 concept SundialsTraits = requires(typename T::Handle h) {
47 { T::free(h) } -> std::same_as<void>;
48 };
49# endif
50
69 template <typename Traits>
70 DEAL_II_CXX20_REQUIRES(SundialsTraits<Traits>)
72 {
73 public:
74 using Handle = typename Traits::Handle;
75
80 explicit SundialsHandle(Handle handle)
81 : handle(handle)
82 {
83 AssertThrow(handle != nullptr,
84 ExcMessage("SUNDIALS failed to create an object."));
85 }
86
88 {
89 reset();
90 }
91
92 SundialsHandle(const SundialsHandle &) = delete;
94 operator=(const SundialsHandle &) = delete;
95
97 : handle(std::exchange(other.handle, nullptr))
98 {}
99
101 operator=(SundialsHandle &&other) noexcept
102 {
103 if (this != &other)
104 {
105 reset();
106 handle = std::exchange(other.handle, nullptr);
107 }
108 return *this;
109 }
110
115 operator Handle() const
116 {
117 return handle;
118 }
119
120 private:
121 void
122 reset() noexcept
123 {
124 if (handle != nullptr)
125 {
126 Traits::free(handle);
127 handle = nullptr;
128 }
129 }
130
132 };
133 } // namespace internal
134} // namespace SUNDIALS
135#endif
136
138#endif
SundialsHandle(const SundialsHandle &)=delete
SundialsHandle(SundialsHandle &&other) noexcept
SundialsHandle & operator=(SundialsHandle &&other) noexcept
SundialsHandle & operator=(const SundialsHandle &)=delete
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_CXX20_REQUIRES(condition)
Definition config.h:249
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)