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"
23 template <
typename T,
typename WeaknessTag,
typename WriteBarrierPolicy,
24 typename CheckingPolicy>
25 class BasicMember :
private CheckingPolicy {
27 using PointeeType = T;
33 InitializingWriteBarrier();
34 this->CheckPointer(raw_);
37 BasicMember(
const BasicMember& other) : BasicMember(other.Get()) {}
39 template <
typename U,
typename OtherBarrierPolicy,
typename OtherWeaknessTag,
40 typename OtherCheckingPolicy,
41 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
43 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
44 OtherCheckingPolicy>& other)
45 : BasicMember(other.Get()) {}
47 template <
typename U,
typename PersistentWeaknessPolicy,
48 typename PersistentLocationPolicy,
49 typename PersistentCheckingPolicy,
50 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
52 const BasicPersistent<U, PersistentWeaknessPolicy,
53 PersistentLocationPolicy, PersistentCheckingPolicy>&
55 : BasicMember(p.Get()) {}
57 BasicMember&
operator=(
const BasicMember& other) {
58 return operator=(other.Get());
61 template <
typename U,
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
62 typename OtherCheckingPolicy,
63 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
65 const BasicMember<U, OtherWeaknessTag, OtherBarrierPolicy,
66 OtherCheckingPolicy>& other) {
67 return operator=(other.Get());
70 template <
typename U,
typename PersistentWeaknessPolicy,
71 typename PersistentLocationPolicy,
72 typename PersistentCheckingPolicy,
73 typename = std::enable_if_t<std::is_base_of<T, U>::value>>
75 const BasicPersistent<U, PersistentWeaknessPolicy,
76 PersistentLocationPolicy, PersistentCheckingPolicy>&
78 return operator=(other.Get());
82 AssigningWriteBarrier();
83 this->CheckPointer(
Get());
95 template <
typename OtherWeaknessTag,
typename OtherBarrierPolicy,
96 typename OtherCheckingPolicy>
97 void Swap(BasicMember<T, OtherWeaknessTag, OtherBarrierPolicy,
98 OtherCheckingPolicy>& other) {
114 void Clear() { SetRawAtomic(
nullptr); }
123 void SetRawAtomic(T* raw) {
124 reinterpret_cast<std::atomic<T*>*>(&raw_)->store(raw,
125 std::memory_order_relaxed);
127 T* GetRawAtomic()
const {
128 return reinterpret_cast<
const std::atomic<T*>*>(&raw_)->load(
129 std::memory_order_relaxed);
132 void InitializingWriteBarrier()
const {
133 WriteBarrierPolicy::InitializingBarrier(
134 reinterpret_cast<
const void*>(&raw_),
static_cast<
const void*>(raw_));
136 void AssigningWriteBarrier()
const {
137 WriteBarrierPolicy::AssigningBarrier(
reinterpret_cast<
const void*>(&raw_),
138 static_cast<
const void*>(raw_));
146 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
147 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
148 typename WriteBarrierPolicy2,
typename CheckingPolicy2>
150 BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1> member1,
151 BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2>
153 return member1.Get() == member2.Get();
156 template <
typename T1,
typename WeaknessTag1,
typename WriteBarrierPolicy1,
157 typename CheckingPolicy1,
typename T2,
typename WeaknessTag2,
158 typename WriteBarrierPolicy2,
typename CheckingPolicy2>
160 BasicMember<T1, WeaknessTag1, WriteBarrierPolicy1, CheckingPolicy1> member1,
161 BasicMember<T2, WeaknessTag2, WriteBarrierPolicy2, CheckingPolicy2>
163 return !(member1 == member2);
166 template <
typename T,
typename WriteBarrierPolicy,
typename CheckingPolicy>
168 internal::BasicMember<T, WeakMemberTag, WriteBarrierPolicy, CheckingPolicy>>
178 template <
typename T>
190 template <
typename T>
200 template <
typename T>