Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
BinaryExpressionImpl.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/* BinaryExpressionImpl.cc (C) 2000-2007 */
9/* */
10/* Implementation of a binary expression. */
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
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29BinaryExpressionImpl::
30BinaryExpressionImpl(IExpressionImpl* first, IExpressionImpl* second,
31 eOperationType operation)
33, m_first(first)
34, m_second(second)
35, m_operation(operation)
36{
37}
38
39/*---------------------------------------------------------------------------*/
40/*---------------------------------------------------------------------------*/
41
42String BinaryExpressionImpl::
43operationName(eOperationType type)
44{
45 switch (type) {
46 case Add:
47 return "Add";
48 case Substract:
49 return "Substract";
50 case Multiply:
51 return "Multiply";
52 case Divide:
53 return "Divide";
54 case Minimum:
55 return "Minimum";
56 case Maximum:
57 return "Maximum";
58 case Pow:
59 return "Pow";
60 case LessThan:
61 return "LessThan";
62 case GreaterThan:
63 return "GreaterThan";
64 case LessOrEqualThan:
65 return "LessOrEqualThan";
66 case GreaterOrEqualThan:
67 return "GreaterOrEqualThan";
68 default:
69 return "Unknown";
70 }
71}
72
73/*---------------------------------------------------------------------------*/
74/*---------------------------------------------------------------------------*/
75
76void BinaryExpressionImpl::
77apply(ExpressionResult* result)
78{
79 /*
80 cerr << ">> BEGIN BINARY EXPRESSION "
81 << operationName() << " [" << *result << "]\n";
82 */
83
84 // calculate the left and right expressions
85 ExpressionResult first_op(result->indices());
86 m_first->apply(&first_op);
87 ExpressionResult second_op(result->indices());
88 m_second->apply(&second_op);
89
90 // search for the operator based on the expected type in the result
91 VariantBase::eType type = first_op.data()->type();
92 BinaryOperator* op = m_op_mng->find(this, type, m_operation);
93 if (!op)
94 throw BadOperationException("BinaryExpressionImpl::apply",
95 operationName(), type);
96
97 op->evaluate(result, first_op.data(), second_op.data());
98
99 /*
100 cerr << "<< END BINARY EXPRESSION "
101 << operationName() << " [" << *result << "]\n";
102 */
103}
104
105/*---------------------------------------------------------------------------*/
106/*---------------------------------------------------------------------------*/
107
108} // namespace Arcane
109
110/*---------------------------------------------------------------------------*/
111/*---------------------------------------------------------------------------*/
Base class for the expression implementation.
Interface for the different implementations of an expression.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --