Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
LitteralExpressionImpl.h
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/* LitteralExpressionImpl.h (C) 2000-2025 */
9/* */
10/* Implementation of a literal expression containing a scalar. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_EXPR_LITTERALEXPRESSIONIMPL_H
13#define ARCANE_CORE_EXPR_LITTERALEXPRESSIONIMPL_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/core/datatype/ScalarVariant.h"
18
19#include "arcane/expr/ExpressionImpl.h"
20#include "arcane/expr/Expression.h"
21#include "arcane/expr/ExpressionResult.h"
22
23/*---------------------------------------------------------------------------*/
24/*---------------------------------------------------------------------------*/
25
26namespace Arcane
27{
28
29/*---------------------------------------------------------------------------*/
30/*---------------------------------------------------------------------------*/
31
33
34/*---------------------------------------------------------------------------*/
35/*---------------------------------------------------------------------------*/
36
40class LitteralExpressionImpl
41: public ExpressionImpl
42{
43 public:
44
45 explicit LitteralExpressionImpl(const ScalarVariant& value);
46
47 public:
48
49 virtual void assign(IExpressionImpl*) {}
50 virtual void assign(IExpressionImpl*, IntegerConstArrayView) {}
51 virtual void apply(ExpressionResult* result);
52 virtual Integer vectorSize() const { return 0; }
53
54 private:
55
56 ScalarVariant m_value;
57};
58
59/*---------------------------------------------------------------------------*/
60/*---------------------------------------------------------------------------*/
61
66{
67 public:
68
69 virtual ~LitteralOperator() {}
70
71 public:
72
73 virtual void evaluate(ExpressionResult* res, ScalarVariant& a) = 0;
74};
75
76/*---------------------------------------------------------------------------*/
77/*---------------------------------------------------------------------------*/
78
79template <typename T>
81: public LitteralOperator
82{
83 public:
84
85 void evaluate(ExpressionResult* res, ScalarVariant& a) override
86 {
87 // Allocate the result based on the variant type
88 res->allocate(a.type());
89
90 // Retrieve the operand values
91 ArrayView<T> res_val;
92 res->data()->value(res_val);
93 T a_val;
94 a.value(a_val);
95
96 Integer size = res->data()->size();
97 for (Integer i = 0; i < size; ++i)
98 res_val[i] = a_val;
99 }
100};
101
102/*---------------------------------------------------------------------------*/
103/*---------------------------------------------------------------------------*/
104
105} // End namespace Arcane
106
107/*---------------------------------------------------------------------------*/
108/*---------------------------------------------------------------------------*/
109
110#endif
Modifiable view of an array of type T.
constexpr const_pointer data() const noexcept
Pointer to the start of the view.
Polymorphic base type of an expression.
Interface for the different implementations of an expression.
virtual Integer vectorSize() const
Number of elements in the vector.
Generic cast operator for literals.
Polymorphic base type for scalars (dimension 0).
-- 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