Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ItemInternalVectorView.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/* ItemInternalVectorView.h (C) 2000-2024 */
9/* */
10/* View on a vector (indirect array) of entities. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ITEMINTERNALVECTORVIEW_H
13#define ARCANE_CORE_ITEMINTERNALVECTORVIEW_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/ArrayView.h"
19#include "arcane/core/ItemSharedInfo.h"
20#include "arcane/core/ItemIndexedListView.h"
21
22#include <iterator>
23
24/*---------------------------------------------------------------------------*/
25/*---------------------------------------------------------------------------*/
26
27namespace Arcane
28{
29
30/*---------------------------------------------------------------------------*/
31/*---------------------------------------------------------------------------*/
32
33/*!
34 * \internal
35 * \brief Iterator for an ItemInternalVectorView.
36 * \deprecated Use an iterator from an ItemVectorView.
37 */
38class ItemInternalVectorViewConstIterator
39{
40 friend class ItemInternalVectorView;
41 template <int Extent> friend class ItemConnectedListView;
42 typedef ItemInternal* ItemInternalPtr;
43
44 private:
45
46 ItemInternalVectorViewConstIterator(const ItemInternalPtr* items,
47 const Int32* ARCANE_RESTRICT local_ids,
48 Integer index, Int32 local_id_offset)
49 : m_items(items)
50 , m_local_ids(local_ids)
51 , m_index(index)
52 , m_local_id_offset(local_id_offset)
53 {}
54
55 public:
56
57 typedef ItemInternalVectorViewConstIterator ThatClass;
58
59 public:
60
61 typedef std::random_access_iterator_tag iterator_category;
62 //! Type indexing the array
63 typedef const ItemInternalPtr* pointer;
64 //! Type indexing the array
65 typedef const ItemInternalPtr& reference;
66 //! Type indexing the array
67 typedef ItemInternalPtr value_type;
68 //! Type indexing the array
70 //! Type of a difference between iterator elements in the array
72
73 public:
74
75 value_type operator*() const { return m_items[m_local_id_offset + m_local_ids[m_index]]; }
76 value_type operator->() const { return m_items[m_local_id_offset + m_local_ids[m_index]]; }
77 ThatClass& operator++()
78 {
79 ++m_index;
80 return (*this);
81 }
82 ThatClass& operator--()
83 {
84 --m_index;
85 return (*this);
86 }
87 void operator+=(difference_type v) { m_index += v; }
88 void operator-=(difference_type v) { m_index -= v; }
89 friend Integer operator-(const ThatClass& a, const ThatClass& b)
90 {
91 return a.m_index - b.m_index;
92 }
93 friend ThatClass operator-(const ThatClass& a, difference_type v)
94 {
95 Integer index = a.m_index - v;
96 return ThatClass(a.m_items, a.m_local_ids, index, a.m_local_id_offset);
97 }
98 friend ThatClass operator+(const ThatClass& a, difference_type v)
99 {
100 Integer index = a.m_index + v;
101 return ThatClass(a.m_items, a.m_local_ids, index, a.m_local_id_offset);
102 }
103 friend bool operator<(const ThatClass& lhs, const ThatClass& rhs)
104 {
105 return lhs.m_index <= rhs.m_index;
106 }
107 friend bool operator==(const ThatClass& lhs, const ThatClass& rhs)
108 {
109 // TODO: check if these three comparisons cause performance problems.
110 // If so, we can only use the last one.
111 return lhs.m_items == rhs.m_items && lhs.m_local_ids == rhs.m_local_ids && lhs.m_index == rhs.m_index;
112 }
113 friend bool operator!=(const ThatClass& lhs, const ThatClass& rhs)
114 {
115 return !(lhs == rhs);
116 }
117
118 private:
119
120 const ItemInternalPtr* m_items;
121 const Int32* ARCANE_RESTRICT m_local_ids;
122 Int32 m_index;
123 Int32 m_local_id_offset = 0;
124};
125
126/*---------------------------------------------------------------------------*/
127/*---------------------------------------------------------------------------*/
128
129/*!
130 * \internal
131 * \brief Internal view on an array of entities.
132 *
133 * This class is only useful for constructing entity lists used
134 * internally by %Arcane. The user version of this class is
135 * ItemVectorView.
136 *
137 * \sa ItemVectorView
138 */
139class ARCANE_CORE_EXPORT ItemInternalVectorView
140{
141 public:
142
143 friend class ItemVectorView;
144 friend class ItemInternalConnectivityList;
145 friend class ItemBase;
146 friend class ItemEnumeratorBase;
147 friend class SimdItemEnumeratorBase;
148 friend class ItemInternalEnumerator;
149 template <int Extent> friend class ItemConnectedListView;
150 friend ItemInternal;
151 template <typename T> friend class ItemEnumeratorBaseT;
152 using const_iterator = ItemInternalVectorViewConstIterator;
153
154 public:
155
156 ItemInternalVectorView() = default;
157
158 private:
159
160 ItemInternalVectorView(ItemSharedInfo* si, Int32ConstArrayView local_ids, Int32 local_id_offset)
161 : m_local_ids(local_ids)
162 , m_shared_info(si)
163 , m_local_id_offset(local_id_offset)
164 {
165 ARCANE_ASSERT(_isValid(), ("Bad ItemInternalVectorView"));
166 }
167
168#if 0
169 ItemInternalVectorView(ItemSharedInfo* si, const Int32* local_ids, Integer count, Int32 local_id_offset)
170 : m_local_ids(count, local_ids)
171 , m_shared_info(si)
172 , m_local_id_offset(local_id_offset)
173 {
174 ARCANE_ASSERT(_isValid(), ("Bad ItemInternalVectorView"));
175 }
176#endif
177
178 ItemInternalVectorView(ItemSharedInfo* si, const impl::ItemLocalIdListContainerView& local_ids)
179 : m_local_ids(local_ids._idsWithoutOffset())
180 , m_shared_info(si)
181 , m_local_id_offset(local_ids.m_local_id_offset)
182 {
183 ARCANE_ASSERT(_isValid(), ("Bad ItemInternalVectorView"));
184 }
185
186 ItemInternalVectorView(const impl::ItemIndexedListView<DynExtent>& view)
187 : m_local_ids(view.constLocalIds())
188 , m_shared_info(view.m_shared_info)
189 , m_local_id_offset(view.m_local_id_offset)
190 {}
191
192 public:
193
194 //! Number of elements in the vector
195 Integer size() const { return m_local_ids.size(); }
196
197 // TODO: to be removed
198 //! Array of local entity IDs
199 Int32ConstArrayView localIds() const { return m_local_ids; }
200
201 public:
202
203 /*!
204 * \brief Accesses the i-th element of the vector.
205 *
206 * This method is obsolete. You must construct an 'ItemVectorView' instead
207 * and use the associated 'operator[]'.
208 */
209 ARCANE_DEPRECATED_REASON("Y2022: Use ItemVectorView::operator[] instead")
210 ItemInternal* operator[](Integer index) const { return m_shared_info->m_items_internal[m_local_ids[index]]; }
211
212 //! Array of entities
213 ARCANE_DEPRECATED_REASON("Y2022: Do not use this method")
214 ItemInternalArrayView items() const { return m_shared_info->m_items_internal; }
215
216 ARCANE_DEPRECATED_REASON("Y2022: Use ItemVectorView to iterate")
217 const_iterator begin() const
218 {
219 return const_iterator(_items().data(), m_local_ids.data(), 0, m_local_id_offset);
220 }
221
222 ARCANE_DEPRECATED_REASON("Y2022: Use ItemVectorView to iterate")
223 const_iterator end() const
224 {
225 return const_iterator(_items().data(), m_local_ids.data(), this->size(), m_local_id_offset);
226 }
227
228 protected:
229
230 Int32 localIdOffset() const { return m_local_id_offset; }
231
232 protected:
233
234 Int32ConstArrayView m_local_ids;
235 ItemSharedInfo* m_shared_info = ItemSharedInfo::nullInstance();
236 Int32 m_local_id_offset = 0;
237
238 private:
239
240 bool _isValid();
241 ItemInternalArrayView _items() const { return m_shared_info->m_items_internal; }
242};
243
244/*---------------------------------------------------------------------------*/
245/*---------------------------------------------------------------------------*/
246
247} // End namespace Arcane
248
249/*---------------------------------------------------------------------------*/
250/*---------------------------------------------------------------------------*/
251
252#endif
Declarations of types on entities.
const ItemInternalPtr * pointer
Type indexing the array.
ItemInternalPtr value_type
Type indexing the array.
Integer difference_type
Type of a difference between iterator elements in the array.
const ItemInternalPtr & reference
Type indexing the array.
Int32ConstArrayView localIds() const
Array of local entity IDs.
ItemInternalArrayView items() const
Array of entities.
Integer size() const
Number of elements in the vector.
-- 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.