Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
VariableRefArrayLock.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/* VariableRefArrayLock.h (C) 2000-2025 */
9/* */
10/* Lock on an array variable. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_VARIABLEREFARRAYLOCK_H
13#define ARCANE_CORE_VARIABLEREFARRAYLOCK_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Array.h"
18
19#include "arcane/core/IVariable.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
35template <typename DataType>
36class VariableRefArrayLockT
37{
38 public:
39
40 typedef Array<DataType> ValueType;
41 typedef VariableRefArrayLockT<DataType> ThatClass;
42
43 public:
44
45 VariableRefArrayLockT(ValueType& v, IVariable* var)
46 : m_value(v)
47 , m_variable(var)
48 , m_saved_ptr(v.data())
49 , m_saved_size(v.size())
50 {
51 }
52
53 ~VariableRefArrayLockT()
54 {
55 if (m_value.data() != m_saved_ptr || m_value.size() != m_saved_size)
56 m_variable->syncReferences();
57 }
58
59 public:
60
61 VariableRefArrayLockT(const VariableRefArrayLockT<DataType>& rhs) = default;
62 ThatClass& operator=(const ThatClass& rhs) = default;
63
64 public:
65
66 ARCCORE_DEPRECATED_2021("This class is deprecated")
67 ValueType& value() { return m_value; }
68
69 private:
70
71 ValueType& m_value;
72 IVariable* m_variable;
73 DataType* m_saved_ptr;
74 Integer m_saved_size;
75};
76
77/*---------------------------------------------------------------------------*/
78/*---------------------------------------------------------------------------*/
79
80} // End namespace Arcane
81
82/*---------------------------------------------------------------------------*/
83/*---------------------------------------------------------------------------*/
84
85#endif
Integer size() const
Number of elements in the vector.
Base class for 1D data vectors.
const T * data() const
Access to the root of the array without any protection.
Interface of a variable.
Definition IVariable.h:40
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.