Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
MeshHandle.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/* MeshHandle.h (C) 2000-2025 */
9/* */
10/* Handle on a mesh. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_MESHHANDLE_H
13#define ARCANE_CORE_MESHHANDLE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18#include "arccore/base/StringView.h"
19#include "arccore/base/String.h"
20
23
24#include <atomic>
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35/*!
36 * \brief Handle on a mesh.
37 *
38 * This class uses reference counting semantics.
39 *
40 * This class allows managing a reference to a mesh (IMesh) before
41 * it is explicitly created. This allows services and modules
42 * to specify which mesh they refer to during their construction.
43 *
44 * It also allows associating user data with the mesh
45 * via meshUserDataList().
46 */
47class ARCANE_CORE_EXPORT MeshHandle
48{
49 private:
50
51 // Temporary: to access the constructor that uses ISubDomain.
52 friend class MeshMng;
53
54 private:
55
56 class MeshHandleRef
58 {
59 public:
60
61 MeshHandleRef()
62 : m_is_null(true)
63 {}
64 MeshHandleRef(ISubDomain* sd, const String& name);
65 ~MeshHandleRef();
66
67 public:
68
69 const String& meshName() const { return m_mesh_name; }
70 bool isNull() const { return m_is_null; }
71 IMesh* mesh() const { return m_mesh_ptr; }
72 IMeshBase* meshBase() const { return m_mesh_base_ptr; }
73 ISubDomain* subDomain() const { return m_sub_domain; }
74 IMeshMng* meshMng() const { return m_mesh_mng; }
75 ITraceMng* traceMng() const { return m_trace_mng; }
76 IVariableMng* variableMng() const { return m_variable_mng; }
77 IUserDataList* userDataList() const { return m_user_data_list; }
78 Observable* onDestroyObservable() const { return m_on_destroy_observable; }
79 bool isDoFatalInMeshMethod() const { return m_do_fatal_in_mesh_method; }
80
81 public:
82
83 void _destroyMesh();
84 void _setMesh(IMesh* mesh);
85
86 private:
87
88 String m_mesh_name;
89 IMesh* m_mesh_ptr = nullptr;
90 IMeshBase* m_mesh_base_ptr = nullptr;
91 // For now we need it, but it should be removed
92 ISubDomain* m_sub_domain = nullptr;
93 IUserDataList* m_user_data_list = nullptr;
94 IMeshMng* m_mesh_mng = nullptr;
95 ITraceMng* m_trace_mng = nullptr;
96 IVariableMng* m_variable_mng = nullptr;
97 Observable* m_on_destroy_observable = nullptr;
98 bool m_is_null = true;
99 bool m_do_fatal_in_mesh_method = false;
100 };
101
102 public:
103
104 MeshHandle();
105
106 private:
107
108 // TODO make accessible only to classes implementing IMeshMng.
109 MeshHandle(ISubDomain* sd, const String& name);
110
111 public:
112
113 /*!
114 * \brief Associated mesh.
115 *
116 * It is forbidden to call this method if the mesh has not yet been
117 * created. Eventually, an exception will be raised in this case.
118 *
119 * If we are not sure that the mesh exists, we can test its
120 * existence via hasMesh().
121 *
122 * \pre hasMesh() == true
123 */
124 IMesh* mesh() const;
125
126 //! Indicates if the associated mesh has already been created (i.e.: mesh() is valid)
127 bool hasMesh() const;
128
129 /*!
130 * \brief Returns the mesh associated with this instance.
131 *
132 * Unlike mesh(), this can be called even if the associated mesh has not
133 * yet been created. In this case, a null pointer is returned.
134 */
135 IMesh* meshOrNull() const;
136
137 public:
138
139 //! Associated sub-domain. Null if isNull() is true.
140 ARCCORE_DEPRECATED_2020("Do not use this method. Try to get ISubDomain from another way")
141 ISubDomain* subDomain() const { return m_ref->subDomain(); }
142
143 public:
144
145 //! Associated mesh manager. nullptr if isNull() is true.
146 IMeshMng* meshMng() const;
147
148 //! Associated trace manager. nullptr if isNull() is true.
149 ITraceMng* traceMng() const;
150
151 //! Associated variable manager. nullptr if isNull() is true.
152 IVariableMng* variableMng() const;
153
154 //! Associated application. nullptr if isNull() is true.
155 IApplication* application() const;
156
157 //! Associated user data
158 IUserDataList* meshUserDataList() const { return m_ref->userDataList(); }
159
160 const String& meshName() const { return m_ref->meshName(); }
161
162 //! Indicates if the handle is null (it does not reference any existing mesh or not)
163 bool isNull() const { return m_ref->isNull(); }
164
165 //! Observable to be notified of destruction
166 IObservable* onDestroyObservable() const;
167
168 //! \internal
169 const void* reference() const { return m_ref.get(); }
170
171 public:
172
173 //! \internal
174 void _setMesh(IMesh* mesh) { m_ref->_setMesh(mesh); }
175
176 //! \internal
177 void _destroyMesh() { m_ref->_destroyMesh(); }
178
179 //! \internal
180 IMesh* _internalMeshOrNull() const { return m_ref->mesh(); }
181
182 private:
183
184 Arccore::ReferenceCounter<MeshHandleRef> m_ref;
185};
186
187/*---------------------------------------------------------------------------*/
188/*---------------------------------------------------------------------------*/
189
190/*!
191 * \brief Compatibility class to hold a MeshHandle or an IMesh*.
192 *
193 * Eventually, the constructors and converters to IMesh* will be removed.
194 */
195class ARCANE_CORE_EXPORT MeshHandleOrMesh
196{
197 public:
198
199 // NOTE: The constructors must not be explicit
200 // to allow conversions
201
202 //! Constructs an instance from a MeshHandle
204
205 /*!
206 * \brief Constructs an instance from an IMesh*.
207 *
208 * If \a mesh is null, the associated MeshHandle will also be null.
209 */
211
212 //! Associated mesh. Can be null if the mesh has not yet been created
213 IMesh* mesh() const { return m_handle.meshOrNull(); }
214
215 //! Associated mesh. Can be null if the mesh has not yet been created
216 operator IMesh*() const { return mesh(); }
217
218 //! Associated handle.
219 const MeshHandle& handle() const { return m_handle; }
220
221 private:
222
223 MeshHandle m_handle;
224};
225
226/*---------------------------------------------------------------------------*/
227/*---------------------------------------------------------------------------*/
228
229} // End namespace Arcane
230
231/*---------------------------------------------------------------------------*/
232/*---------------------------------------------------------------------------*/
233
234#endif
Declarations of Arcane's general types.
Declarations of types used in Arcane.
Application interface.
Mesh manager interface.
Definition IMeshMng.h:41
Interface of the subdomain manager.
Definition ISubDomain.h:75
Interface of a list that manages user data.
Variable manager interface.
IMesh * mesh() const
Associated mesh. Can be null if the mesh has not yet been created.
Definition MeshHandle.h:213
const MeshHandle & handle() const
Associated handle.
Definition MeshHandle.h:219
MeshHandleOrMesh(const MeshHandle &handle)
Constructs an instance from a MeshHandle.
Handle on a mesh.
Definition MeshHandle.h:48
ITraceMng * traceMng() const
Associated trace manager. nullptr if isNull() is true.
ISubDomain * subDomain() const
Associated sub-domain. Null if isNull() is true.
Definition MeshHandle.h:141
bool hasMesh() const
Indicates if the associated mesh has already been created (i.e.: mesh() is valid).
IMesh * meshOrNull() const
Returns the mesh associated with this instance.
bool isNull() const
Indicates if the handle is null (it does not reference any existing mesh or not).
Definition MeshHandle.h:163
IMesh * mesh() const
Associated mesh.
IUserDataList * meshUserDataList() const
Associated user data.
Definition MeshHandle.h:158
IVariableMng * variableMng() const
Associated variable manager. nullptr if isNull() is true.
IMeshMng * meshMng() const
Associated mesh manager. nullptr if isNull() is true.
IObservable * onDestroyObservable() const
Observable to be notified of destruction.
Thread-safe implementation of a reference counter.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --