Arcane  4.1.12.0
Developer documentation
Loading...
Searching...
No Matches
ScalarVariant.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/* ScalarVariant.h (C) 2000-2025 */
9/* */
10/* Polymorphic base type for scalars (dimension 0). */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_CORE_DATATYPE_SCALARVARIANT_H
13#define ARCANE_CORE_DATATYPE_SCALARVARIANT_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/String.h"
18#include "arcane/utils/Real2.h"
19#include "arcane/utils/Real3.h"
20#include "arcane/utils/Real2x2.h"
21#include "arcane/utils/Real3x3.h"
22
23#include "arcane/core/datatype/VariantBase.h"
24
25/*---------------------------------------------------------------------------*/
26/*---------------------------------------------------------------------------*/
27
28namespace Arcane
29{
30
31/*---------------------------------------------------------------------------*/
32/*---------------------------------------------------------------------------*/
33
38class ARCANE_DATATYPE_EXPORT ScalarVariant
39: public VariantBase
40{
41 private:
42 public:
43
44 ScalarVariant();
45 ScalarVariant(const ScalarVariant& v);
46 ScalarVariant(Real v);
47 ScalarVariant(Real2 v);
48 ScalarVariant(Real3 v);
49 ScalarVariant(Real2x2 v);
50 ScalarVariant(Real3x3 v);
51 ScalarVariant(Int32 v);
52 ScalarVariant(Int64 v);
53 ScalarVariant(bool v);
54 ScalarVariant(const String& v);
55 ~ScalarVariant() {}
56
57 ScalarVariant& operator=(const ScalarVariant& v);
58
59 bool isInteger() const { return m_type == TInt32 || m_type == TInt64; }
60
61 void setValue(Real v)
62 {
63 m_real_value = v;
64 m_type = TReal;
65 }
66 void setValue(Real2 v)
67 {
68 m_real2_value = v;
69 m_type = TReal2;
70 }
71 void setValue(Real3 v)
72 {
73 m_real3_value = v;
74 m_type = TReal3;
75 }
76 void setValue(Real2x2 v)
77 {
79 m_type = TReal2x2;
80 }
81 void setValue(Real3x3 v)
82 {
84 m_type = TReal3x3;
85 }
86 void setValue(Int32 v)
87 {
88 m_int32_value = v;
89 m_type = TInt32;
90 }
91 void setValue(Int64 v)
92 {
93 m_int64_value = v;
94 m_type = TInt64;
95 }
96 void setValue(bool v)
97 {
98 m_bool_value = v;
99 m_type = TBool;
100 }
101 void setValue(const String& v)
102 {
103 m_string_value = v;
104 m_type = TString;
105 }
106
107 void value(Real& v) const { v = m_real_value; }
108 void value(Real2& v) const { v = m_real2_value; }
109 void value(Real3& v) const { v = m_real3_value; }
110 void value(Real2x2& v) const { v = m_real2x2_value; }
111 void value(Real3x3& v) const { v = m_real3x3_value; }
112 void value(Int32& v) const { v = m_int32_value; }
113 void value(Int64& v) const { v = m_int64_value; }
114 void value(bool& v) const { v = m_bool_value; }
115 void value(String& v) const { v = m_string_value; }
116
117 Real asReal() const { return m_real_value; }
118 Real2 asReal2() const { return m_real2_value; }
119 Real3 asReal3() const { return m_real3_value; }
120 Real2x2 asReal2x2() const { return m_real2x2_value; }
121 Real3x3 asReal3x3() const { return m_real3x3_value; }
122 Integer asInteger() const;
123 Int32 asInt32() const { return m_int32_value; }
124 Int64 asInt64() const { return m_int64_value; }
125 bool asBool() const { return m_bool_value; }
126 const String& asString() const { return m_string_value; }
127
128 private:
129
139};
140
141/*---------------------------------------------------------------------------*/
142/*---------------------------------------------------------------------------*/
143
144} // End namespace Arcane
145
146/*---------------------------------------------------------------------------*/
147/*---------------------------------------------------------------------------*/
148
149#endif
Class managing a 2-dimensional real vector.
Definition Real2.h:122
Class managing a 2x2 matrix of reals.
Definition Real2x2.h:55
Class managing a 3-dimensional real vector.
Definition Real3.h:132
Class managing a 3x3 real matrix.
Definition Real3x3.h:67
Real m_real_value
Real type value.
Real3 m_real3_value
3-real vector type value
Real3x3 m_real3x3_value
3x3 real matrix type value
Int64 m_int64_value
64-bit integer type value
Int32 m_int32_value
32-bit integer type value
bool m_bool_value
Boolean type value.
Real2x2 m_real2x2_value
2x2 real matrix type value
Real2 m_real2_value
2-real vector type value
String m_string_value
Character string type value.
eType m_type
Guaranteed valid type of the value.
Definition VariantBase.h:77
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
double Real
Type representing a real number.
std::int32_t Int32
Signed integer type of 32 bits.