CommonLibSSE (powerof3)
Loading...
Searching...
No Matches
NiTListBase.h
Go to the documentation of this file.
1#pragma once
2
3namespace RE
4{
5 template <class T>
7 {
8 public:
10 next(nullptr),
11 prev(nullptr),
12 element{}
13 {}
14
17 T element; // 10
18 };
19 static_assert(sizeof(NiTListItem<void*>) == 0x18);
20
21 template <class Allocator, class T>
23 {
24 private:
25 using Node = NiTListItem<T>;
26
27 public:
28 using value_type = T;
29 using size_type = std::uint32_t;
30 using difference_type = std::ptrdiff_t;
33
34 template <class U>
36 {
37 public:
38 using difference_type = std::ptrdiff_t;
39 using value_type = U;
40 using pointer = U*;
41 using reference = U&;
42 using iterator_category = std::bidirectional_iterator_tag;
43
44 constexpr iterator_base() noexcept :
45 _cur(nullptr)
46 {}
47
48 constexpr iterator_base(Node* a_node) noexcept :
50 {}
51
52 constexpr iterator_base(const iterator_base& a_rhs) noexcept :
54 {}
55
56 constexpr iterator_base(iterator_base&& a_rhs) noexcept :
57 _cur(std::move(a_rhs._cur))
58 {
59 a_rhs._cur = nullptr;
60 }
61
62 inline ~iterator_base() noexcept { _cur = nullptr; }
63
64 constexpr iterator_base& operator=(const iterator_base& a_rhs) noexcept
65 {
66 if (this != std::addressof(a_rhs)) {
67 _cur = a_rhs._cur;
68 }
69 return *this;
70 }
71
73 {
74 if (this != std::addressof(a_rhs)) {
75 _cur = std::move(a_rhs._cur);
76 a_rhs._cur = nullptr;
77 }
78 return *this;
79 }
80
81 [[nodiscard]] constexpr reference operator*() const noexcept { return _cur->element; }
82 [[nodiscard]] constexpr pointer operator->() const noexcept { return std::addressof(_cur->element); }
83
84 [[nodiscard]] constexpr bool operator==(const iterator_base& a_rhs) const noexcept { return _cur == a_rhs._cur; }
85 [[nodiscard]] constexpr bool operator!=(const iterator_base& a_rhs) const noexcept { return !(*this == a_rhs); }
86
87 protected:
88 friend class NiTListBase<T, Allocator>;
89
91 };
92
93 template <class U>
95 {
96 public:
97 // prefix
98 constexpr forward_iterator& operator++() noexcept
99 {
100 assert(this->_cur);
101 this->_cur = this->_cur->next;
102 return *this;
103 }
104
105 // postfix
106 [[nodiscard]] constexpr forward_iterator operator++(int) noexcept
107 {
108 iterator_base tmp(*this);
109 ++(*this);
110 return tmp;
111 }
112 };
113
114 template <class U>
116 {
117 public:
118 // prefix
119 constexpr backward_iterator& operator++() noexcept
120 {
121 assert(this->_cur);
122 this->_cur = this->_cur->prev;
123 return *this;
124 }
125
126 // postfix
127 [[nodiscard]] constexpr backward_iterator operator++(int) noexcept
128 {
129 iterator_base tmp(*this);
130 ++(*this);
131 return tmp;
132 }
133 };
134
139
140 inline NiTListBase() :
141 head(nullptr),
142 tail(nullptr),
143 allocator(0)
144 {}
145
147 {
148 assert(!empty());
149 return *begin();
150 }
151
152 [[nodiscard]] inline const_reference front() const
153 {
154 assert(!empty());
155 return *begin();
156 }
157
159 {
160 assert(!empty());
161 return *rbegin();
162 }
163
164 [[nodiscard]] inline const_reference back() const
165 {
166 assert(!empty());
167 return *rbegin();
168 }
169
170 [[nodiscard]] inline iterator begin() { return empty() ? end() : iterator(head); }
171 [[nodiscard]] inline const_iterator begin() const { return empty() ? end() : const_iterator(head); }
172 [[nodiscard]] inline const_iterator cbegin() const { return begin(); }
173
174 [[nodiscard]] constexpr iterator end() noexcept { return iterator(nullptr); }
175 [[nodiscard]] constexpr const_iterator end() const noexcept { return const_iterator(nullptr); }
176 [[nodiscard]] constexpr const_iterator cend() const noexcept { return end(); }
177
180 [[nodiscard]] inline const_reverse_iterator crbegin() const { return rbegin(); }
181
182 [[nodiscard]] constexpr reverse_iterator rend() noexcept { return reverse_iterator(nullptr); }
183 [[nodiscard]] constexpr const_reverse_iterator rend() const noexcept { return const_reverse_iterator(nullptr); }
184 [[nodiscard]] constexpr const_reverse_iterator crend() const noexcept { return rend(); }
185
186 [[nodiscard]] inline bool empty() const { return allocator.size == 0; }
187 [[nodiscard]] size_type size() const noexcept { return allocator.size; }
188
189 protected:
190 struct AntiBloatAllocator : public Allocator
191 {
192 // members
193 std::uint32_t size; // ??
194 };
195
196 // members
200 };
201}
Definition NiTListBase.h:116
constexpr backward_iterator operator++(int) noexcept
Definition NiTListBase.h:127
constexpr backward_iterator & operator++() noexcept
Definition NiTListBase.h:119
Definition NiTListBase.h:95
constexpr forward_iterator & operator++() noexcept
Definition NiTListBase.h:98
constexpr forward_iterator operator++(int) noexcept
Definition NiTListBase.h:106
Definition NiTListBase.h:36
constexpr iterator_base(Node *a_node) noexcept
Definition NiTListBase.h:48
constexpr bool operator==(const iterator_base &a_rhs) const noexcept
Definition NiTListBase.h:84
Node * _cur
Definition NiTListBase.h:90
std::bidirectional_iterator_tag iterator_category
Definition NiTListBase.h:42
constexpr iterator_base(iterator_base &&a_rhs) noexcept
Definition NiTListBase.h:56
constexpr pointer operator->() const noexcept
Definition NiTListBase.h:82
constexpr iterator_base() noexcept
Definition NiTListBase.h:44
constexpr reference operator*() const noexcept
Definition NiTListBase.h:81
~iterator_base() noexcept
Definition NiTListBase.h:62
constexpr iterator_base(const iterator_base &a_rhs) noexcept
Definition NiTListBase.h:52
std::ptrdiff_t difference_type
Definition NiTListBase.h:38
constexpr iterator_base & operator=(iterator_base &&a_rhs) noexcept
Definition NiTListBase.h:72
constexpr bool operator!=(const iterator_base &a_rhs) const noexcept
Definition NiTListBase.h:85
constexpr iterator_base & operator=(const iterator_base &a_rhs) noexcept
Definition NiTListBase.h:64
Definition NiTListBase.h:23
constexpr iterator end() noexcept
Definition NiTListBase.h:174
forward_iterator< value_type > iterator
Definition NiTListBase.h:135
AntiBloatAllocator allocator
Definition NiTListBase.h:199
reverse_iterator rbegin()
Definition NiTListBase.h:178
constexpr const_iterator end() const noexcept
Definition NiTListBase.h:175
backward_iterator< value_type > reverse_iterator
Definition NiTListBase.h:137
reference front()
Definition NiTListBase.h:146
iterator begin()
Definition NiTListBase.h:170
constexpr const_reverse_iterator crend() const noexcept
Definition NiTListBase.h:184
size_type size() const noexcept
Definition NiTListBase.h:187
const_iterator cbegin() const
Definition NiTListBase.h:172
std::uint32_t size_type
Definition NiTListBase.h:29
constexpr const_iterator cend() const noexcept
Definition NiTListBase.h:176
const_reverse_iterator crbegin() const
Definition NiTListBase.h:180
NiTListBase()
Definition NiTListBase.h:140
reference back()
Definition NiTListBase.h:158
const_reverse_iterator rbegin() const
Definition NiTListBase.h:179
NiTListItem< T > * head
Definition NiTListBase.h:197
constexpr reverse_iterator rend() noexcept
Definition NiTListBase.h:182
backward_iterator< const value_type > const_reverse_iterator
Definition NiTListBase.h:138
const_reference back() const
Definition NiTListBase.h:164
const_iterator begin() const
Definition NiTListBase.h:171
bool empty() const
Definition NiTListBase.h:186
forward_iterator< const value_type > const_iterator
Definition NiTListBase.h:136
constexpr const_reverse_iterator rend() const noexcept
Definition NiTListBase.h:183
const_reference front() const
Definition NiTListBase.h:152
NiTListItem< T > * tail
Definition NiTListBase.h:198
std::ptrdiff_t difference_type
Definition NiTListBase.h:30
Definition NiTListBase.h:7
NiTListItem * next
Definition NiTListBase.h:15
T element
Definition NiTListBase.h:17
NiTListItem * prev
Definition NiTListBase.h:16
NiTListItem()
Definition NiTListBase.h:9
Definition AbsorbEffect.h:6
Definition NiTListBase.h:191
std::uint32_t size
Definition NiTListBase.h:193