Arcane  v3.14.10.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
ArrayVariant.cc
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/* ArrayVariant.cc (C) 2000-2006 */
9/* */
10/* Type de base polymorphe pour les tableaux mono-dim (dimension 1). */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/Array.h"
17#include "arcane/utils/String.h"
18#include "arcane/utils/Real2.h"
19#include "arcane/utils/Real3.h"
20#include "arcane/utils/Real2x2.h"
21#include "arcane/utils/Real3x3.h"
22
23#include "arcane/datatype/ArrayVariant.h"
24#include "arcane/datatype/BadVariantTypeException.h"
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29ARCANE_BEGIN_NAMESPACE
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34ArrayVariant::
35ArrayVariant(eType type,Integer asize)
36: VariantBase(1, type)
37, m_allocated_array(0)
38{
39 switch(type){
40 case TReal:
41 {
42 RealArray* v = new RealUniqueArray(asize);
43 m_allocated_array = v;
44 m_real_value = *v;
45 }
46 break;
47 case TInt64:
48 {
49 Int64Array* v = new Int64UniqueArray(asize);
50 m_allocated_array = v;
51 m_int64_value = *v;
52 }
53 break;
54 case TInt32:
55 {
56 Int32Array* v = new Int32UniqueArray(asize);
57 m_allocated_array = v;
58 m_int32_value = *v;
59 }
60 break;
61 case TBool:
62 {
63 BoolArray* v = new BoolUniqueArray(asize);
64 m_allocated_array = v;
65 m_bool_value = *v;
66 }
67 break;
68 case TString:
69 {
70 StringArray* v = new StringUniqueArray(asize);
71 m_allocated_array = v;
72 m_string_value = *v;
73 }
74 break;
75 case TReal2:
76 {
77 Real2Array* v = new Real2UniqueArray(asize);
78 m_allocated_array = v;
79 m_real2_value = *v;
80 }
81 break;
82 case TReal3:
83 {
84 Real3Array* v = new Real3UniqueArray(asize);
85 m_allocated_array = v;
86 m_real3_value = *v;
87 }
88 break;
89 case TReal2x2:
90 {
91 Real2x2Array* v = new Real2x2UniqueArray(asize);
92 m_allocated_array = v;
93 m_real2x2_value = *v;
94 }
95 break;
96 case TReal3x3:
97 {
98 Real3x3Array* v = new Real3x3UniqueArray(asize);
99 m_allocated_array = v;
100 m_real3x3_value = *v;
101 }
102 break;
103 default:
104 throw BadVariantTypeException("ArrayVariant::ArrayVariant(eType,Integer)",type);
105 }
106}
107
108/*---------------------------------------------------------------------------*/
109/*---------------------------------------------------------------------------*/
110
111ArrayVariant::
112ArrayVariant(ArrayView<Real> data)
113: VariantBase(1,TReal)
114, m_real_value(data)
115, m_allocated_array(0)
116{
117}
118
119/*---------------------------------------------------------------------------*/
120/*---------------------------------------------------------------------------*/
121
122ArrayVariant::
123ArrayVariant(ArrayView<Real2> data)
124: VariantBase(1,TReal2)
125, m_real2_value(data)
126, m_allocated_array(0)
127{
128}
129
130/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
132
133ArrayVariant::
134ArrayVariant(ArrayView<Real3> data)
135: VariantBase(1, TReal3)
136, m_real3_value(data)
137, m_allocated_array(0)
138{
139}
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
144ArrayVariant::
145ArrayVariant(ArrayView<Real2x2> data)
146: VariantBase(1,TReal2x2)
147, m_real2x2_value(data)
148, m_allocated_array(0)
149{
150}
151
152/*---------------------------------------------------------------------------*/
153/*---------------------------------------------------------------------------*/
154
155ArrayVariant::
156ArrayVariant(ArrayView<Real3x3> data)
157: VariantBase(1,TReal3x3)
158, m_real3x3_value(data)
159, m_allocated_array(0)
160{
161}
162
163/*---------------------------------------------------------------------------*/
164/*---------------------------------------------------------------------------*/
165
166ArrayVariant::
167ArrayVariant(ArrayView<Int32> data)
168: VariantBase(1,TInt32)
169, m_int32_value(data)
170, m_allocated_array(0)
171{
172}
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177ArrayVariant::
178ArrayVariant(ArrayView<Int64> data)
179: VariantBase(1,TInt64)
180, m_int64_value(data)
181, m_allocated_array(0)
182{
183}
184
185/*---------------------------------------------------------------------------*/
186/*---------------------------------------------------------------------------*/
187
188ArrayVariant::
189ArrayVariant(ArrayView<bool> data)
190: VariantBase(1,TBool)
191, m_bool_value(data)
192, m_allocated_array(0)
193{
194}
195
196/*---------------------------------------------------------------------------*/
197/*---------------------------------------------------------------------------*/
198
199ArrayVariant::
200ArrayVariant(ArrayView<String> data)
201: VariantBase(1,TString)
202, m_string_value(data)
203, m_allocated_array(0)
204{
205}
206
207/*---------------------------------------------------------------------------*/
208/*---------------------------------------------------------------------------*/
209
210ArrayVariant::
211~ArrayVariant()
212{
213 _destroy();
214}
215
216/*---------------------------------------------------------------------------*/
217/*---------------------------------------------------------------------------*/
218
219void ArrayVariant::
220_destroy()
221{
222 if (!m_allocated_array)
223 return;
224 switch(m_type){
225 case TReal: delete reinterpret_cast<RealArray*>(m_allocated_array); break;
226 case TReal2: delete reinterpret_cast<Real2Array*>(m_allocated_array); break;
227 case TReal3: delete reinterpret_cast<Real3Array*>(m_allocated_array); break;
228 case TReal2x2: delete reinterpret_cast<Real2x2Array*>(m_allocated_array); break;
229 case TReal3x3: delete reinterpret_cast<Real3x3Array*>(m_allocated_array); break;
230 case TInt64: delete reinterpret_cast<Int64Array*>(m_allocated_array); break;
231 case TInt32: delete reinterpret_cast<Int32Array*>(m_allocated_array); break;
232 case TBool: delete reinterpret_cast<BoolArray*>(m_allocated_array); break;
233 case TString: delete reinterpret_cast<StringArray*>(m_allocated_array); break;
234 default:
235 break;
236 }
237}
238
239/*---------------------------------------------------------------------------*/
240/*---------------------------------------------------------------------------*/
241
242Integer ArrayVariant::
243size() const
244{
245 switch(m_type){
246 case TReal:
247 return m_real_value.size();
248 case TReal2:
249 return m_real2_value.size();
250 case TReal3:
251 return m_real3_value.size();
252 case TReal2x2:
253 return m_real2x2_value.size();
254 case TReal3x3:
255 return m_real3x3_value.size();
256 case TBool:
257 return m_bool_value.size();
258 case TString:
259 return m_string_value.size();
260 case TInt32:
261 return m_int32_value.size();
262 case TInt64:
263 return m_int64_value.size();
264 default:
265 break;
266 }
267 return 0;
268}
269
270/*---------------------------------------------------------------------------*/
271/*---------------------------------------------------------------------------*/
272
273extern "C++" ARCANE_DATATYPE_EXPORT std::ostream&
274operator<<(std::ostream& s, const ArrayVariant& x)
275{
276 s << "ArrayVariant [t="
277 << x.typeName();
278
279 s << ", adr=";
280 Integer size = 0;
281 switch (x.type())
282 {
283 case VariantBase::TReal:
284 s << x.asReal().data();
285 s << "], v=[ ";
286 size = x.asReal().size();
287 for (Integer i=0 ; i<size ; ++i)
288 s << x.asReal()[i] << " ";
289 break;
290 case VariantBase::TReal2:
291 s << x.asReal2().data();
292 s << "], v=[ ";
293 size = x.asReal2().size();
294 for (Integer i=0 ; i<size ; ++i)
295 s << x.asReal2()[i] << " ";
296 break;
297 case VariantBase::TReal3:
298 s << x.asReal3().data();
299 s << "], v=[ ";
300 size = x.asReal3().size();
301 for (Integer i=0 ; i<size ; ++i)
302 s << x.asReal3()[i] << " ";
303 break;
304 case VariantBase::TReal2x2:
305 s << x.asReal2().data();
306 s << "], v=[ ";
307 size = x.asReal2().size();
308 for (Integer i=0 ; i<size ; ++i)
309 s << x.asReal2x2()[i] << " ";
310 break;
311 case VariantBase::TReal3x3:
312 s << x.asReal3x3().data();
313 s << "], v=[ ";
314 size = x.asReal3x3().size();
315 for (Integer i=0 ; i<size ; ++i)
316 s << x.asReal3x3()[i] << " ";
317 break;
318 case VariantBase::TInt64:
319 s << x.asInt64().data();
320 s << "], v=[ ";
321 size = x.asInt64().size();
322 for(Integer i=0 ; i<size ; ++i)
323 s << x.asInt64()[i] << " ";
324 break;
325 case VariantBase::TInt32:
326 s << x.asInteger().data();
327 s << "], v=[ ";
328 size = x.asInteger().size();
329 for (Integer i=0 ; i<size ; ++i)
330 s << x.asInteger()[i] << " ";
331 break;
332 case VariantBase::TBool:
333 s << x.asBool().data();
334 s << "], v=[ ";
335 size = x.asBool().size();
336 for (Integer i=0 ; i<size ; ++i)
337 s << x.asBool()[i] << " ";
338 break;
339 case VariantBase::TString:
340 s << x.asString().data();
341 s << "], v=[ ";
342 size = x.asString().size();
343 for (Integer i=0 ; i<size ; ++i)
344 s << x.asString()[i] << " ";
345 break;
346 default:
347 break;
348 }
349 s << "]";
350
351 return s;
352}
353
354/*---------------------------------------------------------------------------*/
355/*---------------------------------------------------------------------------*/
356
357IntegerArrayView ArrayVariant::
358asInteger()
359{
360#ifdef ARCANE_64BIT
361 return m_int64_value;
362#else
363 return m_int32_value;
364#endif
365}
366
367/*---------------------------------------------------------------------------*/
368/*---------------------------------------------------------------------------*/
369
370IntegerConstArrayView ArrayVariant::
371asInteger() const
372{
373#ifdef ARCANE_64BIT
374 return m_int64_value;
375#else
376 return m_int32_value;
377#endif
378}
379
380/*---------------------------------------------------------------------------*/
381/*---------------------------------------------------------------------------*/
382
383ARCANE_END_NAMESPACE
384
385/*---------------------------------------------------------------------------*/
386/*---------------------------------------------------------------------------*/
Array< Real2 > Real2Array
Tableau dynamique à une dimension de vecteurs de rang 2.
Definition UtilsTypes.h:339
UniqueArray< Real2x2 > Real2x2UniqueArray
Tableau dynamique à une dimension de tenseurs de rang 2.
Definition UtilsTypes.h:531
Array< Int64 > Int64Array
Tableau dynamique à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:325
UniqueArray< Real3x3 > Real3x3UniqueArray
Tableau dynamique à une dimension de tenseurs de rang 3.
Definition UtilsTypes.h:533
UniqueArray< Int64 > Int64UniqueArray
Tableau dynamique à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:513
Array< String > StringArray
Tableau dynamique à une dimension de chaînes de caractères.
Definition UtilsTypes.h:337
ArrayView< Integer > IntegerArrayView
Equivalent C d'un tableau à une dimension d'entiers.
Definition UtilsTypes.h:615
Array< bool > BoolArray
Tableau dynamique à une dimension de booléens.
Definition UtilsTypes.h:335
Array< Real3x3 > Real3x3Array
Tableau dynamique à une dimension de tenseurs de rang 3.
Definition UtilsTypes.h:345
UniqueArray< Real3 > Real3UniqueArray
Tableau dynamique à une dimension de vecteurs de rang 3.
Definition UtilsTypes.h:529
UniqueArray< bool > BoolUniqueArray
Tableau dynamique à une dimension de booléens.
Definition UtilsTypes.h:523
UniqueArray< Int32 > Int32UniqueArray
Tableau dynamique à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:515
UniqueArray< Real > RealUniqueArray
Tableau dynamique à une dimension de réels.
Definition UtilsTypes.h:521
Array< Real2x2 > Real2x2Array
Tableau dynamique à une dimension de tenseurs de rang 2.
Definition UtilsTypes.h:343
Array< Int32 > Int32Array
Tableau dynamique à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:327
Array< Real > RealArray
Tableau dynamique à une dimension de réels.
Definition UtilsTypes.h:333
UniqueArray< String > StringUniqueArray
Tableau dynamique à une dimension de chaînes de caractères.
Definition UtilsTypes.h:525
UniqueArray< Real2 > Real2UniqueArray
Tableau dynamique à une dimension de vecteurs de rang 2.
Definition UtilsTypes.h:527
std::ostream & operator<<(std::ostream &ostr, eItemKind item_kind)
Opérateur de sortie sur un flot.
ConstArrayView< Integer > IntegerConstArrayView
Equivalent C d'un tableau à une dimension d'entiers.
Definition UtilsTypes.h:644
Array< Real3 > Real3Array
Tableau dynamique à une dimension de vecteurs de rang 3.
Definition UtilsTypes.h:341
Int32 Integer
Type représentant un entier.