5 #ifndef INCLUDE_CPPGC_MEMBER_H_
6 #define INCLUDE_CPPGC_MEMBER_H_
10 #include <type_traits>
12 #include "cppgc/internal/pointer-policies.h"
13 #include "cppgc/type-traits.h"
28 void*
GetRaw()
const {
return raw_; }
29 void SetRaw(
void* value) { raw_ = value; }
32 return reinterpret_cast<
const std::atomic<
void*>*>(&raw_)->load(
33 std::memory_order_relaxed);
36 reinterpret_cast<std::atomic<
void*>*>(&raw_)->store(
37 value, std::memory_order_relaxed);
43 mutable void* raw_ =
nullptr;
47 template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
48 typename CheckingPolicy>
49 class BasicMember final :
private MemberBase,
private CheckingPolicy {
51 using PointeeType = T;
57 InitializingWriteBarrier();
58 this->CheckPointer(Get());
61 BasicMember(
const BasicMember& other) : BasicMember(other.Get()) {}
63 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
64 typename OtherCheckingPolicy,
65 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
67 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
68 OtherCheckingPolicy>& other)
69 : BasicMember(other.Get()) {}
71 template <
typename U,
typename PersistentWeaknessPolicy,
72 typename PersistentLocationPolicy,
73 typename PersistentCheckingPolicy,
74 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
77 PersistentLocationPolicy, PersistentCheckingPolicy>&
79 : BasicMember(p.Get()) {}
81 BasicMember&
operator=(
const BasicMember& other) {
82 return operator=(other.Get());
85 template <
typename U,
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
86 typename OtherCheckingPolicy,
87 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
89 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
90 OtherCheckingPolicy>& other) {
91 return operator=(other.Get());
94 template <
typename U,
typename PersistentWeaknessPolicy,
95 typename PersistentLocationPolicy,
96 typename PersistentCheckingPolicy,
97 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
100 PersistentLocationPolicy, PersistentCheckingPolicy>&
102 return operator=(other.Get());
106 AssigningWriteBarrier();
107 this->CheckPointer(Get());
119 template <
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
120 typename OtherCheckingPolicy>
121 void Swap(BasicMember<T, OtherWeaknessTag, OtherBarrierPolicy,
122 OtherCheckingPolicy>& other) {
150 T* GetRawAtomic()
const {
154 void InitializingWriteBarrier()
const {
157 void AssigningWriteBarrier()
const {
166 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
167 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
168 typename WriteBarrierPolicy2,
typename CheckingPolicy2>
170 BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1> member1,
171 BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2>
173 return member1.Get() == member2.Get();
176 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
177 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
178 typename WriteBarrierPolicy2,
typename CheckingPolicy2>
180 BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1> member1,
181 BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2>
183 return !(member1 == member2);
186 template <
typename T,
typename WriteBarrierPolicy,
typename CheckingPolicy>
188 internal::BasicMember<T, WeakMemberTag, WriteBarrierPolicy, CheckingPolicy>>
198 template <
typename T>
210 template <
typename T>
220 template <
typename T>