Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ExpressionResult.cc
1// -*- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature -*-
2//-----------------------------------------------------------------------------
3// Copyright 2000-2026 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/* Contains the result of an expression evaluation. */
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
29namespace Arcane
30{
31
32/*---------------------------------------------------------------------------*/
33/*---------------------------------------------------------------------------*/
34
35//%% ARCANE_EXPR_SUPPRESS_BEGIN
36ExpressionResult::
37ExpressionResult(IVariable* v)
38{
39 if (v->dimension() != 1)
40 throw BadExpressionException("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//%% ARCANE_EXPR_SUPPRESS_END
105
106/*---------------------------------------------------------------------------*/
107/*---------------------------------------------------------------------------*/
108
109ExpressionResult::
110ExpressionResult(ArrayVariant* data)
111: m_data(data)
112{
113 Integer size = data->size();
114 m_own_indices.resize(size);
115 for (Integer i = 0; i < size; ++i)
116 m_own_indices[i] = i;
117 m_indices = m_own_indices.view();
118}
119
120/*---------------------------------------------------------------------------*/
121/*---------------------------------------------------------------------------*/
122
123ExpressionResult::
124ExpressionResult(IntegerConstArrayView indices)
125: m_data(0)
126{
127 m_indices = indices;
128}
129
130/*---------------------------------------------------------------------------*/
131/*---------------------------------------------------------------------------*/
132
133ExpressionResult::
134~ExpressionResult()
135{
136 delete m_data;
137}
138
139/*---------------------------------------------------------------------------*/
140/*---------------------------------------------------------------------------*/
141
142void ExpressionResult::
143allocate(VariantBase::eType type)
144{
145 if (!m_data) {
146 m_data = new ArrayVariant(type, m_indices.size());
147 }
148 else if (type != m_data->type()) {
149 OStringStream s;
150 s() << "The result type of the expression ("
151 << m_data->typeName() << ") "
152 << "is not compatible with the type of the variable ("
153 << VariantBase::typeName(type) << ").\n";
154 throw BadExpressionException("ExpressionResult::allocate", s.str());
155 }
156}
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
161std::ostream&
162operator<<(std::ostream& s, const ExpressionResult& x)
163{
164 s << "ExpressionResult [";
165 if (x.m_data)
166 s << "data=" << *x.m_data << ", ";
167 s << "indices=[ ";
168 Integer size = x.m_indices.size();
169 for (Integer i = 0; i < size; ++i)
170 s << x.m_indices[i] << " ";
171 s << "]]";
172
173 return s;
174}
175
176/*---------------------------------------------------------------------------*/
177/*---------------------------------------------------------------------------*/
178
179} // namespace Arcane
180
181/*---------------------------------------------------------------------------*/
182/*---------------------------------------------------------------------------*/
Polymorphic base type for arrays (dimension 1).
UniqueArray< Integer > m_own_indices
Array of indices allocated by this instance.
Interface of a variable.
Definition IVariable.h:40
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
ArrayView< Int64 > Int64ArrayView
C equivalent of a 1D array of 64-bit integers.
Definition UtilsTypes.h:451
ArrayView< Real2x2 > Real2x2ArrayView
C equivalent of a 1D array of Real2x2.
Definition UtilsTypes.h:469
ArrayView< Real3 > Real3ArrayView
C equivalent of a 1D array of Real3.
Definition UtilsTypes.h:467
Int32 Integer
Type representing an integer.
ArrayView< Real3x3 > Real3x3ArrayView
C equivalent of a 1D array of Real3x3.
Definition UtilsTypes.h:471
ArrayView< Int32 > Int32ArrayView
C equivalent of a 1D array of 32-bit integers.
Definition UtilsTypes.h:453
ArrayView< Real2 > Real2ArrayView
C equivalent of a 1D array of Real2.
Definition UtilsTypes.h:465
eDataType
Data type.
Definition DataTypes.h:41
@ DT_Real2x2
2x2 tensor data type
Definition DataTypes.h:50
@ DT_Real3x3
3x3 tensor data type
Definition DataTypes.h:51
@ DT_Int32
32-bit integer data type
Definition DataTypes.h:45
@ DT_Real3
Vector 3 data type.
Definition DataTypes.h:49
@ DT_Int64
64-bit integer data type
Definition DataTypes.h:46
@ DT_Real2
Vector 2 data type.
Definition DataTypes.h:48
@ DT_Real
Real data type.
Definition DataTypes.h:43
ArrayView< Real > RealArrayView
C equivalent of a 1D array of reals.
Definition UtilsTypes.h:459