Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
VariableRef.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/* VariableRef.h (C) 2000-2025 */
9/* */
10/* Class managing a reference to a variable. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_VARIABLEREF_H
13#define ARCANE_CORE_VARIABLEREF_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/String.h"
18
19#include "arcane/core/IVariable.h"
20#include "arcane/core/VariableComputeFunction.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27
28/*---------------------------------------------------------------------------*/
29/*---------------------------------------------------------------------------*/
30
31class IModule;
34typedef VariableBuildInfo VariableBuilder;
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
55class ARCANE_CORE_EXPORT VariableRef
56{
57 public:
58
60 friend class UpdateNotifyFunctorList;
61
62 protected:
63
65 explicit VariableRef(const VariableBuildInfo& vbi);
67 VariableRef(const VariableRef& from);
69 explicit VariableRef(IVariable* var);
71 VariableRef& operator=(const VariableRef& from);
74
75 public:
76
78 virtual ~VariableRef();
79
80 public:
81
83 ISubDomain* subDomain() const;
84
85 public:
86
89
91 String name() const;
92
93 public:
94
95 //TODO Remove virtual
97 virtual eDataType dataType() const;
98
100 virtual void print(std::ostream& o) const;
101
102 //TODO Remove virtual
104 virtual IModule* module() const { return m_module; }
105
106 //TODO Remove virtual
108 virtual int property() const;
109
111 virtual int referenceProperty() const;
112
114 virtual void setProperty(int property);
115
117 virtual void unsetProperty(int property);
118
120 virtual void registerVariable();
121
123 virtual void unregisterVariable();
124
126 IVariable* variable() const { return m_variable; }
127
131 virtual Integer checkIfSync(int max_print = 0);
132
137 virtual Integer checkIfSameOnAllReplica(int max_print = 0);
138
140 virtual void updateFromInternal();
141
143 virtual Integer arraySize() const { return 0; }
144
145 public:
146
147 void setUsed(bool v) { m_variable->setUsed(v); }
148 bool isUsed() const { return m_variable->isUsed(); }
149
150 virtual void internalSetUsed(bool /*v*/) {}
151
152 public:
153
161
162 public:
163
165
166 void addTag(const String& tagname, const String& tagvalue);
171 void removeTag(const String& tagname);
173 bool hasTag(const String& tagname) const;
175 String tagValue(const String& tagname) const;
177
178 public:
179
186
193 void update();
194
200 void setUpToDate();
201
203 Int64 modifiedTime();
204
206 void addDependCurrentTime(const VariableRef& var);
207
209 void addDependCurrentTime(const VariableRef& var, const TraceInfo& tinfo);
210
212 void addDependPreviousTime(const VariableRef& var);
213
215 void addDependPreviousTime(const VariableRef& var, const TraceInfo& tinfo);
216
219 void removeDepend(const VariableRef& var);
220
227 template <typename ClassType> void
228 setComputeFunction(ClassType* instance, void (ClassType::*func)())
229 {
230 _setComputeFunction(new VariableComputeFunction(instance, func));
231 }
232
240 template <typename ClassType> void
241 setComputeFunction(ClassType* instance, void (ClassType::*func)(), const TraceInfo& tinfo)
242 {
243 _setComputeFunction(new VariableComputeFunction(instance, func, tinfo));
244 }
245
246
247 public:
248
250 VariableRef* previousReference();
251
253 VariableRef* nextReference();
254
261 void setPreviousReference(VariableRef* v);
262
269 void setNextReference(VariableRef* v);
270
271 public:
272
273 static void setTraceCreation(bool v);
274 static bool hasTraceCreation();
275
276 protected:
277
278 void _setComputeFunction(IVariableComputeFunction* v);
279
287 void _internalInit(IVariable*);
288
295 {
296 _checkValid();
297 return m_variable;
298 }
299
300 private:
301
304
306 IModule* m_module = nullptr;
307
309 bool m_is_registered = false;
310
313
316
319
326
327 protected:
328
329 void _executeUpdateFunctors();
330
331 bool m_has_trace = false;
332
333 private:
334
335 void _checkValid() const
336 {
337#ifdef ARCANE_CHECK
338 if (!m_variable)
339 _throwInvalid();
340#endif
341 }
342 void _throwInvalid() const;
343 bool _checkValidPropertyChanged(int property);
344 void _setAssignmentStackTrace();
345
346 protected:
347
348 void _internalAssignVariable(const VariableRef& var);
349
350 private:
351
352 static bool m_static_has_trace_creation;
353 UpdateNotifyFunctorList* m_notify_functor_list = nullptr;
354};
355
356/*---------------------------------------------------------------------------*/
357/*---------------------------------------------------------------------------*/
358
359} // namespace Arcane
360
361/*---------------------------------------------------------------------------*/
362/*---------------------------------------------------------------------------*/
363
364#endif
365
366//TODO: to be removed when all codes include this file directly
367#include "arcane/core/VariableList.h"
Interface of a module.
Definition IModule.h:40
Interface of the subdomain manager.
Definition ISubDomain.h:75
Interface of the functor class for recalculating a variable.
Variable manager interface.
Interface of a variable.
Definition IVariable.h:40
Parameters necessary for building a variable.
Interface of the variable recalculation functor class.
Internal class to manage functors called when the variable is updated.
Reference to a variable.
Definition VariableRef.h:56
IModule * m_module
Associated module (or 0 if none).
VariableRef(const VariableBuildInfo &vbi)
Constructs a reference to a variable with the infos vbi.
VariableRef & operator=(const VariableRef &from)
Copy assignment operator.
bool m_is_registered
true if the variable has been registered
virtual eDataType dataType() const
Variable type (Real, Integer, ...).
VariableRef * m_previous_reference
Previous reference on m_variable.
virtual void print(std::ostream &o) const
Prints the variable value.
virtual IModule * module() const
Module associated with the variable (or nullptr, if none).
int m_reference_property
Reference properties.
String m_assignment_stack_trace
Call stack during variable assignment.
void setComputeFunction(ClassType *instance, void(ClassType::*func)(), const TraceInfo &tinfo)
Sets the variable's recalculation function.
IVariable * variable() const
Associated variable.
VariableRef * m_next_reference
Next reference on m_variable.
String name() const
Variable name.
const String & assignmentStackTrace() const
Call stack at the time of assigning this instance.
ISubDomain * subDomain() const
Sub-domain associated with the variable (TODO deprecate end of 2023).
virtual Integer arraySize() const
If the variable is an array, returns its dimension, otherwise returns 0.
void setComputeFunction(ClassType *instance, void(ClassType::*func)())
Sets the variable's recalculation function.
IVariable * m_variable
Associated variable.
IVariableMng * variableMng() const
Variable manager associated with the variable.
IVariable * _variable() const
Referenced variable.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
eDataType
Data type.
Definition DataTypes.h:41