Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
Collection.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/* Collection.h (C) 2000-2022 */
9/* */
10/* Classe de base d'une collection. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_COLLECTION_H
13#define ARCANE_UTILS_COLLECTION_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/AutoRef.h"
18#include "arcane/utils/CollectionImpl.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
32class ARCANE_UTILS_EXPORT CollectionBase
33{
34 private:
35
37
38 public:
39
41 : m_ref(rhs.m_ref)
42 {}
44
45 public:
46
52 CollectionBase() = default;
53 CollectionBase& operator=(const CollectionBase& rhs)
54 {
55 m_ref = rhs.m_ref;
56 return *this;
57 }
58
59 protected:
60
61 explicit CollectionBase(Impl* vb)
62 : m_ref(vb)
63 {}
64
65 public:
66
68 void clear() { m_ref->clear(); }
70 Integer count() const { return m_ref->count(); }
72 bool empty() const { return count() == 0; }
74 CollectionChangeEventHandler& change() { return m_ref->change(); }
75
76 protected:
77
78 Impl* _ref() { return m_ref.get(); }
79 const Impl* _ref() const { return m_ref.get(); }
80
81 Impl* _noNullRef()
82 {
83#ifdef ARCANE_CHECK
84 Arcane::arcaneCheckNull(m_ref.get());
85#endif
86 return m_ref.get();
87 }
88 const Impl* _noNullRef() const
89 {
90#ifdef ARCANE_CHECK
91 Arcane::arcaneCheckNull(m_ref.get());
92#endif
93 return m_ref.get();
94 }
95
96 void _setRef(Impl* new_impl)
97 {
98 m_ref = new_impl;
99 }
100
101 private:
102
103 AutoRefT<Impl> m_ref;
104};
105
106/*---------------------------------------------------------------------------*/
107/*---------------------------------------------------------------------------*/
112template <typename T>
114: public CollectionBase
115{
116 private:
117
118 typedef CollectionImplT<T> Impl;
119
120 public:
121
122 typedef const T& ObjectRef;
123 typedef T& Ref;
124 typedef T* Iterator;
125
126 public:
127
130
131 public:
132
139 Collection() = default;
140
141 protected:
142
143 explicit Collection(Impl* vb)
145 {}
146
147 public:
148
149 Enumerator enumerator() const
150 {
151 return Enumerator(_cast().enumerator());
152 }
153
154 Iterator begin() { return _cast().begin(); }
155 Iterator end() { return _cast().end(); }
156 Ref front() { return *begin(); }
157
158 public:
159
160 bool remove(ObjectRef value) { return _cast().remove(value); }
161 void removeAt(Integer index) { return _cast().removeAt(index); }
162 void add(ObjectRef value) { _cast().add(value); }
163 bool contains(ObjectRef value) const { return _cast().contains(value); }
164
165 public:
166
168 template <class Function> Function
169 each(Function f) { return _cast().each(f); }
170
171 private:
172
173 Impl& _cast() { return *static_cast<Impl*>(_noNullRef()); }
174 const Impl& _cast() const { return *static_cast<const Impl*>(_ref()); }
175};
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
180} // namespace Arcane
181
182/*---------------------------------------------------------------------------*/
183/*---------------------------------------------------------------------------*/
184
185#endif
Classe de base d'une collection.
Definition Collection.h:33
void clear()
Supprime tous les éléments de la collection.
Definition Collection.h:68
Integer count() const
Nombre d'éléments de la collection.
Definition Collection.h:70
bool empty() const
True si la collection est vide.
Definition Collection.h:72
CollectionChangeEventHandler & change()
Evènement invoqués lorsque la collection change.
Definition Collection.h:74
CollectionBase()=default
Créé une collection nulle.
classe de base d'implémentation d'une collection.
Classe de base d'une collection fortement typée.
Definition Collection.h:115
EnumeratorT< T > Enumerator
Type d'un itérateur sur toute la collection.
Definition Collection.h:129
Function each(Function f)
Applique le fonctor f à tous les éléments de la collection.
Definition Collection.h:169
Collection()=default
Créé une collection nulle.
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-