deal.II version GIT relicensing-7058-gb35ee29762 2026-11-11 09:30: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 {
48 T::free(h)
49 } -> std::same_as<void>;
50 };
51# endif
52
71 template <typename Traits>
72 DEAL_II_CXX20_REQUIRES(SundialsTraits<Traits>)
74 {
75 public:
76 using Handle = typename Traits::Handle;
77
82 explicit SundialsHandle(Handle handle)
83 : handle(handle)
84 {
85 AssertThrow(handle != nullptr,
86 ExcMessage("SUNDIALS failed to create an object."));
87 }
88
90 {
91 reset();
92 }
93
94 SundialsHandle(const SundialsHandle &) = delete;
96 operator=(const SundialsHandle &) = delete;
97
99 : handle(std::exchange(other.handle, nullptr))
100 {}
101
103 operator=(SundialsHandle &&other) noexcept
104 {
105 if (this != &other)
106 {
107 reset();
108 handle = std::exchange(other.handle, nullptr);
109 }
110 return *this;
111 }
112
117 operator Handle() const
118 {
119 return handle;
120 }
121
122 private:
123 void
124 reset() noexcept
125 {
126 if (handle != nullptr)
127 {
128 Traits::free(handle);
129 handle = nullptr;
130 }
131 }
132
134 };
135 } // namespace internal
136} // namespace SUNDIALS
137#endif
138
140#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)