12#ifndef ARCANE_EXPR_BINARYEXPRESSIONIMPL_H
13#define ARCANE_EXPR_BINARYEXPRESSIONIMPL_H
17#include "arcane/expr/ExpressionImpl.h"
18#include "arcane/expr/Expression.h"
19#include "arcane/expr/ExpressionResult.h"
20#include "arcane/expr/BadOperandException.h"
39class BinaryExpressionImpl
40:
public ExpressionImpl
67 eOperationType operation);
75 String operationName()
const {
return operationName(m_operation); }
76 static String operationName(eOperationType type);
82 eOperationType m_operation;
118 if (a->type() != b->type())
122 if (size != a->size() || size != b->size())
126 res->allocate(a->type());
130 res->
data()->value(res_val);
137 evaluate(res_val, a_val, b_val);
144#define DEFAULT_BINARY_OP(classname, expression) \
146 class classname : public DefaultBinaryOperator<T> \
150 virtual void evaluate(ExpressionResult* res, \
154 DefaultBinaryOperator<T>::evaluate(res, a, b); \
156 virtual void evaluate(ArrayView<T> res, \
160 Integer size = res.size(); \
161 for (Integer i = 0; i < size; ++i) \
169DEFAULT_BINARY_OP(AddOperator, res[i] = a[i] + b[i])
170DEFAULT_BINARY_OP(SubstractOperator, res[i] = a[i] - b[i])
171DEFAULT_BINARY_OP(MultiplyOperator, res[i] = a[i] * b[i])
172DEFAULT_BINARY_OP(DivideOperator, res[i] = a[i] / b[i])
173DEFAULT_BINARY_OP(MinimumOperator, (a[i] < b[i]) ? res[i] = a[i] : res[i] = b[i])
174DEFAULT_BINARY_OP(MaximumOperator, (a[i] < b[i]) ? res[i] = b[i] : res[i] = a[i])
175DEFAULT_BINARY_OP(PowOperator, res[i] = pow(a[i], b[i]))
181class BoolBinaryOperator
195 if (a->type() != b->type())
199 if (size != a->size() || size != b->size())
203 res->allocate(ArrayVariant::TBool);
207 res->
data()->value(res_val);
214 evaluate(res_val, a_val, b_val);
221#define BOOL_BINARY_OP(classname, expression) \
223 class classname : public BoolBinaryOperator<T> \
227 virtual void evaluate(ExpressionResult* res, \
231 BoolBinaryOperator<T>::evaluate(res, a, b); \
233 virtual void evaluate(ArrayView<bool> res, \
237 Integer size = res.size(); \
238 for (Integer i = 0; i < size; ++i) \
246BOOL_BINARY_OP(EQOperator, res[i] = (a[i] == b[i]))
247BOOL_BINARY_OP(LTOperator, res[i] = (a[i] < b[i]))
248BOOL_BINARY_OP(GTOperator, res[i] = (a[i] > b[i]))
249BOOL_BINARY_OP(LOETOperator, res[i] = (a[i] <= b[i]))
250BOOL_BINARY_OP(GOETOperator, res[i] = (a[i] >= b[i]))
251BOOL_BINARY_OP(AndOperator, res[i] = (a[i] && b[i]))
252BOOL_BINARY_OP(OrOperator, res[i] = (a[i] || b[i]))
Polymorphic base type for arrays (dimension 1).
Modifiable view of an array of type T.
constexpr const_pointer data() const noexcept
Pointer to the start of the view.
Exception for operands in expression operations.
virtual Integer vectorSize() const
Number of elements in the vector.
Generic binary operator for expressions.
Polymorphic base type of an expression.
Interface for the different implementations of an expression.
Unicode character string.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
Int32 Integer
Type representing an integer.
ConstArrayView< Integer > IntegerConstArrayView
C equivalent of a 1D array of integers.