Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
BinaryExpressionImpl.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/* BinaryExpressionImpl.cc (C) 2000-2007 */
9/* */
10/* Implementation d'une expression binaire. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/expr/BinaryExpressionImpl.h"
17#include "arcane/expr/OperatorMng.h"
18#include "arcane/expr/BadOperationException.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23ARCANE_BEGIN_NAMESPACE
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28BinaryExpressionImpl::
29BinaryExpressionImpl(IExpressionImpl* first,IExpressionImpl* second,
30 eOperationType operation)
31: ExpressionImpl()
32, m_first(first)
33, m_second(second)
34, m_operation(operation)
35{
36}
37
38/*---------------------------------------------------------------------------*/
39/*---------------------------------------------------------------------------*/
40
41String BinaryExpressionImpl::
42operationName(eOperationType type)
43{
44 switch(type)
45 {
46 case Add: return "Add";
47 case Substract: return "Substract";
48 case Multiply: return "Multiply";
49 case Divide: return "Divide";
50 case Minimum: return "Minimum";
51 case Maximum: return "Maximum";
52 case Pow: return "Pow";
53 case LessThan: return "LessThan";
54 case GreaterThan: return "GreaterThan";
55 case LessOrEqualThan: return "LessOrEqualThan";
56 case GreaterOrEqualThan: return "GreaterOrEqualThan";
57 default: return "Unknown";
58 }
59}
60
61/*---------------------------------------------------------------------------*/
62/*---------------------------------------------------------------------------*/
63
64void BinaryExpressionImpl::
65apply(ExpressionResult* result)
66{
67 /*
68 cerr << ">> BEGIN BINARY EXPRESSION "
69 << operationName() << " [" << *result << "]\n";
70 */
71
72 // calcul des expressions gauche et droite
73 ExpressionResult first_op(result->indices());
74 m_first->apply(&first_op);
75 ExpressionResult second_op(result->indices());
76 m_second->apply(&second_op);
77
78 // recherche de l'operateur en fonction du type attendu en resultat
79 VariantBase::eType type = first_op.data()->type();
80 BinaryOperator* op = m_op_mng->find(this, type, m_operation);
81 if (!op)
82 throw BadOperationException("BinaryExpressionImpl::apply",
83 operationName(),type);
84
85 op->evaluate(result, first_op.data(), second_op.data());
86
87 /*
88 cerr << "<< END BINARY EXPRESSION "
89 << operationName() << " [" << *result << "]\n";
90 */
91}
92
93/*---------------------------------------------------------------------------*/
94/*---------------------------------------------------------------------------*/
95
96ARCANE_END_NAMESPACE
97
98/*---------------------------------------------------------------------------*/
99/*---------------------------------------------------------------------------*/
100