Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ArrayShape.cc
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/* ArrayShape.cc (C) 2000-2023 */
9/* */
10/* Représente la forme d'un tableau. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArrayShape.h"
15
16#include "arcane/utils/ArgumentException.h"
17#include "arcane/utils/FatalErrorException.h"
18#include "arcane/utils/CheckedConvert.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29ArrayShape::
30ArrayShape(Span<const Int32> v)
31{
32 _set(v.smallView());
33}
34
35/*---------------------------------------------------------------------------*/
36/*---------------------------------------------------------------------------*/
37
40{
41 if (nb_dim<0 || nb_dim>=MAX_NB_DIMENSION)
42 ARCANE_THROW(ArgumentException,"Bad value for argument 'nb_value'");
43 m_nb_dim = nb_dim;
44}
45
46/*---------------------------------------------------------------------------*/
47/*---------------------------------------------------------------------------*/
48
49void ArrayShape::
51{
52 Int32 vsize = v.size();
53 if (vsize >= MAX_NB_DIMENSION)
54 ARCANE_FATAL("Bad size '{0}' for shape. Maximum size is {1}",vsize,MAX_NB_DIMENSION);
55 m_nb_dim = CheckedConvert::toInt32(vsize);
56 for (Int32 i = 0; i < vsize; ++i)
57 m_dims[i] = v[i];
58}
59
60/*---------------------------------------------------------------------------*/
61/*---------------------------------------------------------------------------*/
62
65{
66 _set(dims.smallView());
67}
68
69/*---------------------------------------------------------------------------*/
70/*---------------------------------------------------------------------------*/
71
72bool ArrayShape::
73_isEqual(const ArrayShape& s1, const ArrayShape& s2)
74{
75 if (s1.m_nb_dim != s2.m_nb_dim)
76 return false;
77 for (Int32 i = 0; i < s1.m_nb_dim; ++i) {
78 if (s1.m_dims[i] != s2.m_dims[i])
79 return false;
80 }
81 return true;
82}
83
84/*---------------------------------------------------------------------------*/
85/*---------------------------------------------------------------------------*/
86
87void ArrayShape::
88_print(std::ostream& o) const
89{
90 o << "{ ";
91 for (Int32 i = 0; i < m_nb_dim; ++i) {
92 if (i != 0)
93 o << ", ";
94 o << m_dims[i];
95 }
96 o << " }";
97}
98
99/*---------------------------------------------------------------------------*/
100/*---------------------------------------------------------------------------*/
101
102} // End namespace Arcane
103
104/*---------------------------------------------------------------------------*/
105/*---------------------------------------------------------------------------*/
#define ARCANE_THROW(exception_class,...)
Macro pour envoyer une exception avec formattage.
#define ARCANE_FATAL(...)
Macro envoyant une exception FatalErrorException.
Forme d'un tableau.
Definition ArrayShape.h:40
void setNbDimension(Int32 nb_value)
Positionne le rang de la forme.
Definition ArrayShape.cc:39
void setDimensions(Span< const Int32 > dims)
Positionne le nombre et la valeur des dimensions.
Definition ArrayShape.cc:64
Lecteur des fichiers de maillage via la bibliothèque LIMA.
Definition Lima.cc:120
Exception lorsqu'un argument est invalide.
Int32 toInt32(Int64 v)
Converti un Int64 en un Int32.
-*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-