Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
SharedReference.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/* SharedReference.h (C) 2000-2025 */
9/* */
10/* Base class of a reference counter. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_SHAREDREFERENCE_H
13#define ARCANE_CORE_SHAREDREFERENCE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/ISharedReference.h"
18
19#include <atomic>
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
34class ARCANE_CORE_EXPORT SharedReference
35: public ISharedReference
36{
37 public:
38
39 SharedReference()
40 : m_ref_count(0)
41 {}
42
43 public:
44
45 void addRef() override;
46 void removeRef() override;
47 Int32 refCount() const override { return m_ref_count; }
48
50 virtual void deleteMe() = 0;
51
52 private:
53
54 std::atomic<Int32> m_ref_count;
55};
56
57/*---------------------------------------------------------------------------*/
58/*---------------------------------------------------------------------------*/
59
60} // End namespace Arcane
61
62/*---------------------------------------------------------------------------*/
63/*---------------------------------------------------------------------------*/
64
65#endif
Interface of a reference counter.
std::atomic< Int32 > m_ref_count
Number of references on the object.
virtual void deleteMe()=0
Destroys the referenced object.
void addRef() override
Increments the reference counter.
Int32 refCount() const override
Returns the value of the reference counter.
void removeRef() override
Decrements the reference counter.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int32_t Int32
Signed integer type of 32 bits.