Arcane  v3.14.10.0
Documentation développeur
Chargement...
Recherche...
Aucune correspondance
WhereExpressionImpl.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/* WhereExpressionImpl.cc (C) 2000-2004 */
9/* */
10/* Implémentation d'une expression conditionnelle. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14
15#include "arcane/utils/ArcanePrecomp.h"
16
17#include "arcane/utils/Array.h"
18#include "arcane/expr/WhereExpressionImpl.h"
19#include "arcane/expr/OperatorMng.h"
20#include "arcane/expr/BadOperationException.h"
21
22/*---------------------------------------------------------------------------*/
23/*---------------------------------------------------------------------------*/
24
25ARCANE_BEGIN_NAMESPACE
26
27/*---------------------------------------------------------------------------*/
28/*---------------------------------------------------------------------------*/
29
30WhereExpressionImpl::
31WhereExpressionImpl(IExpressionImpl* test,IExpressionImpl* iftrue,
32 IExpressionImpl* iffalse)
33: ExpressionImpl()
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 du 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 de l'expression en fonction du resultat du test
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
99ARCANE_END_NAMESPACE
100
101/*---------------------------------------------------------------------------*/
102/*---------------------------------------------------------------------------*/
ConstArrayView< Integer > IntegerConstArrayView
Equivalent C d'un tableau à une dimension d'entiers.
Definition UtilsTypes.h:644
Int32 Integer
Type représentant un entier.