Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
ItemLocalIdListView.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2023 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/* ItemLocalIdListView.h (C) 2000-2023 */
9/* */
10/* Vue sur une liste de ItemLocalId. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_ITEMLOCALIDLISTVIEW_H
13#define ARCANE_CORE_ITEMLOCALIDLISTVIEW_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/ItemLocalId.h"
18#include "arcane/core/ItemLocalIdListContainerView.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace ArcaneTest
24{
25class MeshUnitTest;
26}
27
28namespace Arcane
29{
30namespace mesh
31{
32 class IndexedItemConnectivityAccessor;
33}
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37/*!
38 * \brief Classe de base des itérateurs pour ItemLocalIdViewT.
39 */
41{
42 protected:
43
44 constexpr ARCCORE_HOST_DEVICE ItemLocalIdListViewConstIterator(const Int32* local_id_ptr, Int32 local_id_offset)
45 : m_local_id_ptr(local_id_ptr)
46 , m_local_id_offset(local_id_offset)
47 {}
48
49 public:
50
52 typedef std::random_access_iterator_tag iterator_category;
53 //! Type indexant le tableau
54 typedef Int32 value_type;
55 //! Type de la taille
56 typedef Int32 size_type;
57 //! Type d'une distance entre itérateur éléments du tableau
58 typedef std::ptrdiff_t difference_type;
59
60 public:
61
62 constexpr ARCCORE_HOST_DEVICE Int32 operator*() const { return m_local_id_offset + (*m_local_id_ptr); }
63
64 constexpr ARCCORE_HOST_DEVICE ThatClass& operator++()
65 {
66 ++m_local_id_ptr;
67 return (*this);
68 }
69 constexpr ARCCORE_HOST_DEVICE ThatClass& operator--()
70 {
71 --m_local_id_ptr;
72 return (*this);
73 }
74 constexpr ARCCORE_HOST_DEVICE void operator+=(difference_type v) { m_local_id_ptr += v; }
75 constexpr ARCCORE_HOST_DEVICE void operator-=(difference_type v) { m_local_id_ptr -= v; }
76 constexpr ARCCORE_HOST_DEVICE difference_type operator-(const ThatClass& b) const
77 {
78 return this->m_local_id_ptr - b.m_local_id_ptr;
79 }
80 constexpr ARCCORE_HOST_DEVICE friend ThatClass operator-(const ThatClass& a, difference_type v)
81 {
82 const Int32* ptr = a.m_local_id_ptr - v;
83 return ThatClass(ptr, a.m_local_id_offset);
84 }
85 constexpr ARCCORE_HOST_DEVICE friend ThatClass operator+(const ThatClass& a, difference_type v)
86 {
87 const Int32* ptr = a.m_local_id_ptr + v;
88 return ThatClass(ptr, a.m_local_id_offset);
89 }
90 constexpr ARCCORE_HOST_DEVICE friend bool operator<(const ThatClass& lhs, const ThatClass& rhs)
91 {
92 return lhs.m_local_id_ptr <= rhs.m_local_id_ptr;
93 }
94 //! Compare les indices d'itération de deux instances
95 constexpr ARCCORE_HOST_DEVICE friend bool operator==(const ThatClass& lhs, const ThatClass& rhs)
96 {
97 return lhs.m_local_id_ptr == rhs.m_local_id_ptr;
98 }
99 constexpr ARCCORE_HOST_DEVICE friend bool operator!=(const ThatClass& lhs, const ThatClass& rhs)
100 {
101 return !(lhs == rhs);
102 }
103
104 protected:
105
106 const Int32* m_local_id_ptr;
107 Int32 m_local_id_offset = 0;
108};
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
112/*!
113 * \brief Itérateur pour ItemLocalIdViewT.
114 */
115template <typename ItemType>
118{
119 friend class ItemLocalIdListViewT<ItemType>;
120
121 private:
122
123 constexpr ARCCORE_HOST_DEVICE ItemLocalIdListViewConstIteratorT(const Int32* local_id_ptr, Int32 local_id_offset)
124 : ItemLocalIdListViewConstIterator(local_id_ptr, local_id_offset)
125 {}
126
127 public:
128
129 using LocalIdType = typename ItemLocalIdTraitsT<ItemType>::LocalIdType;
131 using value_type = LocalIdType;
132
133 public:
134
135 constexpr ARCCORE_HOST_DEVICE LocalIdType operator*() const
136 {
137 return LocalIdType(m_local_id_offset + (*m_local_id_ptr));
138 }
139
140 constexpr ARCCORE_HOST_DEVICE ThatClass& operator++()
141 {
142 ++m_local_id_ptr;
143 return (*this);
144 }
145 constexpr ARCCORE_HOST_DEVICE ThatClass& operator--()
146 {
147 --m_local_id_ptr;
148 return (*this);
149 }
150 constexpr ARCCORE_HOST_DEVICE difference_type operator-(const ThatClass& b) const
151 {
152 return this->m_local_id_ptr - b.m_local_id_ptr;
153 }
154 friend constexpr ARCCORE_HOST_DEVICE ThatClass operator-(const ThatClass& a, difference_type v)
155 {
156 const Int32* ptr = a.m_local_id_ptr - v;
157 return ThatClass(ptr, a.m_local_id_offset);
158 }
159 friend constexpr ARCCORE_HOST_DEVICE ThatClass operator+(const ThatClass& a, difference_type v)
160 {
161 const Int32* ptr = a.m_local_id_ptr + v;
162 return ThatClass(ptr, a.m_local_id_offset);
163 }
164};
165
166/*---------------------------------------------------------------------------*/
167/*---------------------------------------------------------------------------*/
168/*!
169 * \brief Vue sur une liste de ItemLocalId.
170 */
171class ARCANE_CORE_EXPORT ItemLocalIdListView
173{
174 template <typename ItemType> friend class ItemLocalIdListViewT;
175 friend class ItemVectorView;
176 using impl::ItemLocalIdListContainerView::m_size;
177 using impl::ItemLocalIdListContainerView::localId;
178
179 public:
180
183
184 private:
185
186 constexpr ARCCORE_HOST_DEVICE ItemLocalIdListView(const Int32* ids, Int32 s, Int32 local_id_offset)
187 : BaseClass(ids,s,local_id_offset)
188 {}
189 explicit constexpr ARCCORE_HOST_DEVICE ItemLocalIdListView(const BaseClass& view)
190 : BaseClass(view)
191 {}
192
193 public:
194
195 constexpr ARCCORE_HOST_DEVICE ItemLocalId operator[](Int32 index) const
196 {
197 return ItemLocalId(localId(index));
198 }
199 constexpr ARCCORE_HOST_DEVICE Int32 size() const { return m_size; }
200 impl::ItemLocalIdListContainerView containerView() const { return (*this); }
201
202 public:
203
204 friend ARCANE_CORE_EXPORT bool operator==(const ThatClass& lhs, const ThatClass& rhs);
205 friend inline bool operator!=(const ThatClass& lhs, const ThatClass& rhs)
206 {
207 return !operator==(lhs, rhs);
208 }
209 friend ARCANE_CORE_EXPORT std::ostream& operator<<(std::ostream& o, const ThatClass& lhs)
210 {
211 const BaseClass& v = lhs;
212 o << v;
213 return o;
214 }
215
216 private:
217
218 ConstArrayView<Int32> _idsWithoutOffset() const { return BaseClass::_idsWithoutOffset(); }
219};
220
221/*---------------------------------------------------------------------------*/
222/*---------------------------------------------------------------------------*/
223/*!
224 * \brief Vue typée sur une liste d'entités d'une connectivité.
225 */
226template <typename ItemType>
228: public ItemLocalIdListView
229{
231 friend mesh::IndexedItemConnectivityAccessor;
232 friend ArcaneTest::MeshUnitTest;
233 friend class Item;
234 friend class ItemInternalConnectivityList;
235
236 public:
237
238 using LocalIdType = typename ItemLocalIdTraitsT<ItemType>::LocalIdType;
239 using const_iterator = ItemLocalIdListViewConstIteratorT<ItemType>;
240 // TODO: Créér le type 'Sentinel' lorsqu'on sera en C++20
241 using SentinelType = const_iterator;
242
243 public:
244
245 ItemLocalIdListViewT() = default;
246
247 private:
248
249 constexpr ARCCORE_HOST_DEVICE ItemLocalIdListViewT(const Int32* ids, Int32 s, Int32 local_id_offset)
250 : ItemLocalIdListView(ids, s, local_id_offset)
251 {}
252 explicit constexpr ARCCORE_HOST_DEVICE ItemLocalIdListViewT(const impl::ItemLocalIdListContainerView& view)
253 : ItemLocalIdListView(view)
254 {}
255
256 public:
257
258 constexpr ARCCORE_HOST_DEVICE LocalIdType operator[](Int32 i) const { return LocalIdType(localId(i)); }
259
260 constexpr ARCCORE_HOST_DEVICE const_iterator begin() const
261 {
262 return const_iterator(m_local_ids, m_local_id_offset);
263 }
264 constexpr ARCCORE_HOST_DEVICE SentinelType end() const
265 {
266 return endIterator();
267 }
268 constexpr ARCCORE_HOST_DEVICE const_iterator endIterator() const
269 {
270 return const_iterator(m_local_ids + m_size, m_local_id_offset);
271 }
272};
273
274/*---------------------------------------------------------------------------*/
275/*---------------------------------------------------------------------------*/
276
277} // namespace Arcane
278
279/*---------------------------------------------------------------------------*/
280/*---------------------------------------------------------------------------*/
281
282#endif
Itérateur pour ItemLocalIdViewT.
Classe de base des itérateurs pour ItemLocalIdViewT.
Int32 value_type
Type indexant le tableau.
std::ptrdiff_t difference_type
Type d'une distance entre itérateur éléments du tableau.
constexpr __host__ __device__ friend bool operator==(const ThatClass &lhs, const ThatClass &rhs)
Compare les indices d'itération de deux instances.
Vue typée sur une liste d'entités d'une connectivité.
Vue sur une liste de ItemLocalId.
typename ItemTraitsT< ItemType >::LocalIdType LocalIdType
Type du localId()
Definition ItemTypes.h:814
Index d'un Item dans une variable.
Definition ItemLocalId.h:40
Vue sur un vecteur d'entités.
Classe de base d'un élément de maillage.
Definition Item.h:83
Vue constante d'un tableau de type T.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
std::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Opérateur de sortie sur un flot.