Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
ItemIndexArrayView.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/* ItemIndexArrayView.h (C) 2000-2025 */
9/* */
10/* View over an index array (localIds()) of entities. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ITEMINDEXARRAYVIEW_H
13#define ARCANE_CORE_ITEMINDEXARRAYVIEW_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/ArrayView.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29/*!
30 * \internal
31 * \brief View over an index array (localIds()) of entities.
32 *
33 * \warning The view is only valid as long as the associated array is not
34 * modified. Instances of this class are generally temporary
35 * and should not be retained.
36 *
37 * In addition to the list of entities, this class allows for
38 * additional information, such as whether the list is contiguous.
39 */
40class ARCANE_CORE_EXPORT ItemIndexArrayView
41{
42 // NOTE: This class is mapped in C# and if its structure is changed, it
43 // must update the corresponding C# version.
44 friend ItemVectorView;
45 friend ItemGroup;
46 template <int Extent> friend class ItemConnectedListView;
47 template <typename ItemType, int Extent> friend class ItemConnectedListViewT;
48 template <typename ItemType> friend class ItemVectorViewT;
49
50 public:
51
52 // NOTE: If values are added here, it must be checked whether they should be
53 // propagated in methods such as subView().
54 enum
55 {
56 F_Contiguous = 1 << 1, //!< The local IDs are contiguous.
57 F_Contigous = F_Contiguous
58 };
59
60 public:
61
62 //! Constructs an empty view
63 ItemIndexArrayView() = default;
64
65 // TODO: To be removed
66 //! Constructs a view from the local IDs \a local_ids
67 explicit ItemIndexArrayView(const Int32ConstArrayView local_ids)
68 : m_view(local_ids, 0)
69 {}
70
72 : m_view(view)
73 {
74 }
75
76 public:
77
78 //! Accesses the i-th element of the vector
79 inline Int32 operator[](Integer index) const
80 {
81 return m_view.localId(index);
82 }
83
84 //! Number of elements in the vector
85 Int32 size() const
86 {
87 return m_view.size();
88 }
89
90 //! Adds the list of the vector's localIds() to \a ids.
91 void fillLocalIds(Array<Int32>& ids) const;
92
93 //! Sub-view starting from element \a abegin and containing \a asize elements
94 inline ItemIndexArrayView subView(Integer abegin, Integer asize) const
95 {
96 // The F_Contiguous flag is propagated to the sub-view.
97 // For other flags, it will be necessary to check if they should be propagated.
98 return ItemIndexArrayView(m_view._idsWithoutOffset().subView(abegin, asize), m_view.m_local_id_offset, m_flags);
99 }
100
101 Int32 flags() const
102 {
103 return m_flags;
104 }
105
106 bool isContigous() const { return isContiguous(); }
107
108 //! True if the localIds() are contiguous
109 bool isContiguous() const
110 {
111 return m_flags & F_Contigous;
112 }
113
114 friend std::ostream& operator<<(std::ostream& o, const ItemIndexArrayView& a)
115 {
116 o << a.m_view;
117 return o;
118 }
119
120 public:
121
122 // TODO Deprecate (3.11+)
123 //! Array of local IDs of entities
125 {
126 return m_view._idsWithoutOffset();
127 }
128
129 ARCANE_DEPRECATED_REASON("Y2023: This method is internal to Arcane. Do not use it")
130 operator Int32ConstArrayView() const
131 {
132 return _localIds();
133 }
134
135 private:
136
137 ARCANE_DEPRECATED_REASON("Y2023: This method is internal to Arcane. Do not use it")
138 const Int32* unguardedBasePointer() const
139 {
140 return _data();
141 }
142
143 ARCANE_DEPRECATED_REASON("Y2023: This method is internal to Arcane. Do not use it")
144 const Int32* data() const
145 {
146 return _data();
147 }
148
149 protected:
150
151 impl::ItemLocalIdListContainerView m_view;
152 Int32 m_flags = 0;
153
154 private:
155
156 ItemIndexArrayView(SmallSpan<const Int32> local_ids, Int32 local_id_offset, Int32 aflags)
157 : m_view(local_ids, local_id_offset)
158 , m_flags(aflags)
159 {}
160
161 const Int32* _data() const
162 {
163 return m_view.m_local_ids;
164 }
165
166 Int32ConstArrayView _localIds() const
167 {
168 return m_view._idsWithoutOffset();
169 }
170 Int32 _localIdOffset() const
171 {
172 return m_view.m_local_id_offset;
173 }
174};
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179} // End namespace Arcane
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
183
184#endif
Declarations of types used in Arcane.
Base class for 1D data vectors.
bool isContiguous() const
True if the localIds() are contiguous.
ItemIndexArrayView(const Int32ConstArrayView local_ids)
Constructs a view from the local IDs local_ids.
ItemIndexArrayView 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()=default
Constructs an empty view.
Int32ConstArrayView localIds() const
Array of local IDs of entities.
Int32 operator[](Integer index) const
Accesses the i-th element of the vector.
@ F_Contiguous
The local IDs are contiguous.
-- 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::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Output operator for a stream.
std::int32_t Int32
Signed integer type of 32 bits.