Arcane  4.1.12.0
User documentation
Loading...
Searching...
No Matches
BuiltInProxy.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/* BuiltInProxy.h (C) 2000-2006 */
9/* */
10/* Proxy of a language type. */
11/*---------------------------------------------------------------------------*/
12#ifndef ARCANE_UTILS_BUILTINPROXY_H
13#define ARCANE_UTILS_BUILTINPROXY_H
14/*---------------------------------------------------------------------------*/
15/*---------------------------------------------------------------------------*/
16
17#include "arcane/utils/Numeric.h"
18#include "arcane/utils/MemoryAccessInfo.h"
19
20/*---------------------------------------------------------------------------*/
21/*---------------------------------------------------------------------------*/
22
23namespace Arcane
24{
25
26/*---------------------------------------------------------------------------*/
27/*---------------------------------------------------------------------------*/
28
29/*!
30 * \brief Proxy of a language type.
31 */
32template <typename Type>
33class BuiltInProxy
34{
35 public:
36
37 typedef BuiltInProxy<Type> ThatClassType;
38
39 public:
40
41 BuiltInProxy(Type& ref, const MemoryAccessInfo& info)
42 : m_value(ref)
43 , m_info(info)
44 {}
45
46 BuiltInProxy(const ThatClassType& f)
47 : m_value(f.m_value)
48 , m_info(f.m_info)
49 {}
50
51 const Type& operator=(const ThatClassType& f)
52 {
53 setValue(f.m_value);
54 return m_value;
55 }
56
57 const Type& operator=(Type v)
58 {
59 setValue(v);
60 return m_value;
61 }
62
63 //operator Type&()
64 //{ return getValueMutable(); }
65
66 operator Type() const
67 {
68 return getValue();
69 }
70
71 public:
72
73 ThatClassType& operator+=(const Type& b)
74 {
75 return setValue(getValue() + b);
76 }
77
78 void operator++()
79 {
80 setValue(getValue() + 1);
81 }
82
83 Type operator++(int)
84 {
85 Type x = getValue();
86 setValue(x + 1);
87 return x;
88 }
89
90 void operator--()
91 {
92 setValue(getValue() - 1);
93 }
94
95 Type operator--(int)
96 {
97 Type x = getValue();
98 setValue(x - 1);
99 return x;
100 }
101
102 ThatClassType& operator-=(const Type& b)
103 {
104 return setValue(getValue() - b);
105 }
106
107 ThatClassType& operator*=(const Type& b)
108 {
109 return setValue(getValue() * b);
110 }
111
112 ThatClassType& operator/=(const Type& b)
113 {
114 return setValue(getValue() / b);
115 }
116
117 public:
118
119 ThatClassType& setValue(const Type& v)
120 {
121 m_value = v;
122 m_info.setWrite();
123 return (*this);
124 }
125
126 Type getValue() const;
127
128 Type& getValueMutable()
129 {
130 m_info.setReadOrWrite();
131 return m_value;
132 }
133
134 private:
135
136 Type& m_value;
137 MemoryAccessInfo m_info;
138};
139template <typename Type> Type BuiltInProxy<Type>::getValue() const
140{
141 m_info.setRead();
142 return m_value;
143}
144
145template <typename Type> inline bool operator==(const BuiltInProxy<Type>& a, const BuiltInProxy<Type>& b)
146{
147 return a.getValue() == b.getValue();
148}
149template <typename Type> inline bool operator==(const BuiltInProxy<Type>& a, const Type& b)
150{
151 return a.getValue() == b;
152}
153template <typename Type> inline bool operator==(const Type& a, const BuiltInProxy<Type>& b)
154{
155 return a == b.getValue();
156}
157
158/*---------------------------------------------------------------------------*/
159/*---------------------------------------------------------------------------*/
160
161/*!
162 * \brief Reads the triplet \a t from the stream \a o.
163 * \relates Real3
164 */
165template <typename Type> inline std::istream&
166operator>>(std::istream& i, BuiltInProxy<Type>& t)
167{
168 Type v;
169 i >> v;
170 t.setValue(v);
171 return i;
172}
173
174/*---------------------------------------------------------------------------*/
175/*---------------------------------------------------------------------------*/
176
177namespace math
178{
179 template <class _Type> inline bool
180 isNearlyZero(const BuiltInProxy<_Type>& a)
181 {
183 }
184 /*!
185 * \brief Tests if a value is exactly equal to zero.
186 * \retval true if \a is zero,
187 * \retval false otherwise.
188 */
189 template <class _Type> inline bool
191 {
193 }
194} // namespace math
195
196/*---------------------------------------------------------------------------*/
197/*---------------------------------------------------------------------------*/
198
199} // namespace Arcane
200
201/*---------------------------------------------------------------------------*/
202/*---------------------------------------------------------------------------*/
203
204#endif
Proxy of a language type.
std::istream & operator>>(std::istream &i, BuiltInProxy< Type > &t)
Reads the triplet t from the stream o.
constexpr __host__ static __device__ bool isNearlyZero(const T &a)
Compares a to zero.
Definition Numeric.h:54
constexpr __host__ static __device__ bool isZero(const T &a)
Compares a to zero.
Definition Numeric.h:64
Namespace for mathematical functions.
Definition MathUtils.h:36
bool isZero(const BuiltInProxy< _Type > &a)
Tests if a value is exactly equal to zero.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --