Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ItemVector.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/* ItemVector.h (C) 2000-2024 */
9/* */
10/* Vector of entities of the same type. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ITEMVECTOR_H
13#define ARCANE_CORE_ITEMVECTOR_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
18#include "arcane/core/ItemVectorView.h"
19#include "arcane/core/IItemFamily.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
59class ARCANE_CORE_EXPORT ItemVector
60{
61 public:
62
63 using ItemType = Item;
64
65 public:
66
68 explicit ItemVector(IItemFamily* afamily);
69
71 ItemVector(IItemFamily* afamily, Int32ConstArrayView local_ids);
72
74 ItemVector(IItemFamily* afamily, Integer asize);
75
77 ItemVector();
78
79 public:
80
82 operator ItemVectorView() const { return view(); }
83
84 public:
85
91 void setFamily(IItemFamily* afamily);
92
94 void add(Int32 local_id) { m_local_ids.add(local_id); }
95
97 void add(ConstArrayView<Int32> local_ids) { m_local_ids.addRange(local_ids); }
98
100 void addItem(ItemLocalId local_id) { m_local_ids.add(local_id); }
101
103 void addItem(Item item) { m_local_ids.add(item.localId()); }
104
106 Int32 size() const { return m_local_ids.size(); }
107
109 void reserve(Integer capacity) { m_local_ids.reserve(capacity); }
110
112 void clear() { m_local_ids.clear(); }
113
115 ItemVectorView view() const { return ItemVectorView(m_shared_info, m_local_ids, 0); }
116
118 ArrayView<Int32> viewAsArray() { return m_local_ids.view(); }
119
121 ConstArrayView<Int32> viewAsArray() const { return m_local_ids.constView(); }
122
124 void removeAt(Int32 index) { m_local_ids.remove(index); }
125
132 void resize(Integer new_size) { m_local_ids.resize(new_size); }
133
135 ItemVector clone() { return ItemVector(m_family, m_local_ids.constView()); }
136
138 Item operator[](Int32 index) const { return Item(m_local_ids[index], m_shared_info); }
139
141 IItemFamily* family() const { return m_family; }
142
144 ItemEnumerator enumerator() const { return ItemEnumerator(m_shared_info, m_local_ids); }
145
146 protected:
147
148 SharedArray<Int32> m_local_ids;
149 IItemFamily* m_family = nullptr;
150 ItemSharedInfo* m_shared_info = ItemSharedInfo::nullInstance();
151
152 private:
153
154 void _init();
155};
156
157/*---------------------------------------------------------------------------*/
158/*---------------------------------------------------------------------------*/
159
165template <typename VectorItemType>
167: public ItemVector
168{
169 public:
170
171 using ItemType = VectorItemType;
172
173 public:
174
176 ItemVectorT() = default;
177
179 explicit ItemVectorT(IItemFamily* afamily)
180 : ItemVector(afamily)
181 {}
182
185 : ItemVector(afamily, local_ids)
186 {}
187
190 : ItemVector(rhs)
191 {}
192
195 : ItemVector(afamily, asize)
196 {}
197
198 public:
199
201 operator ItemVectorViewT<VectorItemType>() const { return view(); }
202
203 public:
204
206 ItemType operator[](Int32 index) const
207 {
208 return ItemType(m_local_ids[index], m_shared_info);
209 }
210
212 void addItem(ItemType item) { m_local_ids.add(item.localId()); }
213
215 void addItem(ItemLocalIdT<ItemType> local_id) { m_local_ids.add(local_id); }
216
219 {
220 return ItemVectorViewT<ItemType>(m_shared_info, m_local_ids.constView(), 0);
221 }
222
225 {
226 return ItemEnumeratorT<ItemType>(m_shared_info, m_local_ids);
227 }
228};
229
230/*---------------------------------------------------------------------------*/
231/*---------------------------------------------------------------------------*/
232
233template <typename ItemType> inline ItemVectorViewT<ItemType>::
234ItemVectorViewT(const ItemVectorT<ItemType>& rhs)
235: ItemVectorView(rhs.view())
236{
237}
238
239/*---------------------------------------------------------------------------*/
240/*---------------------------------------------------------------------------*/
241
242} // namespace Arcane
243
244/*---------------------------------------------------------------------------*/
245/*---------------------------------------------------------------------------*/
246
247#endif
Types and macros for iterating over mesh entities.
Modifiable view of an array of type T.
Constant view of an array of type T.
Interface of an entity family.
Definition IItemFamily.h:83
Enumerator over a typed list of entities of type ItemType.
Enumerator over a list of entities.
Index of an ItemType entity in a variable.
Definition ItemLocalId.h:92
Index of an Item in a variable.
Definition ItemLocalId.h:42
Internal shared structure of a mesh entity.
ItemEnumeratorT< ItemType > enumerator() const
Enumerator.
Definition ItemVector.h:224
void addItem(ItemType item)
Adds an entity to the end of the vector.
Definition ItemVector.h:212
ItemType operator[](Int32 index) const
Entity at position index of the vector.
Definition ItemVector.h:206
void addItem(ItemLocalIdT< ItemType > local_id)
Adds an entity to the end of the vector.
Definition ItemVector.h:215
ItemVectorT()=default
Empty constructor.
ItemVectorT(IItemFamily *afamily, Integer asize)
Constructor for asize elements for the family afamily.
Definition ItemVector.h:194
ItemVectorT(IItemFamily *afamily, ConstArrayView< Int32 > local_ids)
Creates a vector associated with the family afamily and containing the entities local_ids.
Definition ItemVector.h:184
ItemVectorT(IItemFamily *afamily)
Empty constructor with family.
Definition ItemVector.h:179
ItemVectorViewT< ItemType > view() const
View of the entire array.
Definition ItemVector.h:218
ItemVectorT(const ItemVector &rhs)
Copy constructor.
Definition ItemVector.h:189
View on a typed array of entities.
View on a vector of entities.
ConstArrayView< Int32 > viewAsArray() const
Constant view of the local IDs.
Definition ItemVector.h:121
void add(Int32 local_id)
Adds an entity with local ID local_id to the end of the vector.
Definition ItemVector.h:94
void removeAt(Int32 index)
Removes the entity at index index.
Definition ItemVector.h:124
void clear()
Removes all entities from the vector.
Definition ItemVector.h:112
ItemVector clone()
Clones this vector.
Definition ItemVector.h:135
IItemFamily * family() const
Family associated with the vector.
Definition ItemVector.h:141
ItemVector(IItemFamily *afamily)
Creates an empty vector associated with the family family.
Definition ItemVector.cc:38
ItemVectorView view() const
View of the vector.
Definition ItemVector.h:115
void addItem(Item item)
Adds an entity to the end of the vector.
Definition ItemVector.h:103
void resize(Integer new_size)
Sets the number of elements in the array.
Definition ItemVector.h:132
Int32 size() const
Number of elements in the vector.
Definition ItemVector.h:106
ArrayView< Int32 > viewAsArray()
View of the local IDs.
Definition ItemVector.h:118
void addItem(ItemLocalId local_id)
Adds an entity with local ID local_id to the end of the vector.
Definition ItemVector.h:100
Item operator[](Int32 index) const
Entity at position index of the vector.
Definition ItemVector.h:138
ItemEnumerator enumerator() const
Enumerator.
Definition ItemVector.h:144
void reserve(Integer capacity)
Reserves memory for capacity entities.
Definition ItemVector.h:109
void add(ConstArrayView< Int32 > local_ids)
Adds a list of entity local IDs local_ids to the end of the vector.
Definition ItemVector.h:97
Base class for a mesh element.
Definition Item.h:84
constexpr Int32 localId() const
Local identifier of the entity in the processor subdomain.
Definition Item.h:233
1D vector of data with reference semantics.
-- 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.