Arcane  4.2.3.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-2026 */
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#include "arccore/base/AutoRef2.h"
21
24
25#include <atomic>
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30namespace Arcane
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;
57
58 public:
59
60 MeshHandle();
61 ~MeshHandle();
62
63 MeshHandle(const MeshHandle&);
64 MeshHandle& operator=(const MeshHandle&);
65 MeshHandle(MeshHandle&&) noexcept;
66 MeshHandle& operator=(MeshHandle&&) noexcept;
67
68 private:
69
70 // TODO make accessible only to classes implementing IMeshMng.
71 MeshHandle(ISubDomain* sd, const String& name);
72
73 public:
74
75 /*!
76 * \brief Associated mesh.
77 *
78 * It is forbidden to call this method if the mesh has not yet been
79 * created. Eventually, an exception will be raised in this case.
80 *
81 * If we are not sure that the mesh exists, we can test its
82 * existence via hasMesh().
83 *
84 * \pre hasMesh() == true
85 */
86 IMesh* mesh() const;
87
88 //! Indicates if the associated mesh has already been created (i.e.: mesh() is valid)
89 bool hasMesh() const;
90
91 /*!
92 * \brief Returns the mesh associated with this instance.
93 *
94 * Unlike mesh(), this can be called even if the associated mesh has not
95 * yet been created. In this case, a null pointer is returned.
96 */
97 IMesh* meshOrNull() const;
98
99 public:
100
101 //! Associated sub-domain. Null if isNull() is true.
102 ARCCORE_DEPRECATED_2020("Do not use this method. Try to get ISubDomain from another way")
103 ISubDomain* subDomain() const;
104
105 public:
106
107 //! Associated mesh manager. nullptr if isNull() is true.
108 IMeshMng* meshMng() const;
109
110 //! Associated trace manager. nullptr if isNull() is true.
111 ITraceMng* traceMng() const;
112
113 //! Associated variable manager. nullptr if isNull() is true.
114 IVariableMng* variableMng() const;
115
116 //! Associated application. nullptr if isNull() is true.
117 IApplication* application() const;
118
119 //! Associated user data
121
122 String meshName() const;
123
124 //! Indicates if the handle is null (it does not reference any existing mesh or not)
125 bool isNull() const;
126
127 //! Observable to be notified of destruction
129
130 //! \internal
131 const void* reference() const { return m_ref.get(); }
132
133 public:
134
135 // TODO: Make these privates and add friend on them
136
137 //! \internal
138 void _setMesh(IMesh* mesh);
139
140 //! \internal
141 void _destroyMesh();
142
143 //! \internal
144 IMesh* _internalMeshOrNull() const;
145
146 private:
147
149};
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153/*!
154 * \brief Compatibility class to hold a MeshHandle or an IMesh*.
155 *
156 * Eventually, the constructors and converters to IMesh* will be removed.
157 */
158class ARCANE_CORE_EXPORT MeshHandleOrMesh
159{
160 public:
161
162 // NOTE: The constructors must not be explicit
163 // to allow conversions
164
165 //! Constructs an instance from a MeshHandle
167
168 /*!
169 * \brief Constructs an instance from an IMesh*.
170 *
171 * If \a mesh is null, the associated MeshHandle will also be null.
172 */
174
175 //! Associated mesh. Can be null if the mesh has not yet been created
176 IMesh* mesh() const { return m_handle.meshOrNull(); }
177
178 //! Associated mesh. Can be null if the mesh has not yet been created
179 operator IMesh*() const { return mesh(); }
180
181 //! Associated handle.
182 const MeshHandle& handle() const { return m_handle; }
183
184 private:
185
186 MeshHandle m_handle;
187};
188
189/*---------------------------------------------------------------------------*/
190/*---------------------------------------------------------------------------*/
191
192} // End namespace Arcane
193
194/*---------------------------------------------------------------------------*/
195/*---------------------------------------------------------------------------*/
196
197#endif
Declarations of Arcane's general types.
Declarations of types used in Arcane.
Encapsulation of a pointer with a reference counter.
Definition AutoRef2.h:41
Application interface.
Mesh manager interface.
Definition IMeshMng.h:41
Interface of the subdomain manager.
Definition ISubDomain.h:78
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:176
const MeshHandle & handle() const
Associated handle.
Definition MeshHandle.h:182
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.
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).
IMesh * mesh() const
Associated mesh.
IApplication * application() const
Associated application. nullptr if isNull() is true.
IUserDataList * meshUserDataList() const
Associated user data.
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.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --