Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
ExpressionResult.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/* ExpressionResult.cc (C) 2000-2018 */
9/* */
10/* Contient le résultat de l´évaluation d'une expression. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/OStringStream.h"
17#include "arcane/utils/NotImplementedException.h"
18
19#include "arcane/expr/ExpressionResult.h"
20#include "arcane/expr/BadExpressionException.h"
21
22//%% ARCANE_EXPR_SUPPRESS_BEGIN
23#include "arcane/IVariableAccessor.h"
24//%% ARCANE_EXPR_SUPPRESS_END
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29ARCANE_BEGIN_NAMESPACE
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
34//%% ARCANE_EXPR_SUPPRESS_BEGIN
35ExpressionResult::
36ExpressionResult(IVariable* v)
37{
38 if (v->dimension() != 1)
39 throw BadExpressionException
40 ("ExpressionResult::ExpressionResult(IVariablePrv* v)",
41 "Only variables of dimension 1 are dealt with in the expressions.");
42
43 throw NotImplementedException(A_FUNCINFO,"building expression result after removing IVariableAccessor");
44#if 0
45 eDataType type = v->dataType();
46 switch(type)
47 {
48 case DT_Real:
49 {
50 RealArrayView values = v->accessor()->asArrayReal();
51 m_data = new ArrayVariant(values);
52 break;
53 }
54 case DT_Int32:
55 {
56 Int32ArrayView values = v->accessor()->asArrayInt32();
57 m_data = new ArrayVariant(values);
58 break;
59 }
60 case DT_Int64:
61 {
62 Int64ArrayView values = v->accessor()->asArrayInt64();
63 m_data = new ArrayVariant(values);
64 break;
65 }
66 case DT_Real2:
67 {
68 Real2ArrayView values = v->accessor()->asArrayReal2();
69 m_data = new ArrayVariant(values);
70 break;
71 }
72 case DT_Real3:
73 {
74 Real3ArrayView values = v->accessor()->asArrayReal3();
75 m_data = new ArrayVariant(values);
76 break;
77 }
78 case DT_Real2x2:
79 {
80 Real2x2ArrayView values = v->accessor()->asArrayReal2x2();
81 m_data = new ArrayVariant(values);
82 break;
83 }
84 case DT_Real3x3:
85 {
86 Real3x3ArrayView values = v->accessor()->asArrayReal3x3();
87 m_data = new ArrayVariant(values);
88 break;
89 }
90 default:
91 m_data = 0;
92 String s = String("Type de variable (") + type + ") non supporté.\n";
93 throw BadExpressionException("ExpressionResult::ExpressionResult(IVariable* v)",s);
94 return;
95 }
96
97 Integer size = v->nbElement();
98 m_own_indices.resize(size);
99 for(Integer i=0 ; i<size ; ++i)
100 m_own_indices[i]=i;
101 m_indices = m_own_indices.view();
102#endif
103
104}
105//%% ARCANE_EXPR_SUPPRESS_END
106
107/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
109
110ExpressionResult::
111ExpressionResult(ArrayVariant* data)
112: m_data(data)
113{
114 Integer size = data->size();
115 m_own_indices.resize(size);
116 for( Integer i=0 ; i<size ; ++i)
117 m_own_indices[i] = i;
118 m_indices = m_own_indices.view();
119}
120
121/*---------------------------------------------------------------------------*/
122/*---------------------------------------------------------------------------*/
123
124ExpressionResult::
125ExpressionResult(IntegerConstArrayView indices)
126: m_data(0)
127{
128 m_indices = indices;
129}
130
131/*---------------------------------------------------------------------------*/
132/*---------------------------------------------------------------------------*/
133
134ExpressionResult::
135~ExpressionResult()
136{
137 delete m_data;
138}
139
140/*---------------------------------------------------------------------------*/
141/*---------------------------------------------------------------------------*/
142
143void ExpressionResult::
144allocate(VariantBase::eType type)
145{
146 if (!m_data){
147 m_data = new ArrayVariant(type, m_indices.size());
148 }
149 else if (type != m_data->type()){
150 OStringStream s;
151 s() << "The result type of the expression ("
152 << m_data->typeName() << ") "
153 << "is not compatible with the type of the variable ("
154 << VariantBase::typeName(type) << ").\n";
155 throw BadExpressionException("ExpressionResult::allocate", s.str());
156 }
157}
158
159/*---------------------------------------------------------------------------*/
160/*---------------------------------------------------------------------------*/
161
162std::ostream&
163operator<<(std::ostream& s, const ExpressionResult& x)
164{
165 s << "ExpressionResult [";
166 if (x.m_data)
167 s << "data=" << *x.m_data << ", ";
168 s << "indices=[ ";
169 Integer size = x.m_indices.size();
170 for( Integer i=0 ; i<size ; ++i )
171 s << x.m_indices[i] << " ";
172 s << "]]";
173
174 return s;
175}
176
177/*---------------------------------------------------------------------------*/
178/*---------------------------------------------------------------------------*/
179
180ARCANE_END_NAMESPACE
181
182/*---------------------------------------------------------------------------*/
183/*---------------------------------------------------------------------------*/
std::ostream & operator<<(std::ostream &o, eExecutionPolicy exec_policy)
Affiche le nom de la politique d'exécution.
ArrayView< Real2x2 > Real2x2ArrayView
Equivalent C d'un tableau à une dimension de Real2x2.
Definition UtilsTypes.h:627
ArrayView< Real3 > Real3ArrayView
Equivalent C d'un tableau à une dimension de Real3.
Definition UtilsTypes.h:625
ArrayView< Real3x3 > Real3x3ArrayView
Equivalent C d'un tableau à une dimension de Real3x3.
Definition UtilsTypes.h:629
ArrayView< Int64 > Int64ArrayView
Equivalent C d'un tableau à une dimension d'entiers 64 bits.
Definition UtilsTypes.h:609
ArrayView< Real2 > Real2ArrayView
Equivalent C d'un tableau à une dimension de Real2.
Definition UtilsTypes.h:623
eDataType
Type d'une donnée.
Definition DataTypes.h:39
@ DT_Real2x2
Donnée de type tenseur 3x3.
Definition DataTypes.h:48
@ DT_Real3x3
Donnée de type tenseur 3x3.
Definition DataTypes.h:49
@ DT_Int32
Donnée de type entier 32 bits.
Definition DataTypes.h:43
@ DT_Real3
Donnée de type vecteur 3.
Definition DataTypes.h:47
@ DT_Int64
Donnée de type entier 64 bits.
Definition DataTypes.h:44
@ DT_Real2
Donnée de type vecteur 2.
Definition DataTypes.h:46
@ DT_Real
Donnée de type réel.
Definition DataTypes.h:41
ArrayView< Real > RealArrayView
Equivalent C d'un tableau à une dimension de réels.
Definition UtilsTypes.h:617
ArrayView< Int32 > Int32ArrayView
Equivalent C d'un tableau à une dimension d'entiers 32 bits.
Definition UtilsTypes.h:611
Int32 Integer
Type représentant un entier.