Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
VariableCollection.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/* VariableCollection.h (C) 2000-2019 */
9/* */
10/* Collection de variables. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_VARIABLECOLLECTION_H
13#define ARCANE_VARIABLECOLLECTION_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Array.h"
18
19#include "arcane/VariableRef.h"
20#include "arcane/SharedReference.h"
21#include "arcane/utils/AutoRef.h"
22
23#include <algorithm>
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34class VariableCollection;
35
36/*---------------------------------------------------------------------------*/
37/*---------------------------------------------------------------------------*/
38
39class ARCANE_CORE_EXPORT VariableCollectionEnumerator
40{
41 private:
42 friend class VariableCollection;
43 public:
45 public:
46 bool operator++()
47 {
48 ++m_index;
49 return m_index<m_count;
50 }
51 IVariable* operator*()
52 {
53 return m_collection[m_index];
54 }
55 IVariable* current()
56 {
57 return this->operator*();
58 }
59 bool moveNext()
60 {
61 return this->operator++();
62 }
63 void reset()
64 {
65 m_index = -1;
66 }
67 private:
68 Integer m_index;
69 Integer m_count;
70 ConstArrayView<IVariable*> m_collection;
71};
72
73/*---------------------------------------------------------------------------*/
74/*---------------------------------------------------------------------------*/
80class ARCANE_CORE_EXPORT VariableCollection
81{
82 private:
83
84 class Impl
85 : public SharedReference
86 {
87 public:
88 const Array<IVariable*>& variables() const { return m_variables; }
89 Array<IVariable*>& variables() { return m_variables; }
90 public:
91 void deleteMe() override { delete this; }
92 private:
93 UniqueArray<IVariable*> m_variables;
94 };
95
96 private:
97
98 typedef Array<IVariable*> BaseClass;
99
100 public:
101
102 friend class VariableCollectionEnumerator;
103 typedef VariableCollectionEnumerator Enumerator;
104
105 public:
106
108 VariableCollection(const Enumerator& rhs);
109
110 public:
111
112 void add(IVariable* var)
113 {
114 _values().add(var);
115 }
116
117 void add(VariableRef& var)
118 {
119 _values().add(var.variable());
120 }
121
122 IVariable* front()
123 {
124 return _values()[0];
125 }
126
127 Integer count() const
128 {
129 return _values().size();
130 }
131
133 template<class Function> Function
135 {
136 std::for_each(_values().begin(),_values().end(),f);
137 return f;
138 }
139
140 void clear()
141 {
142 _values().clear();
143 }
144
145 bool empty() const
146 {
147 return _values().empty();
148 }
149
150 VariableCollection clone() const
151 {
152 VariableCollection new_collection;
153 new_collection._values().copy(_values());
154 return new_collection;
155 }
156
157 VariableCollectionEnumerator enumerator() const
158 {
159 return VariableCollectionEnumerator(*this);
160 }
161
162 bool contains(IVariable* v) const
163 {
164 return _values().contains(v);
165 }
166
167 bool contains(VariableRef& v) const
168 {
169 return _values().contains(v.variable());
170 }
171
173 void sortByName(bool is_ascendent);
174
175 private:
176
177 const Array<IVariable*>& _values() const { return m_p->variables(); }
178 Array<IVariable*>& _values() { return m_p->variables(); }
179
180 private:
181
182 AutoRefT<Impl> m_p;
183};
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188} // End namespace Arcane
189
190/*---------------------------------------------------------------------------*/
191/*---------------------------------------------------------------------------*/
192
193#endif
194
Interface d'une variable.
Definition IVariable.h:54
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Implémentation d'un compteur de référence utilisant std::atomic.
void deleteMe() override
Détruit l'objet référencé
Collection de variables.
Function each(Function f)
Applique le fonctor f à tous les éléments de la collection.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
Int32 Integer
Type représentant un entier.