CommonLibSSE NG
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/F/FormTypes.h"
10 #include "RE/M/MemoryManager.h"
11 #include "RE/S/SoulLevels.h"
12 
13 namespace RE
14 {
15  class InventoryChanges;
16  class TESBoundObject;
17 
19  {
20  public:
22  {
23  public:
24  [[nodiscard]] bool HasType(std::uint32_t a_type) const;
25  void MarkType(std::uint32_t a_type, bool a_cleared);
26 
27  // members
28  std::uint8_t bits[0x18]; // 00
29  };
30  static_assert(sizeof(PresenceBitfield) == 0x18);
31 
32  [[nodiscard]] BSExtraData*& GetData() noexcept;
33 
34  [[nodiscard]] const BSExtraData*& GetData() const noexcept;
35 
36  [[nodiscard]] PresenceBitfield*& GetPresence() noexcept;
37 
38  [[nodiscard]] const PresenceBitfield*& GetPresence() const noexcept;
39 
40 #ifndef ENABLE_SKYRIM_AE
41  ~BaseExtraList(); // 00, virtual on AE 1.6.629 and later.
42 
43  // members
44  BSExtraData* data = nullptr; // 00, 08
45  PresenceBitfield* presence = nullptr; // 08, 10
46 #endif
47  };
48 #ifndef ENABLE_SKYRIM_AE
49  static_assert(sizeof(BaseExtraList) == 0x10);
50 #endif
51 
53  {
54  public:
55  template <class T>
57  {
58  public:
59  using difference_type = std::ptrdiff_t;
60  using value_type = T;
61  using pointer = value_type*;
63  using iterator_category = std::forward_iterator_tag;
64 
65  constexpr iterator_base() noexcept :
66  _cur(nullptr)
67  {}
68 
69  constexpr iterator_base(pointer a_node) noexcept :
70  _cur(a_node)
71  {}
72 
73  constexpr iterator_base(const iterator_base& a_rhs) noexcept :
74  _cur(a_rhs._cur)
75  {}
76 
77  constexpr iterator_base(iterator_base&& a_rhs) noexcept :
78  _cur(std::move(a_rhs._cur))
79  {
80  a_rhs._cur = nullptr;
81  }
82 
83  ~iterator_base() = default;
84 
85  constexpr iterator_base& operator=(const iterator_base& a_rhs) noexcept
86  {
87  if (this != std::addressof(a_rhs)) {
88  _cur = a_rhs._cur;
89  }
90  return *this;
91  }
92 
93  constexpr iterator_base& operator=(iterator_base&& a_rhs) noexcept
94  {
95  if (this != std::addressof(a_rhs)) {
96  _cur = a_rhs._cur;
97  a_rhs._cur = nullptr;
98  }
99  return *this;
100  }
101 
102  [[nodiscard]] constexpr reference operator*() const noexcept { return *_cur; }
103  [[nodiscard]] constexpr pointer operator->() const noexcept { return _cur; }
104 
105  [[nodiscard]] constexpr friend bool operator==(const iterator_base& a_lhs, const iterator_base& a_rhs) noexcept { return a_lhs._cur == a_rhs._cur; }
106  [[nodiscard]] constexpr friend bool operator!=(const iterator_base& a_lhs, const iterator_base& a_rhs) noexcept { return !(a_lhs == a_rhs); }
107 
108  // prefix
109  constexpr iterator_base& operator++() noexcept
110  {
111  assert(_cur != nullptr);
112  _cur = _cur->next;
113  return *this;
114  }
115 
116  // postfix
117  [[nodiscard]] constexpr iterator_base operator++(int) noexcept
118  {
119  iterator_base tmp{ *this };
120  ++(*this);
121  return tmp;
122  }
123 
124  inline friend void swap(const iterator_base& a_lhs, const iterator_base& a_rhs) noexcept
125  {
126  std::swap(a_lhs._cur, a_rhs._cur);
127  }
128 
129  private:
130  pointer _cur;
131  };
132 
135 
138 
140 
147 
149  const BSExtraData* GetByType(ExtraDataType a_type) const;
150 
151  template <class T>
152  inline T* GetByType()
153  {
154  return static_cast<T*>(GetByType(T::EXTRADATATYPE));
155  }
156 
157  template <class T>
158  inline const T* GetByType() const
159  {
160  return static_cast<const T*>(GetByType(T::EXTRADATATYPE));
161  }
162 
163  bool HasType(ExtraDataType a_type) const;
164 
165  template <class T>
166  inline bool HasType() const
167  {
168  return HasType(T::EXTRADATATYPE);
169  }
170 
171  bool Remove(ExtraDataType a_type, BSExtraData* a_toRemove);
172 
173  template <class T>
174  inline bool Remove(T* a_toRemove)
175  {
176  return Remove(T::EXTRADATATYPE, a_toRemove);
177  }
178 
180 
183  std::int32_t GetCount() const;
184  const char* GetDisplayName(TESBoundObject* a_baseObject);
192  void SetCount(std::uint16_t a_count);
194  void SetExtraFlags(ExtraFlags::Flag a_flags, bool a_enable);
196  void SetOwner(TESForm* a_owner);
197 
198  private:
199  [[nodiscard]] BSExtraData* GetByTypeImpl(ExtraDataType a_type) const;
200  void MarkType(std::uint32_t a_type, bool a_cleared);
201  void MarkType(ExtraDataType a_type, bool a_cleared);
202  [[nodiscard]] BSReadWriteLock& GetLock() const noexcept;
203 
204  // members
205  BaseExtraList _extraData; // 00
206 #ifndef ENABLE_SKYRIM_AE
207  mutable BSReadWriteLock _lock; // 10, 18; offset 18 only for AE versions .629 and later.
208 #endif
209  };
210 }
Definition: BGSEncounterZone.h:43
Definition: BGSKeyword.h:10
Definition: BSExtraData.h:9
Definition: BSAtomic.h:71
Definition: ExtraDataList.h:19
PresenceBitfield *& GetPresence() noexcept
BSExtraData *& GetData() noexcept
PresenceBitfield * presence
Definition: ExtraDataList.h:45
BSExtraData * data
Definition: ExtraDataList.h:44
Definition: ExtraDataList.h:57
constexpr reference operator*() const noexcept
Definition: ExtraDataList.h:102
value_type & reference
Definition: ExtraDataList.h:62
value_type * pointer
Definition: ExtraDataList.h:61
constexpr iterator_base & operator++() noexcept
Definition: ExtraDataList.h:109
std::ptrdiff_t difference_type
Definition: ExtraDataList.h:59
constexpr iterator_base & operator=(iterator_base &&a_rhs) noexcept
Definition: ExtraDataList.h:93
constexpr friend bool operator!=(const iterator_base &a_lhs, const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:106
constexpr iterator_base() noexcept
Definition: ExtraDataList.h:65
constexpr iterator_base(iterator_base &&a_rhs) noexcept
Definition: ExtraDataList.h:77
friend void swap(const iterator_base &a_lhs, const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:124
std::forward_iterator_tag iterator_category
Definition: ExtraDataList.h:63
constexpr iterator_base operator++(int) noexcept
Definition: ExtraDataList.h:117
constexpr friend bool operator==(const iterator_base &a_lhs, const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:105
T value_type
Definition: ExtraDataList.h:60
constexpr iterator_base & operator=(const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:85
constexpr iterator_base(const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:73
constexpr pointer operator->() const noexcept
Definition: ExtraDataList.h:103
constexpr iterator_base(pointer a_node) noexcept
Definition: ExtraDataList.h:69
Definition: ExtraDataList.h:53
void SetEncounterZone(BGSEncounterZone *a_zone)
const_iterator cbegin() const
const_iterator end() const
const T * GetByType() const
Definition: ExtraDataList.h:158
const BSExtraData * GetByType(ExtraDataType a_type) const
bool HasType() const
Definition: ExtraDataList.h:166
iterator begin()
BSExtraData * GetByType(ExtraDataType a_type)
ObjectRefHandle GetAshPileRef()
ExtraTextDisplayData * GetExtraTextDisplayData()
void SetOwner(TESForm *a_owner)
BSExtraData * Add(BSExtraData *a_toAdd)
BGSEncounterZone * GetEncounterZone()
const_iterator cend() const
bool RemoveByType(ExtraDataType a_type)
bool HasQuestObjectAlias()
TESObjectREFR * GetLinkedRef(BGSKeyword *a_keyword)
const_iterator begin() const
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:174
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:152
void SetInventoryChanges(InventoryChanges *a_changes)
void SetExtraFlags(ExtraFlags::Flag a_flags, bool a_enable)
Flag
Definition: ExtraFlags.h:15
Definition: ExtraTextDisplayData.h:14
Definition: InventoryChanges.h:16
Definition: TESBoundObject.h:24
Definition: TESForm.h:36
Definition: TESObjectREFR.h:113
Definition: AbsorbEffect.h:6
SOUL_LEVEL
Definition: SoulLevels.h:6
void swap(BSTTuple< T1, T2 > &a_lhs, BSTTuple< T1, T2 > &a_rhs) noexcept(noexcept(a_lhs.swap(a_rhs))) requires(std
Definition: BSTTuple.h:212
ExtraDataType
Definition: ExtraDataTypes.h:173
Definition: ExtraDataList.h:22
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:28