Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
OperatorMng.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/* OperatorMng.cc (C) 2000-2003 */
9/* */
10/* Stores all possible operator types on expressions. */
11/*---------------------------------------------------------------------------*/
12/*---------------------------------------------------------------------------*/
13
14#include "arcane/expr/OperatorMng.h"
15
16/*---------------------------------------------------------------------------*/
17/*---------------------------------------------------------------------------*/
18
19namespace Arcane
20{
21/*---------------------------------------------------------------------------*/
22/*---------------------------------------------------------------------------*/
23
24OperatorMng* OperatorMng::m_instance = 0;
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29#define CREATE_ALL_OP(map, name) \
30 map.insert(name##OpMap::value_type(VariantBase::TReal, new name##OperatorT<Real>())); \
31 map.insert(name##OpMap::value_type(VariantBase::TInt64, new name##OperatorT<Int64>())); \
32 map.insert(name##OpMap::value_type(VariantBase::TInt32, new name##OperatorT<Int32>())); \
33 map.insert(name##OpMap::value_type(VariantBase::TBool, new name##OperatorT<bool>())); \
34 map.insert(name##OpMap::value_type(VariantBase::TReal2, new name##OperatorT<Real2>())); \
35 map.insert(name##OpMap::value_type(VariantBase::TReal3, new name##OperatorT<Real3>())); \
36 map.insert(name##OpMap::value_type(VariantBase::TReal2x2, new name##OperatorT<Real2x2>())); \
37 map.insert(name##OpMap::value_type(VariantBase::TReal3x3, new name##OperatorT<Real3x3>()));
38
39#define CREATE_OP(map, var, maptype, varname, vartype, operator) \
40 map[var].insert(maptype ::value_type(VariantBase::varname, \
41 new operator##Operator<vartype>()));
42
43/*---------------------------------------------------------------------------*/
44/*---------------------------------------------------------------------------*/
45
46OperatorMng::
47OperatorMng()
48: m_unary_op()
49{
50 //
51 // construction of unary operators
52 //
53 UnaryExpressionImpl::eOperationType ut;
54 ut = UnaryExpressionImpl::UnarySubstract;
55 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, UnarySubstract)
56 ut = UnaryExpressionImpl::Inverse;
57 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Inverse)
58 ut = UnaryExpressionImpl::Acos;
59 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Acos)
60 ut = UnaryExpressionImpl::Asin;
61 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Asin)
62 ut = UnaryExpressionImpl::Atan;
63 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Atan)
64 ut = UnaryExpressionImpl::Ceil;
65 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Ceil)
66 ut = UnaryExpressionImpl::Cos;
67 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Cos)
68 ut = UnaryExpressionImpl::Cosh;
69 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Cosh)
70 ut = UnaryExpressionImpl::Exp;
71 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Exp)
72 ut = UnaryExpressionImpl::Fabs;
73 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Fabs)
74 ut = UnaryExpressionImpl::Floor;
75 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Floor)
76 ut = UnaryExpressionImpl::Log;
77 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Log)
78 ut = UnaryExpressionImpl::Log10;
79 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Log10)
80 ut = UnaryExpressionImpl::Sin;
81 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Sin)
82 ut = UnaryExpressionImpl::Sinh;
83 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Sinh)
84 ut = UnaryExpressionImpl::Sqrt;
85 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Sqrt)
86 ut = UnaryExpressionImpl::Tan;
87 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Tan)
88 ut = UnaryExpressionImpl::Tanh;
89 CREATE_OP(m_unary_op, ut, UnaryOpMap, TReal, Real, Tanh)
90
91 //
92 // construction of binary operators
93 //
94 BinaryExpressionImpl::eOperationType bt;
95 // add
96 bt = BinaryExpressionImpl::Add;
97 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal, Real, Add)
98 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt32, Integer, Add)
99 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt64, Integer, Add)
100 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal2, Real2, Add)
101 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal3, Real3, Add)
102 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal2x2, Real2x2, Add)
103 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal3x3, Real3x3, Add)
104 // substract
105 bt = BinaryExpressionImpl::Substract;
106 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal, Real, Substract)
107 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt32, Integer, Substract)
108 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt64, Integer, Substract)
109 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal2, Real2, Substract)
110 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal3, Real3, Substract)
111 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal2x2, Real2x2, Substract)
112 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal3x3, Real3x3, Substract)
113 // multiply
114 bt = BinaryExpressionImpl::Multiply;
115 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal, Real, Multiply)
116 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt32, Integer, Multiply)
117 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt64, Integer, Multiply)
118 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal2, Real2, Multiply)
119 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal3, Real3, Multiply)
120 //CREATE_OP(m_binary_op,bt,BinaryOpMap,TReal2x2,Real2x2,Multiply)
121 //CREATE_OP(m_binary_op,bt,BinaryOpMap,TReal3x3,Real3x3,Multiply)
122 // multiply
123 bt = BinaryExpressionImpl::Divide;
124 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal, Real, Divide)
125 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt32, Integer, Divide)
126 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt64, Integer, Divide)
127 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal2, Real2, Divide)
128 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal3, Real3, Divide)
129 //CREATE_OP(m_binary_op,bt,BinaryOpMap,TReal2x2,Real2x2,Divide)
130 //CREATE_OP(m_binary_op,bt,BinaryOpMap,TReal3x3,Real3x3,Divide)
131 // minimum (operator< defined on Real2 and Real3)
132 bt = BinaryExpressionImpl::Minimum;
133 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal, Real, Minimum)
134 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt32, Integer, Minimum)
135 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt64, Integer, Minimum)
136 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal2, Real2, Minimum)
137 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal3, Real3, Minimum)
138 // maximum (operator> defined on Real2 and Real3)
139 bt = BinaryExpressionImpl::Maximum;
140 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal, Real, Maximum)
141 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt32, Integer, Maximum)
142 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt64, Integer, Maximum)
143 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal2, Real2, Maximum)
144 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal3, Real3, Maximum)
145 // pow
146 bt = BinaryExpressionImpl::Pow;
147 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal, Real, Pow)
148 // equal than (defined on Real2 and Real3)
149 bt = BinaryExpressionImpl::Equal;
150 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal, Real, EQ)
151 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt32, Integer, EQ)
152 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt64, Integer, EQ)
153 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal2, Real2, EQ)
154 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal3, Real3, EQ)
155 // less than (defined on Real2 and Real3)
156 bt = BinaryExpressionImpl::LessThan;
157 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal, Real, LT)
158 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt32, Integer, LT)
159 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt64, Integer, LT)
160 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal2, Real2, LT)
161 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal3, Real3, LT)
162 // less or equal than
163 bt = BinaryExpressionImpl::LessOrEqualThan;
164 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal, Real, LOET)
165 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt32, Integer, LOET)
166 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt64, Integer, LOET)
167 // greater than
168 bt = BinaryExpressionImpl::GreaterThan;
169 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal, Real, GT)
170 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt32, Integer, GT)
171 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt64, Integer, GT)
172 // greater or equal than
173 bt = BinaryExpressionImpl::GreaterOrEqualThan;
174 CREATE_OP(m_binary_op, bt, BinaryOpMap, TReal, Real, GOET)
175 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt32, Integer, GOET)
176 CREATE_OP(m_binary_op, bt, BinaryOpMap, TInt64, Integer, GOET)
177 // or
178 bt = BinaryExpressionImpl::Or;
179 CREATE_OP(m_binary_op, bt, BinaryOpMap, TBool, bool, Or)
180 // and
181 bt = BinaryExpressionImpl::And;
182 CREATE_OP(m_binary_op, bt, BinaryOpMap, TBool, bool, And)
183
184 //
185 // construction of "where" operators
186 //
187 CREATE_ALL_OP(m_where_op, Where)
188 //%% ARCANE_EXPR_SUPPRESS_BEGIN
189 CREATE_ALL_OP(m_variable_op, Variable)
190 //%% ARCANE_EXPR_SUPPRESS_END
191 CREATE_ALL_OP(m_litteral_op, Litteral)
192}
193
194OperatorMng::
195~OperatorMng()
196{
197 for (int i = 0; i < UnaryExpressionImpl::NbOperationType; i++) {
198 UnaryOpMap& m = m_unary_op[i];
199 for (UnaryOpMap::iterator it = m.begin(); it != m.end(); it++)
200 delete (*it).second;
201 }
202
203 for (int i = 0; i < BinaryExpressionImpl::NbOperationType; i++) {
204 BinaryOpMap& m = m_binary_op[i];
205 for (BinaryOpMap::iterator it = m.begin(); it != m.end(); it++)
206 delete (*it).second;
207 }
208
209 for (WhereOpMap::iterator it = m_where_op.begin();
210 it != m_where_op.end();
211 it++)
212 delete (*it).second;
213
214 //%% ARCANE_EXPR_SUPPRESS_BEGIN
215 for (VariableOpMap::iterator it = m_variable_op.begin();
216 it != m_variable_op.end();
217 it++)
218 delete (*it).second;
219 //%% ARCANE_EXPR_SUPPRESS_END
220
221 for (LitteralOpMap::iterator it = m_litteral_op.begin();
222 it != m_litteral_op.end();
223 it++)
224 delete (*it).second;
225}
226
227/*---------------------------------------------------------------------------*/
228/*---------------------------------------------------------------------------*/
229
230OperatorMng* OperatorMng::
231instance()
232{
233 if (!m_instance)
234 m_instance = new OperatorMng();
235 return m_instance;
236}
237
238/*---------------------------------------------------------------------------*/
239/*---------------------------------------------------------------------------*/
240
241UnaryOperator* OperatorMng::
242find(UnaryExpressionImpl*, VariantBase::eType type,
243 UnaryExpressionImpl::eOperationType operation)
244{
245 UnaryOpMap::iterator it = m_unary_op[operation].find(type);
246 if (it == m_unary_op[operation].end())
247 return 0;
248 else
249 return (*it).second;
250}
251
252BinaryOperator* OperatorMng::
253find(BinaryExpressionImpl*, VariantBase::eType type,
254 BinaryExpressionImpl::eOperationType operation)
255{
256 BinaryOpMap::iterator it = m_binary_op[operation].find(type);
257 if (it == m_binary_op[operation].end())
258 return 0;
259 else
260 return (*it).second;
261}
262
263WhereOperator* OperatorMng::
264find(WhereExpressionImpl*, VariantBase::eType type)
265{
266 WhereOpMap::iterator it = m_where_op.find(type);
267 if (it == m_where_op.end())
268 return 0;
269 else
270 return (*it).second;
271}
272
273LitteralOperator* OperatorMng::
274find(LitteralExpressionImpl*, VariantBase::eType type)
275{
276 LitteralOpMap::iterator it = m_litteral_op.find(type);
277 if (it == m_litteral_op.end())
278 return 0;
279 else
280 return (*it).second;
281}
282
283//%% ARCANE_EXPR_SUPPRESS_BEGIN
284VariableOperator* OperatorMng::
285find(VariableExpressionImpl*, VariantBase::eType type)
286{
287 VariableOpMap::iterator it = m_variable_op.find(type);
288 if (it == m_variable_op.end())
289 return 0;
290 else
291 return (*it).second;
292}
293//%% ARCANE_EXPR_SUPPRESS_END
294
295/*---------------------------------------------------------------------------*/
296/*---------------------------------------------------------------------------*/
297
298} // namespace Arcane
299
300/*---------------------------------------------------------------------------*/
301/*---------------------------------------------------------------------------*/
Stores all possible operator types on expressions.
Definition OperatorMng.h:41
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --