Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
List.h
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2022 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/* List.h (C) 2000-2022 */
9/* */
10/* Classe collection tableau. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_LIST_H
13#define ARCANE_UTILS_LIST_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/ListImpl.h"
18#include "arcane/utils/Enumerator.h"
19#include "arcane/utils/Ptr.h"
20#include "arcane/utils/Collection.h"
21#include "arcane/utils/Iostream.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
34class ARCANE_UTILS_EXPORT ListEnumeratorBase
35{
36 public:
37
38 typedef void* VoidPtr;
39
40 public:
41
42 ListEnumeratorBase(VoidPtr begin, VoidPtr end, Integer elem_size)
43 : m_begin(begin)
44 , m_end(end)
45 , m_current(begin)
46 , m_elem_size(elem_size)
47 {}
48
49 public:
50
51 void reset() { m_current = m_begin; }
52 bool moveNext()
53 {
54 m_current = (char*)m_current + m_elem_size;
55 return m_current < m_end;
56 }
57 VoidPtr current() { return m_current; }
58
59 bool operator++() { return moveNext(); }
60 VoidPtr operator*() { return current(); }
61
62 protected:
63
64 VoidPtr m_begin;
65 VoidPtr m_end;
66 VoidPtr m_current;
67 Integer m_elem_size;
68};
69
70/*---------------------------------------------------------------------------*/
71/*---------------------------------------------------------------------------*/
75class ARCANE_UTILS_EXPORT ListConstEnumeratorBase
76{
77 public:
78
79 typedef const void* VoidPtr;
80
81 public:
82
84 : m_begin(begin)
85 , m_end(end)
86 , m_current(begin)
87 , m_elem_size(elem_size)
88 {}
89
90 public:
91
92 void reset() { m_current = m_begin; }
93 bool moveNext()
94 {
95 m_current = (const char*)m_current + m_elem_size;
96 return m_current < m_end;
97 }
98 VoidPtr current() { return m_current; }
99
100 bool operator++() { return moveNext(); }
101 VoidPtr operator*() { return current(); }
102
103 protected:
104
105 VoidPtr m_begin;
106 VoidPtr m_end;
107 VoidPtr m_current;
108 Integer m_elem_size;
109};
110
111/*---------------------------------------------------------------------------*/
112/*---------------------------------------------------------------------------*/
113
114template <typename T> class List;
115
116/*---------------------------------------------------------------------------*/
117/*---------------------------------------------------------------------------*/
121template <typename T>
123: public ListEnumeratorBase
124{
125 public:
126
127 typedef T* Ptr;
128 typedef T& Ref;
129
130 public:
131
132 ListEnumeratorT(Ptr begin, Ptr end)
133 : ListEnumeratorBase(begin - 1, end, sizeof(T))
134 {}
136
137 public:
138
139 inline bool moveNext()
140 {
141 Ptr v = reinterpret_cast<Ptr>(m_current);
142 ++v;
143 m_current = v;
144 return m_current < m_end;
145 }
146 inline Ptr current()
147 {
148 return reinterpret_cast<Ptr>(m_current);
149 }
150 inline bool operator++()
151 {
152 return moveNext();
153 }
154 inline Ref operator*()
155 {
156 return *current();
157 }
158 inline Ptr operator->()
159 {
160 return current();
161 }
162
163 private:
164};
165
166/*---------------------------------------------------------------------------*/
167/*---------------------------------------------------------------------------*/
168
169template <typename T>
172{
173 public:
174
175 typedef const T* Ptr;
176 typedef const T& Ref;
177
178 public:
179
180 ListConstEnumeratorT(Ptr begin, Ptr end)
181 : ListConstEnumeratorBase(begin - 1, end, sizeof(T))
182 {}
184
185 public:
186
187 inline bool moveNext()
188 {
189 Ptr v = reinterpret_cast<Ptr>(m_current);
190 ++v;
191 m_current = v;
192 return m_current < m_end;
193 }
194 inline Ptr current()
195 {
196 return reinterpret_cast<Ptr>(m_current);
197 }
198 inline bool operator++()
199 {
200 return moveNext();
201 }
202 inline Ref operator*()
203 {
204 return *current();
205 }
206 inline Ptr operator->()
207 {
208 return current();
209 }
210
211 private:
212};
213
214/*---------------------------------------------------------------------------*/
215/*---------------------------------------------------------------------------*/
219template <typename T>
220class List
221: public Collection<T>
222{
223 public:
224
225 typedef Collection<T> BaseClass;
226
227 private:
228
229 typedef ListImplT<T> Impl;
230
231 public:
232
233 typedef Impl Vec;
234 typedef typename Vec::value_type value_type;
235 typedef typename Vec::iterator iterator;
236 typedef typename Vec::const_iterator const_iterator;
237 typedef typename Vec::pointer pointer;
238 typedef typename Vec::const_pointer const_pointer;
239 typedef typename Vec::reference reference;
240 typedef typename Vec::const_reference const_reference;
241
244
246
247 public:
248
249 List()
250 : BaseClass(new Impl())
251 {}
253 : BaseClass(new Impl(from))
254 {}
255 List(const ArrayView<T>& from)
256 : BaseClass(new Impl(from))
257 {}
258 explicit List(const EnumeratorT<T>& from)
259 : BaseClass(new Impl(from))
260 {}
261
262 public:
263
264 void resize(Integer new_size)
265 {
266 _cast().resize(new_size);
267 }
268
269 T& operator[](Integer i)
270 {
271 return _cast()[i];
272 }
273
274 const T& operator[](Integer i) const
275 {
276 return _cast()[i];
277 }
278
280 void clone(const Collection<T>& base)
281 {
282 //Impl* n = new Impl(base);
283 //BaseClass::_setRef(n);
284 _cast().assign(base);
285 }
286
289 {
290 return List<T>(new Impl(*this));
291 }
292
293 public:
294
295 const_iterator begin() const { return _cast().begin(); }
296 const_iterator end() const { return _cast().end(); }
297
298 T* begin2() const { return _cast().begin2(); }
299 T* end2() const { return _cast().end2(); }
300
302 template <typename Function> Function
304 {
305 return _cast().each(f);
306 }
307
308 template <typename Function> iterator
309 find_if(Function f)
310 {
311 iterator _end = end2();
312 iterator i = std::find_if(begin2(), _end, f);
313 if (i != _end)
314 return i;
315 return _end;
316 }
317
318 template <typename Function> const_iterator
319 find_if(Function f) const
320 {
321 const_iterator _end = end();
322 const_iterator i = std::find_if(begin(), _end, f);
323 if (i != _end)
324 return i;
325 return _end;
326 }
327
328 protected:
329
330 List(Impl* from)
331 : BaseClass(from)
332 {}
333
334 private:
335
336 Impl& _cast() { return *static_cast<Impl*>(this->_noNullRef()); }
337 const Impl& _cast() const { return *static_cast<const Impl*>(this->_noNullRef()); }
338};
339
340/*---------------------------------------------------------------------------*/
341/*---------------------------------------------------------------------------*/
342
343template <typename T> inline ListEnumeratorT<T>::
344ListEnumeratorT(const List<T>& collection)
345: ListEnumeratorBase(collection.begin2() - 1, collection.end2(), sizeof(T))
346{
347}
348
349/*---------------------------------------------------------------------------*/
350/*---------------------------------------------------------------------------*/
351
352template <typename T> inline ListConstEnumeratorT<T>::
353ListConstEnumeratorT(const List<T>& collection)
354: ListConstEnumeratorBase(collection.begin2() - 1, collection.end2(), sizeof(T))
355{
356}
357
358/*---------------------------------------------------------------------------*/
359/*---------------------------------------------------------------------------*/
360
361} // namespace Arcane
362
363/*---------------------------------------------------------------------------*/
364/*---------------------------------------------------------------------------*/
365
366#endif
Classe de base d'une collection fortement typée.
Definition Collection.h:115
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Enumérateur générique constant pour un tableau.
Definition List.h:76
Enumérateur générique pour un tableau.
Definition List.h:35
Enumérateur typé pour un tableau.
Definition List.h:124
Implémentation d'une collection d'éléments sous forme de vecteur.
Definition List.h:222
void clone(const Collection< T > &base)
Clone la collection base.
Definition List.h:280
Function each(Function f)
Applique le fonctor f à tous les éléments du tableau.
Definition List.h:303
ListEnumeratorT< T > Enumerator
Type d'un itérateur constant sur tout le tableau.
Definition List.h:243
List< T > clone() const
Clone la collection.
Definition List.h:288
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-