Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemConnectedEnumeratorBase.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/* ItemConnectedEnumeratorBase.h (C) 2000-2025 */
9/* */
10/* Base class for enumerators over connected entities of the mesh. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ITEMCONNECTEDENUMERATORBASE_H
13#define ARCANE_CORE_ITEMCONNECTEDENUMERATORBASE_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
40class ItemConnectedEnumeratorBase
41{
42 // Only these classes are allowed to construct instances of this class
43 template <typename T> friend class ItemConnectedEnumeratorBaseT;
44
45 private:
46
47 ItemConnectedEnumeratorBase() = default;
48 explicit ItemConnectedEnumeratorBase(const ConstArrayView<Int32> local_ids)
49 : m_local_ids(local_ids.data())
50 , m_count(local_ids.size())
51 {}
52 template <int E> explicit ItemConnectedEnumeratorBase(const ItemConnectedListView<E>& rhs)
53 : m_local_ids(rhs._localIds().data())
54 , m_count(rhs._localIds().size())
55 , m_local_id_offset(rhs._localIdOffset())
56 {}
57 ItemConnectedEnumeratorBase(const Int32* local_ids, Int32 index, Int32 n)
58 : m_local_ids(local_ids)
59 , m_index(index)
60 , m_count(n)
61 {
62 }
63
64 public:
65
67 constexpr void operator++()
68 {
69 ++m_index;
70 }
71
73 constexpr bool operator()() const
74 {
75 return m_index < m_count;
76 }
77
79 constexpr bool hasNext() const { return m_index < m_count; }
80
82 constexpr Int32 count() const { return m_count; }
83
85 constexpr Int32 index() const { return m_index; }
86
88 constexpr ItemLocalId itemLocalId() const { return ItemLocalId(m_local_id_offset + m_local_ids[m_index]); }
89
91 constexpr Int32 localId() const { return m_local_id_offset + m_local_ids[m_index]; }
92
93 protected:
94
95 const Int32* ARCANE_RESTRICT m_local_ids = nullptr;
96 Int32 m_index = 0;
97 Int32 m_count = 0;
98 Int32 m_local_id_offset = 0;
99};
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
103
110template <typename ItemType>
111class ItemConnectedEnumeratorBaseT
112: public ItemConnectedEnumeratorBase
113{
114 friend class ItemConnectedEnumerator;
115 friend class ItemConnectedEnumeratorT<ItemType>;
116
117 private:
118
119 using LocalIdType = typename ItemType::LocalIdType;
120 using BaseClass = ItemConnectedEnumeratorBase;
121
122 private:
123
124 ItemConnectedEnumeratorBaseT()
125 : BaseClass()
126 , m_item(NULL_ITEM_LOCAL_ID, ItemSharedInfo::nullInstance())
127 {}
128
129 ItemConnectedEnumeratorBaseT(ItemSharedInfo* shared_info, const Int32ConstArrayView& local_ids)
130 : BaseClass(local_ids)
131 , m_item(NULL_ITEM_LOCAL_ID, shared_info)
132 {}
133
134 ItemConnectedEnumeratorBaseT(const impl::ItemIndexedListView<DynExtent>& view)
135 : ItemConnectedEnumeratorBaseT(view.m_shared_info, view.constLocalIds())
136 {}
137
138 ItemConnectedEnumeratorBaseT(const ItemConnectedListViewT<ItemType>& rhs)
139 : BaseClass(rhs)
140 , m_item(NULL_ITEM_LOCAL_ID, rhs.m_shared_info)
141 {}
142
143 ItemConnectedEnumeratorBaseT(const Int32* local_ids, Int32 index, Int32 n, Item item_base)
144 : ItemConnectedEnumeratorBase(local_ids, index, n)
145 , m_item(item_base)
146 {
147 }
148
149 public:
150
151 constexpr ItemType operator*() const
152 {
153 m_item.m_local_id = m_local_id_offset + m_local_ids[m_index];
154 return m_item;
155 }
156 constexpr const ItemType* operator->() const
157 {
158 m_item.m_local_id = m_local_id_offset + m_local_ids[m_index];
159 return &m_item;
160 }
161
162 constexpr LocalIdType asItemLocalId() const
163 {
164 return LocalIdType{ m_local_id_offset + m_local_ids[m_index] };
165 }
166
167 protected:
168
169 mutable ItemType m_item = ItemType(NULL_ITEM_LOCAL_ID, nullptr);
170};
171
172/*---------------------------------------------------------------------------*/
173/*---------------------------------------------------------------------------*/
174
175} // End namespace Arcane
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
180#endif
Constant view of an array of type T.
constexpr const_pointer data() const noexcept
Pointer to the allocated memory.
constexpr Integer size() const noexcept
Number of elements in the array.
constexpr void operator++()
Increments the enumerator index.
constexpr Int32 count() const
Number of elements in the enumerator.
constexpr bool operator()() const
True if the end of the enumerator has not been reached (index()<count()).
constexpr ItemLocalId itemLocalId() const
localId() of the current entity.
constexpr Int32 localId() const
localId() of the current entity.
constexpr Int32 index() const
Current index of the enumerator.
constexpr bool hasNext() const
True if the end of the enumerator has not been reached (index()<count()).
Enumerator over a typed list of connected entities of type ItemType.
View of a list of entities connected to another.
View of a list of entities connected to another entity.
Int32ConstArrayView _localIds() const
View of the index array.
Index of an Item in a variable.
Definition ItemLocalId.h:42
Internal shared structure of a mesh entity.
Base class for a mesh element.
Definition Item.h:84
Internal view of an array of entities.
ConstArrayView< Int32 > constLocalIds() const
Array of local entity IDs.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
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.