Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemVectorView.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/* ItemVectorView.h (C) 2000-2024 */
9/* */
10/* View on a vector (indirect array) of entities. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ITEMVECTORVIEW_H
13#define ARCANE_CORE_ITEMVECTORVIEW_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/ItemInternalVectorView.h"
18#include "arcane/core/ItemIndexArrayView.h"
19#include "arcane/core/ItemInfoListView.h"
20#include "arcane/core/ItemConnectedListView.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25namespace Arcane
26{
27// For the C# wrapper
29namespace mesh
30{
32}
33/*---------------------------------------------------------------------------*/
34/*---------------------------------------------------------------------------*/
35
48class ItemVectorViewConstIterator
49{
50 protected:
51
52 friend class ItemVectorView;
53 template <int Extent> friend class ItemConnectedListView;
54
55 protected:
56
57 ItemVectorViewConstIterator(ItemSharedInfo* shared_info, const Int32* local_id_ptr, Int32 local_id_offset)
58 : m_shared_info(shared_info)
59 , m_local_id_ptr(local_id_ptr)
60 , m_local_id_offset(local_id_offset)
61 {}
62 ItemVectorViewConstIterator(ItemSharedInfo* shared_info, const Int32* local_id_ptr)
63 : m_shared_info(shared_info)
64 , m_local_id_ptr(local_id_ptr)
65 {}
66
67 public:
68
69 // Temporary (01/2023) for conversion with the new ItemConnectedListView type
70 ItemVectorViewConstIterator(const ItemConnectedListViewConstIterator& v)
71 : m_shared_info(v.m_shared_info)
72 , m_local_id_ptr(v.m_local_id_ptr)
73 , m_local_id_offset(v.m_local_id_offset)
74 {}
75
76 public:
77
78 typedef ItemVectorViewConstIterator ThatClass;
79 typedef std::random_access_iterator_tag iterator_category;
85 typedef std::ptrdiff_t difference_type;
86
87 public:
88
89 //TODO To be removed with C++20
90 typedef const Item* pointer;
91 //TODO To be removed with C++20
92 typedef const Item& reference;
93
94 public:
95
96 Item operator*() const { return Item(m_local_id_offset + (*m_local_id_ptr), m_shared_info); }
97
98 ThatClass& operator++()
99 {
100 ++m_local_id_ptr;
101 return (*this);
102 }
103 ThatClass& operator--()
104 {
105 --m_local_id_ptr;
106 return (*this);
107 }
108 void operator+=(difference_type v) { m_local_id_ptr += v; }
109 void operator-=(difference_type v) { m_local_id_ptr -= v; }
110 difference_type operator-(const ThatClass& b) const
111 {
112 return this->m_local_id_ptr - b.m_local_id_ptr;
113 }
114 friend ThatClass operator-(const ThatClass& a, difference_type v)
115 {
116 const Int32* ptr = a.m_local_id_ptr - v;
117 return ThatClass(a.m_shared_info, ptr, a.m_local_id_offset);
118 }
119 friend ThatClass operator+(const ThatClass& a, difference_type v)
120 {
121 const Int32* ptr = a.m_local_id_ptr + v;
122 return ThatClass(a.m_shared_info, ptr, a.m_local_id_offset);
123 }
124 friend bool operator<(const ThatClass& lhs, const ThatClass& rhs)
125 {
126 return lhs.m_local_id_ptr <= rhs.m_local_id_ptr;
127 }
129 friend bool operator==(const ThatClass& lhs, const ThatClass& rhs)
130 {
131 return lhs.m_local_id_ptr == rhs.m_local_id_ptr;
132 }
133 friend bool operator!=(const ThatClass& lhs, const ThatClass& rhs)
134 {
135 return !(lhs == rhs);
136 }
137
138 ARCANE_DEPRECATED_REASON("Y2022: This method returns a temporary. Use 'operator*' instead")
139 Item operator->() const { return _itemInternal(); }
140
141 protected:
142
143 ItemSharedInfo* m_shared_info;
144 const Int32* m_local_id_ptr;
145 Int32 m_local_id_offset = 0;
146
147 protected:
148
149 inline ItemInternal* _itemInternal() const
150 {
151 return m_shared_info->m_items_internal[m_local_id_offset + (*m_local_id_ptr)];
152 }
153};
154
155/*---------------------------------------------------------------------------*/
156/*---------------------------------------------------------------------------*/
157
158template <typename ItemType>
159class ItemVectorViewConstIteratorT
160: public ItemVectorViewConstIterator
161{
162 friend class ItemVectorViewT<ItemType>;
163 friend class ItemConnectedListViewT<ItemType>;
164
165 private:
166
167 ItemVectorViewConstIteratorT(ItemSharedInfo* shared_info, const Int32* ARCANE_RESTRICT local_id_ptr,
168 Int32 local_id_offset)
169 : ItemVectorViewConstIterator(shared_info, local_id_ptr, local_id_offset)
170 {}
171 ItemVectorViewConstIteratorT(ItemSharedInfo* shared_info, const Int32* ARCANE_RESTRICT local_id_ptr)
172 : ItemVectorViewConstIterator(shared_info, local_id_ptr)
173 {}
174
175 public:
176
177 // Temporary (01/2023) for conversion with the new ItemConnectedListView type
178 ItemVectorViewConstIteratorT(const ItemConnectedListViewConstIteratorT<ItemType>& v)
179 : ItemVectorViewConstIterator(v)
180 {}
181
182 public:
183
184 typedef ItemVectorViewConstIteratorT<ItemType> ThatClass;
185 typedef ItemType value_type;
186
187 public:
188
189 //TODO To be removed with C++20
190 typedef const Item* pointer;
191 //TODO To be removed with C++20
192 typedef const Item& reference;
193
194 public:
195
196 ItemType operator*() const { return ItemType(m_local_id_offset + (*m_local_id_ptr), m_shared_info); }
197
198 ThatClass& operator++()
199 {
200 ++m_local_id_ptr;
201 return (*this);
202 }
203 ThatClass& operator--()
204 {
205 --m_local_id_ptr;
206 return (*this);
207 }
208 difference_type operator-(const ThatClass& b) const
209 {
210 return this->m_local_id_ptr - b.m_local_id_ptr;
211 }
212 friend ThatClass operator-(const ThatClass& a, difference_type v)
213 {
214 const Int32* ptr = a.m_local_id_ptr - v;
215 return ThatClass(a.m_shared_info, ptr, a.m_local_id_offset);
216 }
217 friend ThatClass operator+(const ThatClass& a, difference_type v)
218 {
219 const Int32* ptr = a.m_local_id_ptr + v;
220 return ThatClass(a.m_shared_info, ptr, a.m_local_id_offset);
221 }
222
223 public:
224
225 ARCANE_DEPRECATED_REASON("Y2022: This method returns a temporary. Use 'operator*' instead")
226 ItemType operator->() const { return this->_itemInternal(); }
227};
228
229/*---------------------------------------------------------------------------*/
230/*---------------------------------------------------------------------------*/
231
239class ARCANE_CORE_EXPORT ItemVectorView
240{
241 // NOTE: This class is mapped to C# and if its structure changes,
242 // the corresponding C# version must be updated.
243
244 friend ItemVector;
245 friend ItemEnumeratorBase;
247
248 public:
249
250 using const_iterator = ItemVectorViewConstIterator;
251 using difference_type = std::ptrdiff_t;
252 using value_type = Item;
253 using reference_type = Item&;
254 using const_reference_type = const Item&;
255 // TODO: Create the 'Sentinel' type when we are in C++20
256 using SentinelType = const_iterator;
257
258 public:
259
260 ARCANE_DEPRECATED_REASON("Y2022: Use constructor with ItemInfoListView instead")
261 ItemVectorView(const ItemInternalArrayView& aitems, const Int32ConstArrayView& local_ids)
262 : m_index_view(local_ids)
263 {
264 _init(aitems);
265 }
266
267 ARCANE_DEPRECATED_REASON("Y2022: Use constructor with ItemInfoListView instead")
268 ItemVectorView(ItemInternalArrayView aitems, ItemIndexArrayView indexes)
269 : m_index_view(indexes)
270 {
271 _init(aitems);
272 }
273
274 public:
275
276 ItemVectorView() = default;
277 // TODO Deprecate (3.11+)
278 ItemVectorView(const ItemInternalVectorView& view)
279 : m_index_view(view.localIds(), view.m_local_id_offset, 0)
280 , m_shared_info(view.m_shared_info)
281 {}
282 // TODO To be removed
283 ItemVectorView(ItemInfoListView item_info_list_view, ConstArrayView<Int32> local_ids)
284 : m_index_view(local_ids, 0, 0)
285 , m_shared_info(item_info_list_view.m_item_shared_info)
286 {}
287 ItemVectorView(ItemInfoListView item_info_list_view, ItemIndexArrayView indexes)
288 : m_index_view(indexes)
289 , m_shared_info(item_info_list_view.m_item_shared_info)
290 {}
291 ItemVectorView(IItemFamily* family, ConstArrayView<Int32> local_ids);
292 ItemVectorView(IItemFamily* family, ItemIndexArrayView indexes);
293 ItemVectorView(const impl::ItemIndexedListView<DynExtent>& view)
294 : m_index_view(view.constLocalIds(), view.m_local_id_offset, 0)
295 , m_shared_info(view.m_shared_info)
296 {}
297
298 // Temporary (01/2023) for conversion with the new ItemConnectedListView type
299 ItemVectorView(const ItemConnectedListView<DynExtent>& v)
300 : m_index_view(v.m_index_view)
301 , m_shared_info(v.m_shared_info)
302 {}
303
304 protected:
305
306 ItemVectorView(ItemSharedInfo* shared_info, const impl::ItemLocalIdListContainerView& local_ids)
307 : m_index_view(local_ids)
308 , m_shared_info(shared_info)
309 {}
310
311 ItemVectorView(ItemSharedInfo* shared_info, ConstArrayView<Int32> local_ids, Int32 local_id_offset)
312 : m_index_view(local_ids, local_id_offset, 0)
313 , m_shared_info(shared_info)
314 {}
315
316 // Temporary to avoid a compilation warning when using the
317 // deprecated constructor of ItemVectorViewT
318 ItemVectorView(const ItemInternalArrayView& aitems, const Int32ConstArrayView& local_ids, bool)
319 : m_index_view(local_ids)
320 {
321 _init(aitems);
322 }
323
324 // Temporary to avoid a compilation warning when using the
325 // deprecated constructor of ItemVectorViewT
326 ItemVectorView(ItemInternalArrayView aitems, ItemIndexArrayView indexes, bool)
327 : m_index_view(indexes)
328 {
329 _init(aitems);
330 }
331
332 public:
333
334 // TODO to be removed
335 operator ItemInternalVectorView() const
336 {
337 return ItemInternalVectorView(m_shared_info, m_index_view._localIds(), _localIdOffset());
338 }
339
341 Item operator[](Integer index) const { return Item(m_index_view[index], m_shared_info); }
342
344 Int32 size() const { return m_index_view.size(); }
345
347 ARCANE_DEPRECATED_REASON("Y2022: Do not use this method")
348 ItemInternalArrayView items() const { return m_shared_info->m_items_internal; }
349
350 // TODO Deprecate (3.11+)
358 Int32ConstArrayView localIds() const { return m_index_view._localIds(); }
359
361 void fillLocalIds(Array<Int32>& ids) const;
362
364 ItemVectorView subView(Integer abegin, Integer asize) const
365 {
366 return ItemVectorView(m_shared_info, m_index_view.subView(abegin, asize)._localIds(), _localIdOffset());
367 }
368 const_iterator begin() const
369 {
370 return const_iterator(m_shared_info, m_index_view._data(), _localIdOffset());
371 }
372 SentinelType end() const
373 {
374 return endIterator();
375 }
376 const_iterator endIterator() const
377 {
378 return const_iterator(m_shared_info, (m_index_view._data() + this->size()), _localIdOffset());
379 }
381 ItemIndexArrayView indexes() const { return m_index_view; }
382
383 public:
384
385 inline ItemEnumerator enumerator() const;
386
387 protected:
388
389 ItemIndexArrayView m_index_view;
390 ItemSharedInfo* m_shared_info = ItemSharedInfo::nullInstance();
391
392 protected:
393
394 const Int32* _localIdsData() const { return m_index_view._data(); }
395 Int32 _localIdOffset() const { return m_index_view._localIdOffset(); }
396
397 private:
398
399 void _init(ItemInternalArrayView items)
400 {
401 m_shared_info = (size() > 0 && !items.empty()) ? ItemInternalCompatibility::_getSharedInfo(items[0]) : ItemSharedInfo::nullInstance();
402 }
403 void _init2(IItemFamily* family);
404
405 public:
406
407 // For SWIG to position the values in the POD instance
408 void _internalSwigSet(ItemVectorViewPOD* vpod);
409};
410
411/*---------------------------------------------------------------------------*/
412/*---------------------------------------------------------------------------*/
413
417template <typename ItemType>
418class ItemVectorViewT
419: public ItemVectorView
420{
421 friend class ItemVectorT<ItemType>;
422 friend class ItemConnectedListViewT<ItemType>;
423
424 public:
425
426 using const_iterator = ItemVectorViewConstIteratorT<ItemType>;
427 using difference_type = std::ptrdiff_t;
428 using value_type = ItemType;
429 //TODO to be removed with C++20
430 using reference_type = ItemType&;
431 //TODO to be removed with C++20
432 using const_reference_type = const ItemType&;
433 // TODO: Create the 'Sentinel' type when we are in C++20
434 using SentinelType = const_iterator;
435
436 public:
437
438 ARCANE_DEPRECATED_REASON("Y2022: Use constructor with ItemInfoListView instead")
439 ItemVectorViewT(const ItemInternalArrayView& aitems, const Int32ConstArrayView& local_ids)
440 : ItemVectorView(aitems, local_ids, true)
441 {}
442
443 ARCANE_DEPRECATED_REASON("Y2022: Use constructor with ItemInfoListView instead")
444 ItemVectorViewT(ItemInternalArrayView aitems, ItemIndexArrayView indexes)
445 : ItemVectorView(aitems, indexes, true)
446 {}
447
448 public:
449
450 ItemVectorViewT() = default;
451 ItemVectorViewT(const ItemVectorView& rhs)
452 : ItemVectorView(rhs)
453 {}
454 inline ItemVectorViewT(const ItemVectorT<ItemType>& rhs);
455 ItemVectorViewT(const ItemInternalVectorView& rhs)
456 : ItemVectorView(rhs)
457 {}
458 ItemVectorViewT(const impl::ItemIndexedListView<DynExtent>& rhs)
459 : ItemVectorView(rhs)
460 {}
461 ItemVectorViewT(ItemInfoListView item_info_list_view, ConstArrayView<Int32> local_ids)
462 : ItemVectorView(item_info_list_view, local_ids)
463 {}
464 ItemVectorViewT(ItemInfoListView item_info_list_view, ItemIndexArrayView indexes)
465 : ItemVectorView(item_info_list_view, indexes)
466 {}
467 ItemVectorViewT(IItemFamily* family, ConstArrayView<Int32> local_ids)
468 : ItemVectorView(family, local_ids)
469 {}
470 ItemVectorViewT(IItemFamily* family, ItemIndexArrayView indexes)
471 : ItemVectorView(family, indexes)
472 {}
473
474 // Temporary (01/2023) for conversion with the new ItemConnectedListView type
475 ItemVectorViewT(const ItemConnectedListViewT<ItemType>& v)
476 : ItemVectorView(v)
477 {}
478
479 protected:
480
481 ItemVectorViewT(ItemSharedInfo* shared_info, ConstArrayView<Int32> local_ids, Int32 local_id_offset)
482 : ItemVectorView(shared_info, local_ids, local_id_offset)
483 {}
484
485 public:
486
487 ItemType operator[](Integer index) const
488 {
489 return ItemType(m_index_view[index], m_shared_info);
490 }
491
492 public:
493
494 inline ItemEnumeratorT<ItemType> enumerator() const
495 {
496 return ItemEnumeratorT<ItemType>(m_shared_info, m_index_view.m_view);
497 }
498 inline const_iterator begin() const
499 {
500 return const_iterator(m_shared_info, _localIdsData(), _localIdOffset());
501 }
502 inline SentinelType end() const
503 {
504 return const_iterator(m_shared_info, _localIdsData() + this->size(), _localIdOffset());
505 }
506 inline const_iterator endIterator() const
507 {
508 return const_iterator(m_shared_info, _localIdsData() + this->size(), _localIdOffset());
509 }
510};
511
512/*---------------------------------------------------------------------------*/
513/*---------------------------------------------------------------------------*/
514
515} // End namespace Arcane
516
517/*---------------------------------------------------------------------------*/
518/*---------------------------------------------------------------------------*/
519
520#endif
Base class for 1D data vectors.
Constant view of an array of type T.
Interface of an entity family.
Definition IItemFamily.h:83
Iterator for the ItemConnectedListView class.
View of a list of entities connected to another.
View of a list of entities connected to another entity.
Enumerator over a typed list of entities of type ItemType.
Enumerator over a list of entities.
View over an index array (localIds()) of entities.
View of a list to obtain information about entities.
Internal view on an array of entities.
Int32ConstArrayView localIds() const
Array of local entity IDs.
Internal shared structure of a mesh entity.
Typed entity vector.
Definition ItemVector.h:168
Iterator for the ItemVectorView class.
friend bool operator==(const ThatClass &lhs, const ThatClass &rhs)
Compare the iteration indices of two instances.
Integer size_type
Type indexing the array.
std::ptrdiff_t difference_type
Type of a distance between iterator elements of the array.
Item value_type
Type indexing the array.
View on a typed array of entities.
ItemVectorView subView(Integer abegin, Integer asize) const
Sub-view starting from element abegin and containing asize elements.
Int32 size() const
Number of elements in the vector.
ItemIndexArrayView indexes() const
View on the array of indices.
Int32ConstArrayView localIds() const
Array of local IDs of entities.
ItemInternalArrayView items() const
Array of entities.
Item operator[](Integer index) const
Access the i-th element of the vector.
Base class for a mesh element.
Definition Item.h:84
Internal view of an array of entities.
View over the container of a list of ItemLocalId.
-- 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.