Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemConnectedListView.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/* ItemConnectedListView.h (C) 2000-2025 */
9/* */
10/* View of a list of entities connected to another entity. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ITEMCONNECTEDLISTVIEW_H
13#define ARCANE_CORE_ITEMCONNECTEDLISTVIEW_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/ItemInternalVectorView.h"
18#include "arcane/core/ItemIndexArrayView.h"
19#include "arcane/core/ItemInfoListView.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
42class ItemConnectedListViewConstIterator
43{
44 protected:
45
46 template <int Extent> friend class ItemConnectedListView;
47 friend class ItemVectorViewConstIterator;
48
49 protected:
50
51 ItemConnectedListViewConstIterator(ItemSharedInfo* shared_info, const Int32* local_id_ptr,
52 Int32 local_id_offset)
53 : m_shared_info(shared_info)
54 , m_local_id_ptr(local_id_ptr)
55 , m_local_id_offset(local_id_offset)
56 {}
57
58 public:
59
60 typedef ItemConnectedListViewConstIterator ThatClass;
61 typedef std::random_access_iterator_tag iterator_category;
67 typedef std::ptrdiff_t difference_type;
68
69 public:
70
71 //TODO A supprimer avec le C++20
72 typedef const Item* pointer;
73 //TODO A supprimer avec le C++20
74 typedef const Item& reference;
75
76 public:
77
78 Item operator*() const
79 {
80 return Item(*m_local_id_ptr, m_shared_info);
81 }
82 ThatClass& operator++()
83 {
84 ++m_local_id_ptr;
85 return (*this);
86 }
87 ThatClass& operator--()
88 {
89 --m_local_id_ptr;
90 return (*this);
91 }
92 void operator+=(difference_type v)
93 {
94 m_local_id_ptr += v;
95 }
96 void operator-=(difference_type v)
97 {
98 m_local_id_ptr -= v;
99 }
100 difference_type operator-(const ThatClass& b) const
101 {
102 return this->m_local_id_ptr - b.m_local_id_ptr;
103 }
104 friend ThatClass operator-(const ThatClass& a, difference_type v)
105 {
106 const Int32* ptr = a.m_local_id_ptr - v;
107 return ThatClass(a.m_shared_info, ptr, a.m_local_id_offset);
108 }
109 friend ThatClass operator+(const ThatClass& a, difference_type v)
110 {
111 const Int32* ptr = a.m_local_id_ptr + v;
112 return ThatClass(a.m_shared_info, ptr, a.m_local_id_offset);
113 }
114 friend bool operator<(const ThatClass& lhs, const ThatClass& rhs)
115 {
116 return lhs.m_local_id_ptr <= rhs.m_local_id_ptr;
117 }
119 friend bool operator==(const ThatClass& lhs, const ThatClass& rhs)
120 {
121 return lhs.m_local_id_ptr == rhs.m_local_id_ptr;
122 }
123 friend bool operator!=(const ThatClass& lhs, const ThatClass& rhs)
124 {
125 return !(lhs == rhs);
126 }
127
128 ARCANE_DEPRECATED_REASON("Y2022: This method returns a temporary. Use 'operator*' instead")
129 Item operator->() const
130 {
131 return _itemInternal();
132 }
133
134 protected:
135
136 ItemSharedInfo* m_shared_info;
137 const Int32* m_local_id_ptr;
138 Int32 m_local_id_offset = 0;
139
140 protected:
141
142 inline ItemInternal* _itemInternal() const
143 {
144 return m_shared_info->m_items_internal[m_local_id_offset + (*m_local_id_ptr)];
145 }
146};
147
148/*---------------------------------------------------------------------------*/
149/*---------------------------------------------------------------------------*/
150
151template <typename ItemType>
152class ItemConnectedListViewConstIteratorT
153: public ItemConnectedListViewConstIterator
154{
155 friend class ItemConnectedListViewT<ItemType>;
156
157 private:
158
159 ItemConnectedListViewConstIteratorT(ItemSharedInfo* shared_info, const Int32* ARCANE_RESTRICT local_id_ptr,
160 Int32 local_id_offset)
161 : ItemConnectedListViewConstIterator(shared_info, local_id_ptr, local_id_offset)
162 {}
163
164 public:
165
166 typedef ItemConnectedListViewConstIteratorT<ItemType> ThatClass;
167 typedef ItemType value_type;
168
169 public:
170
171 //TODO A supprimer avec le C++20
172 typedef const Item* pointer;
173 //TODO A supprimer avec le C++20
174 typedef const Item& reference;
175
176 public:
177
178 ItemType operator*() const
179 {
180 return ItemType(*m_local_id_ptr, m_shared_info);
181 }
182 ThatClass& operator++()
183 {
184 ++m_local_id_ptr;
185 return (*this);
186 }
187 ThatClass& operator--()
188 {
189 --m_local_id_ptr;
190 return (*this);
191 }
192 difference_type operator-(const ThatClass& b) const
193 {
194 return this->m_local_id_ptr - b.m_local_id_ptr;
195 }
196 friend ThatClass operator-(const ThatClass& a, difference_type v)
197 {
198 const Int32* ptr = a.m_local_id_ptr - v;
199 return ThatClass(a.m_shared_info, ptr);
200 }
201 friend ThatClass operator+(const ThatClass& a, difference_type v)
202 {
203 const Int32* ptr = a.m_local_id_ptr + v;
204 return ThatClass(a.m_shared_info, ptr);
205 }
206
207 public:
208
209 ARCANE_DEPRECATED_REASON("Y2022: This method returns a temporary. Use 'operator*' instead")
210 ItemType operator->() const
211 {
212 return this->_itemInternal();
213 }
214};
215
216/*---------------------------------------------------------------------------*/
217/*---------------------------------------------------------------------------*/
218
226template <int Extent>
227class ItemConnectedListView
228{
229 friend ItemVector;
230 friend class ItemEnumeratorBase;
231 friend class ItemVectorView;
232 friend class ItemConnectedEnumeratorBase;
233 template <typename ItemType> friend class ItemEnumeratorBaseT;
234
235 public:
236
237 using const_iterator = ItemConnectedListViewConstIterator;
238 using difference_type = std::ptrdiff_t;
239 using value_type = Item;
240 using reference_type = Item&;
241 using const_reference_type = const Item&;
242 // TODO: Create the 'Sentinel' type when we are in C++20
243 using SentinelType = const_iterator;
244
245 public:
246
247 ItemConnectedListView() = default;
248
249 protected:
250
251 ItemConnectedListView(const impl::ItemIndexedListView<DynExtent>& view)
252 : m_index_view(view.m_local_ids, view.m_local_id_offset, 0)
253 , m_shared_info(view.m_shared_info)
254 {}
255 ItemConnectedListView(ItemSharedInfo* shared_info, ConstArrayView<Int32> local_ids, Int32 local_id_offset)
256 : m_index_view(local_ids, local_id_offset, 0)
257 , m_shared_info(shared_info)
258 {}
259
260 public:
261
264 {
265 return Item(m_index_view[index], m_shared_info);
266 }
267
269 Int32 size() const { return m_index_view.size(); }
270
272 const_iterator begin() const
273 {
274 return const_iterator(m_shared_info, m_index_view._data(), _localIdOffset());
275 }
276
278 SentinelType end() const
279 {
280 return endIterator();
281 }
282
284 const_iterator endIterator() const
285 {
286 return const_iterator(m_shared_info, (m_index_view._data() + this->size()), _localIdOffset());
287 }
288
289 friend std::ostream& operator<<(std::ostream& o, const ItemConnectedListView<Extent>& a)
290 {
291 o << a.m_index_view;
292 return o;
293 }
294
295 ARCANE_DEPRECATED_REASON("Y2023: Use iterator to get values or use operator[]")
296 Int32ConstArrayView localIds() const { return m_index_view._localIds(); }
297
298#ifdef ARCANE_HIDE_ITEM_CONNECTIVITY_STRUCTURE
299 private:
300
301#else
302 public:
303#endif
304
305 // Temporary to make sources compatible
306 operator ItemInternalVectorView() const
307 {
308 return ItemInternalVectorView(m_shared_info, m_index_view._localIds(), _localIdOffset());
309 }
310
311 // TODO: deprecate
312 inline ItemEnumerator enumerator() const;
313
314 private:
315
318 {
319 return m_index_view;
320 }
321
324 {
325 return m_index_view._localIds();
326 }
327
328 protected:
329
330 ItemIndexArrayView m_index_view;
331 ItemSharedInfo* m_shared_info = ItemSharedInfo::nullInstance();
332
333 protected:
334
335 const Int32* _localIdsData() const { return m_index_view._data(); }
336 Int32 _localIdOffset() const { return m_index_view._localIdOffset(); }
337};
338
339/*---------------------------------------------------------------------------*/
340/*---------------------------------------------------------------------------*/
341
345template <typename ItemType, int Extent>
346class ItemConnectedListViewT
347: public ItemConnectedListView<Extent>
348{
349 friend class ItemVectorT<ItemType>;
350 friend class ItemEnumeratorBaseT<ItemType>;
351 friend class ItemEnumerator;
352 friend class Item;
353 friend class ItemWithNodes;
354 friend class Node;
355 friend class Edge;
356 friend class Face;
357 friend class Cell;
358 friend class Particle;
359 friend class DoF;
360 template <typename T> friend class ItemConnectedEnumeratorBaseT;
361
362 using BaseClass = ItemConnectedListView<Extent>;
363 using BaseClass::m_index_view;
364 using BaseClass::m_shared_info;
365
366 public:
367
369 using difference_type = std::ptrdiff_t;
370 using value_type = ItemType;
371 // TODO: Create the 'Sentinel' type when we are in C++20
372 using SentinelType = const_iterator;
373
374 private:
375
376 ItemConnectedListViewT() = default;
377 ItemConnectedListViewT(const ItemConnectedListView<Extent>& rhs)
378 : BaseClass(rhs)
379 {}
380 ItemConnectedListViewT(const impl::ItemIndexedListView<DynExtent>& rhs)
381 : BaseClass(rhs)
382 {}
383
384 protected:
385
386 ItemConnectedListViewT(ItemSharedInfo* shared_info, ConstArrayView<Int32> local_ids, Int32 local_id_offset)
387 : BaseClass(shared_info, local_ids, local_id_offset)
388 {}
389
390 public:
391
393 ItemType operator[](Integer index) const
394 {
395 return ItemType(m_index_view[index], m_shared_info);
396 }
397
398 public:
399
401 inline const_iterator begin() const
402 {
403 return const_iterator(m_shared_info, this->_localIdsData(), this->_localIdOffset());
404 }
405
406 inline SentinelType end() const
407 {
408 return endIterator();
409 }
410
411 inline const_iterator endIterator() const
412 {
413 return const_iterator(m_shared_info, (this->_localIdsData() + this->size()), this->_localIdOffset());
414 }
415
416#ifdef ARCANE_HIDE_ITEM_CONNECTIVITY_STRUCTURE
417 private:
418
419#else
420 public:
421#endif
422
423 // TODO: deprecate
424 inline ItemEnumeratorT<ItemType> enumerator() const
425 {
426 return ItemEnumeratorT<ItemType>(m_shared_info, m_index_view.m_view);
427 }
428};
429
430/*---------------------------------------------------------------------------*/
431/*---------------------------------------------------------------------------*/
432
433} // End namespace Arcane
434
435/*---------------------------------------------------------------------------*/
436/*---------------------------------------------------------------------------*/
437
438#endif
Constant view of an array of type T.
Iterator for the ItemConnectedListView class.
std::ptrdiff_t difference_type
Type of a distance between iterator elements of the array.
friend bool operator==(const ThatClass &lhs, const ThatClass &rhs)
Compare the iteration indices of two instances.
View of a list of entities connected to another.
SentinelType end() const
Iterator after the last connected entity.
const_iterator endIterator() const
Iterator after the last connected entity.
ItemType operator[](Integer index) const
index-th connected entity
const_iterator begin() const
Iterator over the first connected entity.
View of a list of entities connected to another entity.
SentinelType end() const
Iterator after the last connected entity.
const_iterator endIterator() const
Iterator after the last connected entity.
Int32 size() const
Number of elements in the vector.
ItemIndexArrayView indexes() const
View of the index array.
const_iterator begin() const
Iterator over the first connected entity.
Int32ConstArrayView _localIds() const
View of the index array.
Item operator[](Integer index) const
index-th connected entity
Enumerator over a typed list of entities of type ItemType.
View over an index array (localIds()) of entities.
Internal shared structure of a mesh entity.
Typed entity vector.
Definition ItemVector.h:168
Base class for a mesh element.
Definition Item.h:84
Internal view of an array of entities.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
ConstArrayView< Int32 > Int32ConstArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:482
std::int32_t Int32
Signed integer type of 32 bits.