Arcane
v3.15.3.0
Documentation utilisateur
Chargement...
Recherche...
Aucune correspondance
BuiltInProxy.h
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
/* BuiltInProxy.h (C) 2000-2006 */
9
/* */
10
/* Proxy d'un type du langage. */
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
23
ARCANE_BEGIN_NAMESPACE
24
25
/*---------------------------------------------------------------------------*/
26
/*---------------------------------------------------------------------------*/
27
/*!
28
* \brief Proxy d'un type du langage.
29
*/
30
template
<
typename
Type>
31
class
BuiltInProxy
32
{
33
public
:
34
35
typedef
BuiltInProxy<Type>
ThatClassType
;
36
37
public
:
38
39
40
BuiltInProxy
(Type&
ref
,
const
MemoryAccessInfo
& info)
41
: m_value(
ref
), m_info(info) {}
42
BuiltInProxy
(
const
ThatClassType
& f)
43
: m_value(f.m_value), m_info(f.m_info) {}
44
const
Type& operator=(
const
ThatClassType
& f)
45
{ setValue(f.m_value);
return
m_value; }
46
const
Type& operator=(Type v)
47
{ setValue(v);
return
m_value; }
48
//operator Type&()
49
//{ return getValueMutable(); }
50
operator
Type()
const
51
{
return
getValue(); }
52
53
public
:
54
55
ThatClassType
&
operator+=
(
const
Type&
b
)
56
{
57
return
setValue(getValue()+
b
);
58
}
59
void
operator++
()
60
{
61
setValue(getValue()+1);
62
}
63
Type
operator++
(
int
)
64
{
65
Type x = getValue();
66
setValue(x+1);
67
return
x;
68
}
69
void
operator--
()
70
{
71
setValue(getValue()-1);
72
}
73
Type
operator--
(
int
)
74
{
75
Type x = getValue();
76
setValue(x-1);
77
return
x;
78
}
79
ThatClassType
&
operator-=
(
const
Type&
b
)
80
{
81
return
setValue(getValue()-
b
);
82
}
83
ThatClassType
&
operator*=
(
const
Type&
b
)
84
{
85
return
setValue(getValue()*
b
);
86
}
87
ThatClassType
&
operator/=
(
const
Type&
b
)
88
{
89
return
setValue(getValue()/
b
);
90
}
91
92
public
:
93
94
ThatClassType
& setValue(
const
Type& v)
95
{
96
m_value = v;
97
m_info.setWrite();
98
return
(*
this
);
99
}
100
Type getValue()
const
101
{
102
m_info.setRead();
103
return
m_value;
104
}
105
Type& getValueMutable()
106
{
107
m_info.setReadOrWrite();
108
return
m_value;
109
}
110
private
:
111
112
Type& m_value;
113
MemoryAccessInfo
m_info;
114
};
115
116
template
<
typename
Type>
inline
117
bool
operator==(
const
BuiltInProxy<Type>
&
a
,
const
BuiltInProxy<Type>
&
b
)
118
{
119
return
a
.getValue()==
b
.getValue();
120
}
121
template
<
typename
Type>
inline
122
bool
operator==(
const
BuiltInProxy<Type>& a,
const
Type& b)
123
{
124
return
a.getValue()==b;
125
}
126
template
<
typename
Type>
inline
127
bool
operator==(
const
Type& a,
const
BuiltInProxy<Type>& b)
128
{
129
return
a==b.getValue();
130
}
131
132
/*---------------------------------------------------------------------------*/
133
/*---------------------------------------------------------------------------*/
134
135
/*!
136
* \brief Lit le triplet \a t à partir du flot \a o.
137
* \relates Real3
138
*/
139
template
<
typename
Type>
inline
std::istream&
140
operator>>
(std::istream& i,
BuiltInProxy<Type>
&
t
)
141
{
142
Type v;
143
i >> v;
144
t
.setValue(v);
145
return
i;
146
}
147
148
/*---------------------------------------------------------------------------*/
149
/*---------------------------------------------------------------------------*/
150
151
namespace
math
152
{
153
template
<
class
_Type>
inline
bool
154
isNearlyZero(
const
BuiltInProxy<_Type>
&
a
)
155
{
156
return
TypeEqualT<_Type>::isNearlyZero
(
a
);
157
}
158
/*!
159
* \brief Teste si une valeur est exactement égale à zéro.
160
* \retval true si \a vaut zéro,
161
* \retval false sinon.
162
*/
163
template
<
class
_Type>
inline
bool
164
isZero(
const
BuiltInProxy<_Type>& a)
165
{
166
return
TypeEqualT<_Type>::isZero(a);
167
}
168
}
169
170
/*---------------------------------------------------------------------------*/
171
/*---------------------------------------------------------------------------*/
172
173
ARCANE_END_NAMESPACE
174
175
/*---------------------------------------------------------------------------*/
176
/*---------------------------------------------------------------------------*/
177
178
#endif
Arcane::BuiltInProxy
Proxy d'un type du langage.
Definition
BuiltInProxy.h:32
Arcane::MemoryAccessInfo
Definition
MemoryAccessInfo.h:50
Arcane::TypeEqualT
Definition
Numeric.h:45
Arccore::Ref
Référence à une instance.
Definition
arccore/src/base/arccore/base/Ref.h:143
arcane
utils
BuiltInProxy.h
Généré le Lundi 10 Février 2025 02:47:12 pour Arcane par
1.9.8