CommonLibVR
ExtraDataList.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "RE/B/BSAtomic.h"
4 #include "RE/B/BSExtraData.h"
5 #include "RE/B/BSPointerHandle.h"
6 #include "RE/E/ExtraDataTypes.h"
7 #include "RE/E/ExtraFlags.h"
9 #include "RE/E/ExtraWorn.h"
10 #include "RE/E/ExtraWornLeft.h"
11 #include "RE/F/FormTypes.h"
12 #include "RE/M/MemoryManager.h"
13 #include "RE/S/SoulLevels.h"
14 
15 namespace RE
16 {
17  class InventoryChanges;
18  class TESBoundObject;
19 
21  {
22  public:
24  {
25  public:
26  [[nodiscard]] bool HasType(std::uint32_t a_type) const;
27  void MarkType(std::uint32_t a_type, bool a_cleared);
28 
29  // members
30  std::uint8_t bits[0x18]; // 00
31  };
32  static_assert(sizeof(PresenceBitfield) == 0x18);
33 
34 #ifndef SKYRIM_SUPPORT_AE
35  ~BaseExtraList(); // 00
36 #else
37  virtual ~BaseExtraList(); // 00
38 #endif
39 
40  // members
41  BSExtraData* data = nullptr; // 08
42  PresenceBitfield* presence = nullptr; // 10
43  };
44 #ifndef SKYRIM_SUPPORT_AE
45  static_assert(sizeof(BaseExtraList) == 0x10);
46 #else
47  static_assert(sizeof(BaseExtraList) == 0x18);
48 #endif
49 
51  {
52  public:
53  template <class T>
55  {
56  public:
57  using difference_type = std::ptrdiff_t;
58  using value_type = T;
59  using pointer = value_type*;
61  using iterator_category = std::forward_iterator_tag;
62 
63  constexpr iterator_base() noexcept :
64  _cur(nullptr)
65  {}
66 
67  constexpr iterator_base(pointer a_node) noexcept :
68  _cur(a_node)
69  {}
70 
71  constexpr iterator_base(const iterator_base& a_rhs) noexcept :
72  _cur(a_rhs._cur)
73  {}
74 
75  constexpr iterator_base(iterator_base&& a_rhs) noexcept :
76  _cur(std::move(a_rhs._cur))
77  {
78  a_rhs._cur = nullptr;
79  }
80 
81  ~iterator_base() = default;
82 
83  constexpr iterator_base& operator=(const iterator_base& a_rhs) noexcept
84  {
85  if (this != std::addressof(a_rhs)) {
86  _cur = a_rhs._cur;
87  }
88  return *this;
89  }
90 
91  constexpr iterator_base& operator=(iterator_base&& a_rhs) noexcept
92  {
93  if (this != std::addressof(a_rhs)) {
94  _cur = a_rhs._cur;
95  a_rhs._cur = nullptr;
96  }
97  return *this;
98  }
99 
100  [[nodiscard]] constexpr reference operator*() const noexcept { return *_cur; }
101  [[nodiscard]] constexpr pointer operator->() const noexcept { return _cur; }
102 
103  [[nodiscard]] constexpr friend bool operator==(const iterator_base& a_lhs, const iterator_base& a_rhs) noexcept { return a_lhs._cur == a_rhs._cur; }
104  [[nodiscard]] constexpr friend bool operator!=(const iterator_base& a_lhs, const iterator_base& a_rhs) noexcept { return !(a_lhs == a_rhs); }
105 
106  // prefix
107  constexpr iterator_base& operator++() noexcept
108  {
109  assert(_cur != nullptr);
110  _cur = _cur->next;
111  return *this;
112  }
113 
114  // postfix
115  [[nodiscard]] constexpr iterator_base operator++(int) noexcept
116  {
117  iterator_base tmp{ *this };
118  ++(*this);
119  return tmp;
120  }
121 
122  inline friend void swap(const iterator_base& a_lhs, const iterator_base& a_rhs) noexcept
123  {
124  std::swap(a_lhs._cur, a_rhs._cur);
125  }
126 
127  private:
128  pointer _cur;
129  };
130 
133 
135 
142 
144  const BSExtraData* GetByType(ExtraDataType a_type) const;
145 
146  template <class T>
147  inline T* GetByType()
148  {
149  return static_cast<T*>(GetByType(T::EXTRADATATYPE));
150  }
151 
152  template <class T>
153  inline const T* GetByType() const
154  {
155  return static_cast<const T*>(GetByType(T::EXTRADATATYPE));
156  }
157 
158  bool HasType(ExtraDataType a_type) const;
159 
160  template <class T>
161  inline bool HasType() const
162  {
163  return HasType(T::EXTRADATATYPE);
164  }
165 
166  bool Remove(ExtraDataType a_type, BSExtraData* a_toRemove);
167 
168  template <class T>
169  inline bool Remove(T* a_toRemove)
170  {
171  return Remove(T::EXTRADATATYPE, a_toRemove);
172  }
173 
175 
178  std::int32_t GetCount() const;
179  const char* GetDisplayName(TESBoundObject* a_baseObject);
186  bool GetWorn() const;
188  void SetCount(std::uint16_t a_count);
190  void SetExtraFlags(ExtraFlags::Flag a_flags, bool a_enable);
194  void SetLinkedRef(TESObjectREFR* a_targetRef, BGSKeyword* a_keyword);
195  void SetOwner(TESForm* a_owner);
196 
197  private:
198  BSExtraData* GetByTypeImpl(ExtraDataType a_type) const;
199  void MarkType(std::uint32_t a_type, bool a_cleared);
200  void MarkType(ExtraDataType a_type, bool a_cleared);
201 
202  // members
203  BaseExtraList _extraData; // 00
204  mutable BSReadWriteLock _lock; // 18
205  };
206 #ifndef SKYRIM_SUPPORT_AE
207  static_assert(sizeof(ExtraDataList) == 0x18);
208 #else
209  static_assert(sizeof(ExtraDataList) == 0x20);
210 #endif
211 }
Definition: BGSEncounterZone.h:43
Definition: BGSKeyword.h:10
Definition: BSExtraData.h:9
Definition: BSAtomic.h:112
Definition: ExtraDataList.h:21
PresenceBitfield * presence
Definition: ExtraDataList.h:42
BSExtraData * data
Definition: ExtraDataList.h:41
Definition: ExtraDataList.h:55
constexpr reference operator*() const noexcept
Definition: ExtraDataList.h:100
value_type & reference
Definition: ExtraDataList.h:60
value_type * pointer
Definition: ExtraDataList.h:59
constexpr iterator_base & operator++() noexcept
Definition: ExtraDataList.h:107
std::ptrdiff_t difference_type
Definition: ExtraDataList.h:57
constexpr iterator_base & operator=(iterator_base &&a_rhs) noexcept
Definition: ExtraDataList.h:91
constexpr friend bool operator!=(const iterator_base &a_lhs, const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:104
constexpr iterator_base() noexcept
Definition: ExtraDataList.h:63
constexpr iterator_base(iterator_base &&a_rhs) noexcept
Definition: ExtraDataList.h:75
friend void swap(const iterator_base &a_lhs, const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:122
std::forward_iterator_tag iterator_category
Definition: ExtraDataList.h:61
constexpr iterator_base operator++(int) noexcept
Definition: ExtraDataList.h:115
constexpr friend bool operator==(const iterator_base &a_lhs, const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:103
T value_type
Definition: ExtraDataList.h:58
constexpr iterator_base & operator=(const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:83
constexpr iterator_base(const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:71
constexpr pointer operator->() const noexcept
Definition: ExtraDataList.h:101
constexpr iterator_base(pointer a_node) noexcept
Definition: ExtraDataList.h:67
Definition: ExtraDataList.h:51
void SetEncounterZone(BGSEncounterZone *a_zone)
const_iterator cbegin() const
void SetHeadingTargetRefHandle(ObjectRefHandle &a_handle)
const_iterator end() const
const T * GetByType() const
Definition: ExtraDataList.h:153
const BSExtraData * GetByType(ExtraDataType a_type) const
bool HasType() const
Definition: ExtraDataList.h:161
iterator begin()
BSExtraData * GetByType(ExtraDataType a_type)
ObjectRefHandle GetAshPileRef()
ExtraTextDisplayData * GetExtraTextDisplayData()
void SetOwner(TESForm *a_owner)
BSExtraData * Add(BSExtraData *a_toAdd)
void SetLinkedRef(TESObjectREFR *a_targetRef, BGSKeyword *a_keyword)
BGSEncounterZone * GetEncounterZone()
const_iterator cend() const
bool RemoveByType(ExtraDataType a_type)
bool HasQuestObjectAlias()
TESObjectREFR * GetLinkedRef(BGSKeyword *a_keyword)
const_iterator begin() const
void SetLevCreaModifier(LEV_CREA_MODIFIER a_modifier)
SOUL_LEVEL GetSoulLevel() const
bool HasType(ExtraDataType a_type) const
const char * GetDisplayName(TESBoundObject *a_baseObject)
ObjectRefHandle GetTeleportLinkedDoor()
bool Remove(T *a_toRemove)
Definition: ExtraDataList.h:169
void SetCount(std::uint16_t a_count)
TESForm * GetOwner()
bool Remove(ExtraDataType a_type, BSExtraData *a_toRemove)
std::int32_t GetCount() const
T * GetByType()
Definition: ExtraDataList.h:147
bool GetWorn() const
void SetInventoryChanges(InventoryChanges *a_changes)
void SetExtraFlags(ExtraFlags::Flag a_flags, bool a_enable)
Flag
Definition: ExtraFlags.h:16
Definition: ExtraTextDisplayData.h:14
Definition: InventoryChanges.h:16
Definition: TESBoundObject.h:26
Definition: TESForm.h:40
Definition: TESObjectREFR.h:113
Definition: AbsorbEffect.h:6
SOUL_LEVEL
Definition: SoulLevels.h:6
LEV_CREA_MODIFIER
Definition: ExtraLevCreaModifier.h:9
void swap(BSTTuple< T1, T2 > &a_lhs, BSTTuple< T1, T2 > &a_rhs) noexcept(noexcept(a_lhs.swap(a_rhs))) requires(std
Definition: BSTTuple.h:214
ExtraDataType
Definition: ExtraDataTypes.h:173
Definition: ExtraDataList.h:24
bool HasType(std::uint32_t a_type) const
void MarkType(std::uint32_t a_type, bool a_cleared)
std::uint8_t bits[0x18]
Definition: ExtraDataList.h:30