CommonLibSSE (Parapets fork)
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"
8 #include "RE/F/FormTypes.h"
9 #include "RE/M/MemoryManager.h"
10 #include "RE/S/SoulLevels.h"
11 
12 namespace RE
13 {
14  class InventoryChanges;
15  class TESBoundObject;
16 
18  {
19  public:
21  {
22  public:
23  [[nodiscard]] bool HasType(std::uint32_t a_type) const;
24  void MarkType(std::uint32_t a_type, bool a_cleared);
25 
26  // members
27  std::uint8_t bits[0x18]; // 00
28  };
29  static_assert(sizeof(PresenceBitfield) == 0x18);
30 
31 #if !defined(SKYRIMVR) && !defined(SKYRIMSE_PRE_1_6_629)
32  virtual ~BaseExtraList(); // 00
33 #else
35 #endif
36 
38 
39  // members
40  BSExtraData* data = nullptr; // 08
41  PresenceBitfield* presence = nullptr; // 10
42  };
43 #if !defined(SKYRIMVR) && !defined(SKYRIMSE_PRE_1_6_629)
44  static_assert(sizeof(BaseExtraList) == 0x18);
45 #else
46  static_assert(sizeof(BaseExtraList) == 0x10);
47 #endif
48 
50  {
51  public:
52  template <class T>
54  {
55  public:
56  using difference_type = std::ptrdiff_t;
57  using value_type = T;
58  using pointer = value_type*;
60  using iterator_category = std::forward_iterator_tag;
61 
62  constexpr iterator_base() noexcept :
63  _cur(nullptr)
64  {}
65 
66  constexpr iterator_base(pointer a_node) noexcept :
67  _cur(a_node)
68  {}
69 
70  constexpr iterator_base(const iterator_base& a_rhs) noexcept :
71  _cur(a_rhs._cur)
72  {}
73 
74  constexpr iterator_base(iterator_base&& a_rhs) noexcept :
75  _cur(std::move(a_rhs._cur))
76  {
77  a_rhs._cur = nullptr;
78  }
79 
80  ~iterator_base() = default;
81 
82  constexpr iterator_base& operator=(const iterator_base& a_rhs) noexcept
83  {
84  if (this != std::addressof(a_rhs)) {
85  _cur = a_rhs._cur;
86  }
87  return *this;
88  }
89 
90  constexpr iterator_base& operator=(iterator_base&& a_rhs) noexcept
91  {
92  if (this != std::addressof(a_rhs)) {
93  _cur = a_rhs._cur;
94  a_rhs._cur = nullptr;
95  }
96  return *this;
97  }
98 
99  [[nodiscard]] constexpr reference operator*() const noexcept { return *_cur; }
100  [[nodiscard]] constexpr pointer operator->() const noexcept { return _cur; }
101 
102  [[nodiscard]] constexpr friend bool operator==(const iterator_base& a_lhs, const iterator_base& a_rhs) noexcept { return a_lhs._cur == a_rhs._cur; }
103  [[nodiscard]] constexpr friend bool operator!=(const iterator_base& a_lhs, const iterator_base& a_rhs) noexcept { return !(a_lhs == a_rhs); }
104 
105  // prefix
106  constexpr iterator_base& operator++() noexcept
107  {
108  assert(_cur != nullptr);
109  _cur = _cur->next;
110  return *this;
111  }
112 
113  // postfix
114  [[nodiscard]] constexpr iterator_base operator++(int) noexcept
115  {
116  iterator_base tmp{ *this };
117  ++(*this);
118  return tmp;
119  }
120 
121  inline friend void swap(const iterator_base& a_lhs, const iterator_base& a_rhs) noexcept
122  {
123  std::swap(a_lhs._cur, a_rhs._cur);
124  }
125 
126  private:
127  pointer _cur;
128  };
129 
132 
134 
141 
143  const BSExtraData* GetByType(ExtraDataType a_type) const;
144 
145  template <class T>
146  inline T* GetByType()
147  {
148  return static_cast<T*>(GetByType(T::EXTRADATATYPE));
149  }
150 
151  template <class T>
152  inline const T* GetByType() const
153  {
154  return static_cast<const T*>(GetByType(T::EXTRADATATYPE));
155  }
156 
157  bool HasType(ExtraDataType a_type) const;
158 
159  template <class T>
160  inline bool HasType() const
161  {
162  return HasType(T::EXTRADATATYPE);
163  }
164 
165  bool Remove(ExtraDataType a_type, BSExtraData* a_toRemove);
166 
167  template <class T>
168  inline bool Remove(T* a_toRemove)
169  {
170  return Remove(T::EXTRADATATYPE, a_toRemove);
171  }
172 
174 
177  std::int32_t GetCount() const;
178  const char* GetDisplayName(TESBoundObject* a_baseObject);
184  void SetCount(std::uint16_t a_count);
185  void SetEnchantment(EnchantmentItem* a_enchantment, std::uint16_t a_chargeAmount, bool a_removeOnUnequip);
186  void SetExtraFlags(ExtraFlags::Flag a_flags, bool a_enable);
188  void SetOverrideName(const char* a_name);
189  void SetOwner(TESForm* a_owner);
190 
191  private:
192  BSExtraData* GetByTypeImpl(ExtraDataType a_type) const;
193  void MarkType(std::uint32_t a_type, bool a_cleared);
194  void MarkType(ExtraDataType a_type, bool a_cleared);
195 
196  // members
197  BaseExtraList _extraData; // 00
198  mutable BSReadWriteLock _lock; // 18
199  };
200 #if !defined(SKYRIMVR) && !defined(SKYRIMSE_PRE_1_6_629)
201  static_assert(sizeof(ExtraDataList) == 0x20);
202 #else
203  static_assert(sizeof(ExtraDataList) == 0x18);
204 #endif
205 }
Definition: BGSEncounterZone.h:43
Definition: BGSKeyword.h:10
Definition: BSExtraData.h:9
Definition: BSAtomic.h:69
Definition: ExtraDataList.h:18
virtual ~BaseExtraList()
PresenceBitfield * presence
Definition: ExtraDataList.h:41
BSExtraData * data
Definition: ExtraDataList.h:40
Definition: EnchantmentItem.h:10
Definition: ExtraDataList.h:54
constexpr reference operator*() const noexcept
Definition: ExtraDataList.h:99
value_type & reference
Definition: ExtraDataList.h:59
value_type * pointer
Definition: ExtraDataList.h:58
constexpr iterator_base & operator++() noexcept
Definition: ExtraDataList.h:106
std::ptrdiff_t difference_type
Definition: ExtraDataList.h:56
constexpr iterator_base & operator=(iterator_base &&a_rhs) noexcept
Definition: ExtraDataList.h:90
constexpr friend bool operator!=(const iterator_base &a_lhs, const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:103
constexpr iterator_base() noexcept
Definition: ExtraDataList.h:62
constexpr iterator_base(iterator_base &&a_rhs) noexcept
Definition: ExtraDataList.h:74
friend void swap(const iterator_base &a_lhs, const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:121
std::forward_iterator_tag iterator_category
Definition: ExtraDataList.h:60
constexpr iterator_base operator++(int) noexcept
Definition: ExtraDataList.h:114
constexpr friend bool operator==(const iterator_base &a_lhs, const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:102
T value_type
Definition: ExtraDataList.h:57
constexpr iterator_base & operator=(const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:82
constexpr iterator_base(const iterator_base &a_rhs) noexcept
Definition: ExtraDataList.h:70
constexpr pointer operator->() const noexcept
Definition: ExtraDataList.h:100
constexpr iterator_base(pointer a_node) noexcept
Definition: ExtraDataList.h:66
Definition: ExtraDataList.h:50
const_iterator cbegin() const
void SetOverrideName(const char *a_name)
const_iterator end() const
const T * GetByType() const
Definition: ExtraDataList.h:152
const BSExtraData * GetByType(ExtraDataType a_type) const
void SetEnchantment(EnchantmentItem *a_enchantment, std::uint16_t a_chargeAmount, bool a_removeOnUnequip)
bool HasType() const
Definition: ExtraDataList.h:160
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)
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)
bool Remove(T *a_toRemove)
Definition: ExtraDataList.h:168
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:146
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:17
Definition: TESBoundObject.h:24
Definition: TESForm.h:34
Definition: TESObjectREFR.h:105
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:21
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:27