Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ItemEnumeratorBase.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/* ItemEnumeratorBase.h (C) 2000-2024 */
9/* */
10/* Base class for enumerators over mesh entities. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ITEMENUMERATORBASE_H
13#define ARCANE_CORE_ITEMENUMERATORBASE_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/ItemInternalEnumerator.h"
18#include "arcane/core/Item.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29class ItemEnumeratorCS;
30class ItemGroupImpl;
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35/*!
36 * \brief Represents an index of an enumeration over an entity.
37 */
38class ItemEnumeratorIndex
39{
40 public:
41
42 ItemEnumeratorIndex() = default;
43 constexpr ARCCORE_HOST_DEVICE explicit ItemEnumeratorIndex(Int32 index)
44 : m_index(index)
45 {}
46 constexpr ARCCORE_HOST_DEVICE Int32 index() const { return m_index; }
47 constexpr ARCCORE_HOST_DEVICE Int32 asInt32() const { return m_index; }
48
49 private:
50
51 Int32 m_index = -1;
52};
53
54/*---------------------------------------------------------------------------*/
55/*---------------------------------------------------------------------------*/
56
57/*!
58 * \brief Represents an index of an enumeration over an entity \a ItemType.
59 */
60template <typename ItemType>
61class ItemEnumeratorIndexT
62: public ItemEnumeratorIndex
63{
64 public:
65
66 ItemEnumeratorIndexT() = default;
67 constexpr ARCCORE_HOST_DEVICE explicit ItemEnumeratorIndexT(Int32 index)
68 : ItemEnumeratorIndex(index)
69 {}
70};
71
72/*---------------------------------------------------------------------------*/
73/*---------------------------------------------------------------------------*/
74
75/*!
76 * \brief Base class for enumerators over a list of entities.
77 *
78 * Instances of this class are created either via ItemEnumerator or via ItemEnumeratorT.
79 */
80class ItemEnumeratorBase
81{
82 private:
83
84 using ItemInternalPtr = ItemInternal*;
85
86 protected:
87
88 ItemEnumeratorBase() = default;
89 ItemEnumeratorBase(const ItemInternalPtr*, const Int32* local_ids, Integer n, const ItemGroupImpl* agroup)
90 // TODO: manage offset
91 : m_view(local_ids, n, 0)
92 , m_group_impl(agroup)
93 {}
94 explicit ItemEnumeratorBase(const Int32ConstArrayView& local_ids)
95 // TODO: manage offset
96 : m_view(local_ids, 0)
97 , m_group_impl(nullptr)
98 {}
99 ItemEnumeratorBase(const Int32ConstArrayView& local_ids, const ItemGroupImpl* agroup)
100 // TODO: manage offset
101 : m_view(local_ids, 0)
102 , m_group_impl(agroup)
103 {}
104 // TODO: To be removed
105 ItemEnumeratorBase(const ItemInternalVectorView& view, const ItemGroupImpl* agroup)
106 : m_view(view.localIds(), view.m_local_id_offset)
107 , m_group_impl(agroup)
108 {}
109 ItemEnumeratorBase(const ItemVectorView& rhs)
110 : m_view(rhs.localIds(), rhs._localIdOffset())
111 {}
112 template <int E> ItemEnumeratorBase(const ItemConnectedListView<E>& rhs)
113 : m_view(rhs._localIds(), rhs._localIdOffset())
114 {}
115
116 ItemEnumeratorBase(const ItemEnumerator& rhs);
117
118 public:
119
120 //! Increments the enumerator index
121 constexpr void operator++() { ++m_index; }
122 constexpr bool operator()() { return m_index < m_view.m_size; }
123
124 //! True if the end of the enumerator has not been reached (index()<count())
125 constexpr bool hasNext() { return m_index < m_view.m_size; }
126
127 //! Number of elements in the enumerator
128 constexpr Integer count() const { return m_view.m_size; }
129
130 //! Current index of the enumerator
131 constexpr Integer index() const { return m_index; }
132
133 //! localId() of the current entity.
134 Int32 itemLocalId() const { return m_view.localId(m_index); }
135
136 //! localId() of the current entity.
137 Int32 localId() const { return m_view.localId(m_index); }
138
139 /*!
140 * \internal
141 * \brief Local indices.
142 */
143 ARCANE_DEPRECATED_REASON("Y2022: This method is internal to Arcane")
144 constexpr const Int32* unguardedLocalIds() const { return m_view.m_local_ids; }
145
146 /*!
147 * \brief Underlying group if it exists (nullptr otherwise).
148 *
149 * \brief This aims to test that accesses via this enumerator on a partial object are legitimate.
150 */
151 constexpr const ItemGroupImpl* group() const { return m_group_impl; }
152
153 static constexpr int version() { return 3; }
154
155 protected:
156
157 impl::ItemLocalIdListContainerView m_view;
158 Int32 m_index = 0;
159 const ItemGroupImpl* m_group_impl = nullptr; // could be removed in release mode if necessary
160
161 protected:
162
163 //! Constructor only used by fromItemEnumerator()
164 ItemEnumeratorBase(const ItemEnumerator& rhs, bool);
165
166 ItemEnumeratorBase(const impl::ItemLocalIdListContainerView& view, Int32 index, const ItemGroupImpl* agroup)
167 : m_view(view)
168 , m_index(index)
169 , m_group_impl(agroup)
170 {
171 }
172
173 explicit ItemEnumeratorBase(const impl::ItemLocalIdListContainerView& view)
174 : m_view(view)
175 {
176 }
177
178 ItemInternal* _internal(ItemSharedInfo* si) const
179 {
180 return si->m_items_internal[m_view.localId(m_index)];
181 }
182 constexpr const ItemInternalPtr* _unguardedItems(ItemSharedInfo* si) const
183 {
184 return si->m_items_internal.data();
185 }
186
187 private:
188};
189
190/*---------------------------------------------------------------------------*/
191/*---------------------------------------------------------------------------*/
192
193/*!
194 * \brief Base class for enumerators over a list of entities.
195 *
196 * Instances of this class are created either via ItemEnumerator or via ItemEnumeratorT.
197 */
198template <typename ItemType>
199class ItemEnumeratorBaseT
200: public ItemEnumeratorBase
201{
202 friend class SimdItemEnumeratorBase;
203
204 private:
205
206 using ItemInternalPtr = ItemInternal*;
207 using LocalIdType = typename ItemType::LocalIdType;
208 using BaseClass = ItemEnumeratorBase;
209
210 protected:
211
212 ItemEnumeratorBaseT()
213 : BaseClass()
214 , m_item(NULL_ITEM_LOCAL_ID, ItemSharedInfo::nullInstance())
215 {}
216 // TODO: manage offset
217 ItemEnumeratorBaseT(ItemSharedInfo* shared_info, const Int32ConstArrayView& local_ids)
218 : BaseClass(local_ids)
219 , m_item(NULL_ITEM_LOCAL_ID, shared_info)
220 {}
221 // TODO: manage offset
222 ItemEnumeratorBaseT(const ItemInfoListView& items, const Int32ConstArrayView& local_ids, const ItemGroupImpl* agroup)
223 : BaseClass(local_ids, agroup)
224 , m_item(NULL_ITEM_LOCAL_ID, items.m_item_shared_info)
225 {}
226 ItemEnumeratorBaseT(const ItemInternalVectorView& view, const ItemGroupImpl* agroup)
227 : BaseClass(view, agroup)
228 , m_item(NULL_ITEM_LOCAL_ID, view.m_shared_info)
229 {}
230 ItemEnumeratorBaseT(const ItemVectorView& rhs)
231 : ItemEnumeratorBaseT((const ItemInternalVectorView&)rhs, nullptr)
232 {}
233 ItemEnumeratorBaseT(const ItemVectorViewT<ItemType>& rhs)
234 : ItemEnumeratorBaseT((const ItemInternalVectorView&)rhs, nullptr)
235 {}
236
237 ItemEnumeratorBaseT(const ItemEnumerator& rhs);
238 ItemEnumeratorBaseT(const impl::ItemIndexedListView<DynExtent>& view)
239 : ItemEnumeratorBaseT(view.m_shared_info, view.constLocalIds())
240 {}
241
242 ItemEnumeratorBaseT(const ItemConnectedListViewT<ItemType>& rhs)
243 : BaseClass(rhs)
244 , m_item(NULL_ITEM_LOCAL_ID, rhs.m_shared_info)
245 {}
246
247 ItemEnumeratorBaseT(ItemSharedInfo* si, const impl::ItemLocalIdListContainerView& view)
248 : BaseClass(view)
249 , m_item(NULL_ITEM_LOCAL_ID, si)
250 {
251 }
252
253 protected:
254
255 // TODO: to be removed
256 ItemEnumeratorBaseT(const ItemInternalPtr* items, const Int32* local_ids, Integer n, const ItemGroupImpl* agroup)
257 : BaseClass(items, local_ids, n, agroup)
258 {
259 _init(items);
260 }
261 // TODO: to be removed
262 ItemEnumeratorBaseT(const ItemInternalArrayView& items, const Int32ConstArrayView& local_ids, const ItemGroupImpl* agroup)
263 : BaseClass(local_ids, agroup)
264 {
265 _init(items.data());
266 }
267 // TODO: to be removed
268 ItemEnumeratorBaseT(const ItemInternalEnumerator& rhs);
269
270 public:
271
272 /*!
273 * \internal
274 * \brief List of ItemInternal.
275 * NOTE: In Arcane, this method is used only for the C# wrapper. To be removed later.
276 */
277 ARCANE_DEPRECATED_REASON("Y2022: This method is internal to Arcane")
278 constexpr const ItemInternalPtr* unguardedItems() const { return _unguardedItems(m_item.m_shared_info); }
279
280 /*!
281 * \internal
282 * \brief Internal part (for internal use only).
283 */
284 ARCANE_DEPRECATED_REASON("Y2022: This method is internal to Arcane")
285 constexpr ItemInternal* internal() const { return _internal(m_item.m_shared_info); }
286
287 public:
288
289 constexpr ItemType operator*() const
290 {
291 m_item.m_local_id = m_view.localId(m_index);
292 return m_item;
293 }
294 constexpr const ItemType* operator->() const
295 {
296 m_item.m_local_id = m_view.localId(m_index);
297 return &m_item;
298 }
299
300 constexpr LocalIdType asItemLocalId() const
301 {
302 return LocalIdType{ m_view.localId(m_index) };
303 }
304
305 constexpr operator LocalIdType() const
306 {
307 return LocalIdType{ m_view.localId(m_index) };
308 }
309
310 ItemEnumerator toItemEnumerator() const;
311
312 public:
313
314 impl::ItemBase _internalItemBase() const { return m_item.itemBase(); }
315
316 protected:
317
318 mutable ItemType m_item = ItemType(NULL_ITEM_LOCAL_ID, nullptr);
319
320 protected:
321
322 //! Constructor only used by fromItemEnumerator()
324
325 ItemEnumeratorBaseT(const impl::ItemLocalIdListContainerView& view, Int32 index,
326 const ItemGroupImpl* agroup, Item item_base)
327 : ItemEnumeratorBase(view, index, agroup)
328 , m_item(item_base)
329 {
330 }
331
332 void _init(const ItemInternalPtr* items)
333 {
334 m_item.m_shared_info = ItemInternalCompatibility::_getSharedInfo(items, count());
335 }
336};
337
338/*---------------------------------------------------------------------------*/
339/*---------------------------------------------------------------------------*/
340
341} // End namespace Arcane
342
343/*---------------------------------------------------------------------------*/
344/*---------------------------------------------------------------------------*/
345
346#endif
View of a list of entities connected to another.
View of a list of entities connected to another entity.
ItemEnumeratorBaseT(const ItemEnumerator &rhs, bool)
Constructor only used by fromItemEnumerator().
Int32 localId() const
localId() of the current entity.
Int32 itemLocalId() const
localId() of the current entity.
constexpr Integer count() const
Number of elements in the enumerator.
constexpr const ItemGroupImpl * group() const
Underlying group if it exists (nullptr otherwise).
constexpr bool hasNext()
True if the end of the enumerator has not been reached (index()<count()).
constexpr void operator++()
Increments the enumerator index.
constexpr Integer index() const
Current index of the enumerator.
Enumerator over a list of entities.
View of a list to obtain information about entities.
Int32ConstArrayView localIds() const
Array of local entity IDs.
View on a typed array of entities.
View on a vector of entities.
Int32ConstArrayView localIds() const
Array of local IDs of entities.
Base class for a mesh element.
Definition Item.h:84
-- 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
Int32 LocalIdType
Type of integers used to store local identifiers of entities.
std::int32_t Int32
Signed integer type of 32 bits.