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/sentinel-pointer.h"
14 #include "cppgc/type-traits.h"
31 const void*
GetRaw()
const {
return raw_; }
32 void SetRaw(
void* value) { raw_ = value; }
35 return reinterpret_cast<
const std::atomic<
const void*>*>(&raw_)->load(
36 std::memory_order_relaxed);
39 reinterpret_cast<std::atomic<
const void*>*>(&raw_)->store(
40 value, std::memory_order_relaxed);
46 mutable const void* raw_ =
nullptr;
50 template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
51 typename CheckingPolicy>
52 class BasicMember final :
private MemberBase,
private CheckingPolicy {
54 using PointeeType = T;
60 InitializingWriteBarrier();
61 this->CheckPointer(Get());
65 BasicMember(
const BasicMember& other) : BasicMember(other.Get()) {}
67 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
68 typename OtherCheckingPolicy,
69 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
71 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
72 OtherCheckingPolicy>& other)
73 : BasicMember(other.Get()) {}
75 BasicMember(BasicMember&& other)
noexcept : BasicMember(other.Get()) {
79 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
80 typename OtherCheckingPolicy,
81 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
83 BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
84 OtherCheckingPolicy>&& other)
noexcept
85 : BasicMember(other.Get()) {
89 template <
typename U,
typename PersistentWeaknessPolicy,
90 typename PersistentLocationPolicy,
91 typename PersistentCheckingPolicy,
92 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
95 PersistentLocationPolicy, PersistentCheckingPolicy>&
97 : BasicMember(p.Get()) {}
101 return operator=(other.Get());
104 template <
typename U,
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
105 typename OtherCheckingPolicy,
106 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
108 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
109 OtherCheckingPolicy>& other) {
110 return operator=(other.Get());
113 BasicMember&
operator=(BasicMember&& other)
noexcept {
114 operator=(other.Get());
119 template <
typename U,
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
120 typename OtherCheckingPolicy,
121 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
122 BasicMember&
operator=(BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
123 OtherCheckingPolicy>&& other)
noexcept {
124 operator=(other.Get());
129 template <
typename U,
typename PersistentWeaknessPolicy,
130 typename PersistentLocationPolicy,
131 typename PersistentCheckingPolicy,
132 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
135 PersistentLocationPolicy, PersistentCheckingPolicy>&
137 return operator=(other.Get());
141 AssigningWriteBarrier();
142 this->CheckPointer(Get());
154 template <
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
155 typename OtherCheckingPolicy>
156 void Swap(BasicMember<T, OtherWeaknessTag, OtherBarrierPolicy,
157 OtherCheckingPolicy>& other) {
193 const T* GetRawAtomic()
const {
197 void InitializingWriteBarrier()
const {
200 void AssigningWriteBarrier()
const {
207 template <
typename U>
211 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
212 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
213 typename WriteBarrierPolicy2,
typename CheckingPolicy2>
215 BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1> member1,
216 BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2>
218 return member1.Get() == member2.Get();
221 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
222 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
223 typename WriteBarrierPolicy2,
typename CheckingPolicy2>
225 BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1> member1,
226 BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2>
228 return !(member1 == member2);
231 template <
typename T,
typename WriteBarrierPolicy,
typename CheckingPolicy>
233 internal::BasicMember<T, WeakMemberTag, WriteBarrierPolicy, CheckingPolicy>>
243 template <
typename T>
255 template <
typename T>
265 template <
typename T>
266 using UntracedMember =
internal::BasicMember<T,
internal::UntracedMemberTag,