Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ScopedPtr.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/* ScopedPtr.h (C) 2000-2006 */
9/* */
10/* Encapsulation of a pointer that is automatically destroyed. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_SCOPEDPTR_H
13#define ARCANE_UTILS_SCOPEDPTR_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Ptr.h"
18
19/*---------------------------------------------------------------------------*/
20/*---------------------------------------------------------------------------*/
21
22namespace Arcane
23{
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
41template <class T>
43: public PtrT<T>
44{
45 public:
46
49
50 public:
51
54 : BaseClass(0)
55 {}
56
58 explicit ScopedPtrT(T* t)
59 : BaseClass(t)
60 {}
61
63 ~ScopedPtrT() { delete this->m_value; }
64
65 public:
66
69 {
70 if (this != &from) {
71 delete this->m_value;
73 }
74 return (*this);
75 }
76
78 const ScopedPtrT<T>& operator=(T* new_value)
79 {
80 if (this->m_value != new_value) {
81 delete this->m_value;
82 this->m_value = new_value;
83 }
84 return (*this);
85 }
86};
87
88/*---------------------------------------------------------------------------*/
89/*---------------------------------------------------------------------------*/
90
91} // namespace Arcane
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96#endif
T * m_value
Pointer to the referenced object.
Definition Ptr.h:128
PtrT< T > & operator=(const PtrT< T > &from)
Copy operator.
Definition Ptr.h:50
PtrT(const PtrT< T > &from)
Constructs a reference referring to from.
Definition Ptr.h:71
const ScopedPtrT< T > & operator=(const ScopedPtrT< T > &from)
Copy operator.
Definition ScopedPtr.h:68
ScopedPtrT()
Constructs an instance without a reference.
Definition ScopedPtr.h:53
~ScopedPtrT()
Destroys the referenced object.
Definition ScopedPtr.h:63
const ScopedPtrT< T > & operator=(T *new_value)
Assigns the value new_value to the instance.
Definition ScopedPtr.h:78
PtrT< T > BaseClass
Base class type.
Definition ScopedPtr.h:48
ScopedPtrT(T *t)
Constructs an instance referencing t.
Definition ScopedPtr.h:58
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --