Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
RefBase.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 CEA (www.cea.fr) IFPEN (www.ifpenergiesnouvelles.com)
4// See the top-level COPYRIGHT file for details.
5// SPDX-License-Identifier: Apache-2.0
6//-----------------------------------------------------------------------------
7/*---------------------------------------------------------------------------*/
8/* RefBase.h (C) 2000-2025 */
9/* */
10/* Base class for reference management on an instance. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCCORE_BASE_REFBASE_H
13#define ARCCORE_BASE_REFBASE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arccore/base/ExternalRef.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
32class ARCCORE_BASE_EXPORT RefBase
33{
34 friend class ReferenceCounterImpl;
35 template <typename InstanceType> friend class impl::ReferenceCounterWrapper;
36
37 protected:
38
39 class ARCCORE_BASE_EXPORT BasicDeleterBase
40 {
41 };
42
43 class ARCCORE_BASE_EXPORT DeleterBase
44 {
45 using ExternalRef = Internal::ExternalRef;
46 friend class ReferenceCounterImpl;
47
48 public:
49
50 bool hasExternal() const { return m_handle.isValid(); }
51 void setNoDestroy(bool x) { m_no_destroy = x; }
52
53 protected:
54
55 bool _destroyHandle(const void* instance, ExternalRef& handle);
56 bool _destroyHandle(void* instance, ExternalRef& handle);
57
58 private:
59
60 bool _destroyHandleTrue(const void* instance, ExternalRef& handle);
61
62 protected:
63
64 DeleterBase() = default;
65 DeleterBase(ExternalRef h)
66 : m_handle(std::move(h))
67 {}
68 DeleterBase(ExternalRef h, bool no_destroy)
69 : m_handle(std::move(h))
70 , m_no_destroy(no_destroy)
71 {}
72
73 protected:
74
81 bool m_no_destroy = false;
82 };
83};
84
85/*---------------------------------------------------------------------------*/
86/*---------------------------------------------------------------------------*/
87
88} // namespace Arcane
89
90/*---------------------------------------------------------------------------*/
91/*---------------------------------------------------------------------------*/
92
93#endif
Management of references to an external object.
Internal::ExternalRef m_handle
External handle responsible for the destruction of the instance.
Definition RefBase.h:76
bool m_no_destroy
Indicates whether the instance destructor should be called when there are no more references to it.
Definition RefBase.h:81
Base class for reference management.
Definition RefBase.h:33
Wrapper around a class managing its own reference counter.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --