Arcane  4.2.1.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-2026 */
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#include <utility>
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
34class ARCCORE_BASE_EXPORT RefBase
35{
36 friend class ReferenceCounterImpl;
37 template <typename InstanceType> friend class impl::ReferenceCounterWrapper;
38
39 protected:
40
41 class ARCCORE_BASE_EXPORT BasicDeleterBase
42 {
43 };
44
45 class ARCCORE_BASE_EXPORT DeleterBase
46 {
47 using ExternalRef = Internal::ExternalRef;
48 friend class ReferenceCounterImpl;
49
50 public:
51
52 bool hasExternal() const { return m_handle.isValid(); }
53 void setNoDestroy(bool x) { m_no_destroy = x; }
54
55 protected:
56
57 bool _destroyHandle(const void* instance, ExternalRef& handle);
58 bool _destroyHandle(void* instance, ExternalRef& handle);
59
60 private:
61
62 bool _destroyHandleTrue(const void* instance, ExternalRef& handle);
63
64 protected:
65
66 DeleterBase() = default;
67 DeleterBase(ExternalRef h)
68 : m_handle(std::move(h))
69 {}
70 DeleterBase(ExternalRef h, bool no_destroy)
71 : m_handle(std::move(h))
72 , m_no_destroy(no_destroy)
73 {}
74
75 protected:
76
83 bool m_no_destroy = false;
84 };
85};
86
87/*---------------------------------------------------------------------------*/
88/*---------------------------------------------------------------------------*/
89
90} // namespace Arcane
91
92/*---------------------------------------------------------------------------*/
93/*---------------------------------------------------------------------------*/
94
95#endif
Management of references to an external object.
Internal::ExternalRef m_handle
External handle responsible for the destruction of the instance.
Definition RefBase.h:78
bool m_no_destroy
Indicates whether the instance destructor should be called when there are no more references to it.
Definition RefBase.h:83
Base class for reference management.
Definition RefBase.h:35
Wrapper around a class managing its own reference counter.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --