Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemPairGroupImpl.cc
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/* ItemPairGroupImpl.cc (C) 2000-2021 */
9/* */
10/* Implementation of an array of lists of entities. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/Array.h"
17#include "arcane/utils/IFunctor.h"
18
19#include "arcane/core/ItemGroupObserver.h"
20#include "arcane/core/ItemPairGroupImpl.h"
21#include "arcane/core/ItemPairGroup.h"
22#include "arcane/core/IItemFamily.h"
23#include "arcane/core/ItemGroup.h"
24#include "arcane/core/IMesh.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
39class ItemPairGroupImplNull
40: public ItemPairGroupImpl
41{
42 public:
43
44 ItemPairGroupImplNull()
45 : ItemPairGroupImpl()
46 {}
48
49 public:
50 private:
51};
52
53/*---------------------------------------------------------------------------*/
54/*---------------------------------------------------------------------------*/
58class ItemPairGroupImplPrivate
59{
60 public:
61
62 ItemPairGroupImplPrivate();
63 ItemPairGroupImplPrivate(const ItemGroup& group, const ItemGroup& sub_group);
64 ~ItemPairGroupImplPrivate();
65
66 public:
67
68 inline bool null() const { return m_is_null; }
69 inline IMesh* mesh() const { return m_mesh; }
70 inline eItemKind kind() const { return m_kind; }
71 inline eItemKind subKind() const { return m_sub_kind; }
72
73 public:
74
78 ItemGroup m_item_group;
79 ItemGroup m_sub_item_group;
80 bool m_is_null;
82 eItemKind m_sub_kind;
84
85 UniqueArray<Int64> m_indexes;
86 UniqueArray<Int32> m_sub_items_local_id;
87 IFunctor* m_compute_functor;
88
89 public:
90
91 void invalidate() { m_need_recompute = true; }
92
93 private:
94
95 void _init();
96};
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100
101ItemPairGroupImplPrivate::
102ItemPairGroupImplPrivate()
103: m_mesh(nullptr)
104, m_item_family(nullptr)
105, m_sub_item_family(nullptr)
106, m_is_null(true)
107, m_kind(IK_Unknown)
108, m_sub_kind(IK_Unknown)
109, m_need_recompute(false)
110, m_compute_functor(nullptr)
111{
112 _init();
113}
114
115/*---------------------------------------------------------------------------*/
116/*---------------------------------------------------------------------------*/
117
118ItemPairGroupImplPrivate::
119ItemPairGroupImplPrivate(const ItemGroup& group, const ItemGroup& sub_group)
120: m_mesh(group.mesh())
121, m_item_family(group.itemFamily())
122, m_sub_item_family(sub_group.itemFamily())
123, m_item_group(group)
124, m_sub_item_group(sub_group)
125, m_is_null(false)
126, m_kind(group.itemKind())
127, m_sub_kind(sub_group.itemKind())
128, m_need_recompute(false)
129, m_compute_functor(nullptr)
130{
131 _init();
132}
133
134/*---------------------------------------------------------------------------*/
135/*---------------------------------------------------------------------------*/
136
137ItemPairGroupImplPrivate::
138~ItemPairGroupImplPrivate()
139{
140 delete m_compute_functor;
141}
142
143/*---------------------------------------------------------------------------*/
144/*---------------------------------------------------------------------------*/
145
146void ItemPairGroupImplPrivate::
147_init()
148{
149}
150
151/*---------------------------------------------------------------------------*/
152/*---------------------------------------------------------------------------*/
153
154/*---------------------------------------------------------------------------*/
155/*---------------------------------------------------------------------------*/
156
157ItemPairGroupImpl* ItemPairGroupImpl::shared_null = 0;
158
159/*---------------------------------------------------------------------------*/
160/*---------------------------------------------------------------------------*/
161
162/*---------------------------------------------------------------------------*/
163/*---------------------------------------------------------------------------*/
164
165ItemPairGroupImpl* ItemPairGroupImpl::
166checkSharedNull()
167{
168 if (!shared_null) {
169 shared_null = new ItemPairGroupImplNull();
170 shared_null->addRef();
171 }
172 return shared_null;
173}
174
175/*---------------------------------------------------------------------------*/
176/*---------------------------------------------------------------------------*/
177
178ItemPairGroupImpl::
179ItemPairGroupImpl(const ItemGroup& group, const ItemGroup& sub_group)
180: m_p(new ItemPairGroupImplPrivate(group, sub_group))
181{
182 m_p->m_item_group.internal()->attachObserver(this, newItemGroupObserverT(m_p, &ItemPairGroupImplPrivate::invalidate));
183 m_p->m_sub_item_group.internal()->attachObserver(this, newItemGroupObserverT(m_p, &ItemPairGroupImplPrivate::invalidate));
184}
185
186/*---------------------------------------------------------------------------*/
187/*---------------------------------------------------------------------------*/
188
189ItemPairGroupImpl::
190ItemPairGroupImpl()
191: m_p(new ItemPairGroupImplPrivate())
192{
193}
194
195/*---------------------------------------------------------------------------*/
196/*---------------------------------------------------------------------------*/
197
200{
201 m_p->m_item_group.internal()->detachObserver(this);
202 m_p->m_sub_item_group.internal()->detachObserver(this);
203 delete m_p;
204}
205
206/*---------------------------------------------------------------------------*/
207/*---------------------------------------------------------------------------*/
208
213deleteMe()
214{
215 delete this;
216}
217
218/*---------------------------------------------------------------------------*/
219/*---------------------------------------------------------------------------*/
220
226
227/*---------------------------------------------------------------------------*/
228/*---------------------------------------------------------------------------*/
229
235
236/*---------------------------------------------------------------------------*/
237/*---------------------------------------------------------------------------*/
238
240mesh() const
241{
242 return m_p->mesh();
243}
244
245/*---------------------------------------------------------------------------*/
246/*---------------------------------------------------------------------------*/
247
249itemFamily() const
250{
251 return m_p->m_item_family;
252}
253
254/*---------------------------------------------------------------------------*/
255/*---------------------------------------------------------------------------*/
256
258subItemFamily() const
259{
260 return m_p->m_sub_item_family;
261}
262
263/*---------------------------------------------------------------------------*/
264/*---------------------------------------------------------------------------*/
265
267null() const
268{
269 return m_p->null();
270}
271
272/*---------------------------------------------------------------------------*/
273/*---------------------------------------------------------------------------*/
274
276itemKind() const
277{
278 return m_p->kind();
279}
280
281/*---------------------------------------------------------------------------*/
282/*---------------------------------------------------------------------------*/
283
285subItemKind() const
286{
287 return m_p->subKind();
288}
289
290/*---------------------------------------------------------------------------*/
291/*---------------------------------------------------------------------------*/
292
294itemGroup() const
295{
296 return m_p->m_item_group;
297}
298
299/*---------------------------------------------------------------------------*/
300/*---------------------------------------------------------------------------*/
301
303subItemGroup() const
304{
305 return m_p->m_sub_item_group;
306}
307
308/*---------------------------------------------------------------------------*/
309/*---------------------------------------------------------------------------*/
310
313{
314}
315
316/*---------------------------------------------------------------------------*/
317/*---------------------------------------------------------------------------*/
318
320invalidate(bool force_recompute)
321{
322 m_p->m_need_recompute = true;
323 if (force_recompute)
325}
326
327/*---------------------------------------------------------------------------*/
328/*---------------------------------------------------------------------------*/
329
332{
333 if (m_p->m_need_recompute) {
334 m_p->m_need_recompute = false;
335 if (m_p->m_compute_functor)
336 m_p->m_compute_functor->executeFunctor();
337 return true;
338 }
339 return false;
340}
341
342/*---------------------------------------------------------------------------*/
343/*---------------------------------------------------------------------------*/
344
346unguardedIndexes() const
347{
348 return m_p->m_indexes;
349}
350
351/*---------------------------------------------------------------------------*/
352/*---------------------------------------------------------------------------*/
353
355unguardedLocalIds() const
356{
357 return m_p->m_sub_items_local_id;
358}
359
360/*---------------------------------------------------------------------------*/
361/*---------------------------------------------------------------------------*/
362
363ArrayView<Int64> ItemPairGroupImpl::
364indexes()
365{
367 return m_p->m_indexes;
368}
369
370/*---------------------------------------------------------------------------*/
371/*---------------------------------------------------------------------------*/
372
373Span<const Int32> ItemPairGroupImpl::
374subItemsLocalId()
375{
377 return m_p->m_sub_items_local_id;
378}
379
380/*---------------------------------------------------------------------------*/
381/*---------------------------------------------------------------------------*/
382
385{
386 delete m_p->m_compute_functor;
387 m_p->m_compute_functor = functor;
388}
389
390/*---------------------------------------------------------------------------*/
391/*---------------------------------------------------------------------------*/
392
393} // End namespace Arcane
394
395/*---------------------------------------------------------------------------*/
396/*---------------------------------------------------------------------------*/
Modifiable view of an array of type T.
Base class for 1D data vectors.
Interface of an entity family.
Definition IItemFamily.h:83
Mesh entity group.
Definition ItemGroup.h:51
virtual ~ItemPairGroupImplNull()
Frees resources.
eItemKind m_kind
Kind of entities in the group.
bool m_need_recompute
True if the group must be recalculated.
IItemFamily * m_item_family
Associated family.
IItemFamily * m_sub_item_family
Associated family.
IMesh * m_mesh
Associated group manager.
bool m_is_null
True if the group is null.
Implementation of an array of lists of entities.
ItemPairGroupImplPrivate * m_p
Group implementation.
IMesh * mesh() const
Mesh to which the group belongs (0 for the null group).
eItemKind subItemKind() const
Group kind. This is the kind of its elements.
const ItemGroup & itemGroup() const
Group of entities.
bool checkNeedUpdate()
Updates the group if necessary.
void checkValid()
Checks that the group is valid.
~ItemPairGroupImpl() override
Releases resources.
eItemKind itemKind() const
Group kind. This is the kind of its elements.
Array< Int32 > & unguardedLocalIds() const
IItemFamily * subItemFamily() const
Family to which the group belongs (or 0 if none).
void removeRef() override
Decrements the reference counter.
IItemFamily * itemFamily() const
Family to which the group belongs (or 0 if none).
Array< Int64 > & unguardedIndexes() const
void addRef() override
Increments the reference counter.
const ItemGroup & subItemGroup() const
Group of sub-entities.
void invalidate(bool force_recompute)
Invalidates the group.
void setComputeFunctor(IFunctor *functor)
bool null() const
Returns true if the group is null.
void addRef() override
Increments the reference counter.
void removeRef() override
Decrements the reference counter.
1D data vector with value semantics (STL style).
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
eItemKind
Mesh entity type.
@ IK_Unknown
Unknown or uninitialized mesh entity.
IItemGroupObserver * newItemGroupObserverT(T *object, typename IItemGroupObserver::FuncTraits< T >::FuncPtr funcptr)
Utility for simplified creation of ItemGroupObserverT.