Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
WhereExpressionImpl.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/* WhereExpressionImpl.cc (C) 2000-2004 */
9/* */
10/* Implementation of a conditional expression. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/utils/ArcanePrecomp.h"
15
16#include "arcane/utils/Array.h"
17#include "arcane/expr/WhereExpressionImpl.h"
18#include "arcane/expr/OperatorMng.h"
19#include "arcane/expr/BadOperationException.h"
20
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24namespace Arcane
25{
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30WhereExpressionImpl::
31WhereExpressionImpl(IExpressionImpl* test, IExpressionImpl* iftrue,
32 IExpressionImpl* iffalse)
34, m_test(test)
35, m_iftrue(iftrue)
36, m_iffalse(iffalse)
37{
38}
39
40/*---------------------------------------------------------------------------*/
41/*---------------------------------------------------------------------------*/
42
43void WhereExpressionImpl::
44apply(ExpressionResult* result)
45{
46 // cerr << ">> BEGIN WHERE EXPRESSION [" << *result << "]\n";
47
48 // Evaluation of the test
49 IntegerConstArrayView indices = result->indices();
50 ExpressionResult test_op(indices);
51 m_test->apply(&test_op);
52 ArrayView<bool> test_values;
53 test_op.data()->value(test_values);
54 Integer s = test_values.size();
55 Integer nb_true = 0;
56 Integer nb_false = 0;
57 for (Integer i = 0; i < s; ++i)
58 (test_values[i] == 0.) ? ++nb_false : ++nb_true;
59 UniqueArray<Integer> true_indices(nb_true);
60 UniqueArray<Integer> false_indices(nb_false);
61 Integer true_i = 0;
62 Integer false_i = 0;
63 for (Integer i = 0; i < s; ++i)
64 (test_values[i] != 0.) ? true_indices[true_i++] = indices[i]
65 : false_indices[false_i++] = indices[i];
66
67 /*
68 cerr << "Expression where."<< endl;
69 cerr << " false indices = [ ";
70 for(Integer i=0 ; i<nb_false ; ++i)
71 cerr << false_indices[i] << " ";
72 cerr << "]."<< endl;
73 cerr << " true indices = [ ";
74 for(Integer i=0 ; i<nb_true ; ++i)
75 cerr << true_indices[i] << " ";
76 cerr << "]."<< endl;
77 */
78
79 // Evaluation of the expression based on the test result
80 ExpressionResult iftrue_op(true_indices);
81 m_iftrue->apply(&iftrue_op);
82 ExpressionResult iffalse_op(false_indices);
83 m_iffalse->apply(&iffalse_op);
84
85 // recuperation des resultat
86 VariantBase::eType type = iftrue_op.data()->type();
87 WhereOperator* op = m_op_mng->find(this, type);
88 if (!op)
89 throw BadOperationException("WhereExpressionImpl::apply", "", type);
90
91 op->evaluate(result, test_op.data(), iftrue_op.data(), iffalse_op.data());
92
93 // cerr << "<< END WHERE EXPRESSION [" << *result << "]\n";
94}
95
96/*---------------------------------------------------------------------------*/
97/*---------------------------------------------------------------------------*/
98
99} // namespace Arcane
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
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 --
Int32 Integer
Type representing an integer.
ConstArrayView< Integer > IntegerConstArrayView
C equivalent of a 1D array of integers.
Definition UtilsTypes.h:486