libER 0.1.4.2
ELDEN RING API library
Loading...
Searching...
No Matches
param_iterator.hpp
Go to the documentation of this file.
1
8#pragma once
9
10#include <detail/preprocessor.hpp>
11#include <param/detail/paramdef.hpp>
13#include <param/param_file.hpp>
14
15#include <compare>
16#include <cstddef>
17#include <cstdint>
18#include <iterator>
19#include <type_traits>
20#include <utility>
21
22namespace from {
23namespace param {
29template <typename Def>
31 uintptr_t file_start;
33
34public:
39 using iterator_concept = std::bidirectional_iterator_tag;
40
45 using iterator_category = std::bidirectional_iterator_tag;
46
51 using value_type = std::pair<row_index_type, Def&>;
52
57 using difference_type = ptrdiff_t;
58
64
70
77 param_iterator() noexcept : file_start(0), ptr(nullptr) {}
78
85 param_iterator(const param_file& file, difference_type pos) noexcept
86 : file_start(file.get_file_start()),
87 ptr(&*file.get_param_row_locators().begin() + pos) {}
88
93 param_iterator(const param_iterator& other) noexcept
94 : file_start(other.file_start), ptr(other.ptr) {}
95
101 const param_iterator<std::remove_const_t<Def>>& other) noexcept
102 requires(std::is_const_v<Def>)
103 : file_start(other.file_start), ptr(other.ptr) {}
104
112 value_type operator*() const noexcept {
113 return { this->ptr->row,
114 *reinterpret_cast<Def*>(
115 this->file_start + this->ptr->file_offset) };
116 }
117
124 ++this->ptr;
125 return *this;
126 }
127
134 param_iterator tmp = *this;
135 ++this->ptr;
136 return tmp;
137 }
138
145 --this->ptr;
146 return *this;
147 }
148
155 param_iterator tmp = *this;
156 --this->ptr;
157 return tmp;
158 }
159
167 this->ptr += offset;
168 return *this;
169 }
170
177 param_iterator operator+(difference_type offset) const noexcept {
178 param_iterator tmp = *this;
179 tmp += offset;
180 return tmp;
181 }
182
190 this->ptr -= offset;
191 return *this;
192 }
193
200 param_iterator operator-(difference_type offset) const noexcept {
201 param_iterator tmp = *this;
202 tmp -= offset;
203 return tmp;
204 }
205
217 template <typename OtherDef>
219 const param_iterator<OtherDef>& rhs) const noexcept
220 requires(std::is_same_v<const Def, const OtherDef>)
221 {
222 return static_cast<difference_type>(this->ptr - rhs.ptr);
223 }
224
231 value_type operator[](difference_type offset) const noexcept {
232 return *(*this + offset);
233 }
234
248 template <typename OtherDef>
249 bool operator==(const param_iterator<OtherDef>& rhs) const noexcept
250 requires(std::is_same_v<const Def, const OtherDef>)
251 {
252 return this->ptr == rhs.ptr;
253 }
254
262 template <typename OtherDef>
263 std::strong_ordering operator<=>(
264 const param_iterator<OtherDef>& rhs) const noexcept
265 requires(std::is_same_v<const Def, const OtherDef>)
266 {
267 return this->ptr <=> rhs.ptr;
268 }
269
270private:
271 template <typename>
272 friend class param_iterator;
273
274 template <typename>
275 friend class param_table;
276
277 param_iterator(const param_iterator<const Def>& other) noexcept
278 requires(!std::is_const_v<Def>)
279 : file_start(other.file_start), ptr(other.ptr) {}
280};
281
287template <typename Def>
289} // namespace param
290} // namespace from
The bidirectional param table iterator.
Definition param_iterator.hpp:30
param_iterator operator-(difference_type offset) const noexcept
Subtract offset entries from the iterator.
Definition param_iterator.hpp:200
param_iterator(const param_file &file, difference_type pos) noexcept
Construct a param iterator at a given row entry position.
Definition param_iterator.hpp:85
std::bidirectional_iterator_tag iterator_category
Bidirectional iterator category tag.
Definition param_iterator.hpp:45
param_iterator & operator-=(difference_type offset) noexcept
Advance the iterator backwards by offset entries.
Definition param_iterator.hpp:189
std::strong_ordering operator<=>(const param_iterator< OtherDef > &rhs) const noexcept
The iterator relation operator in terms of row indices.
Definition param_iterator.hpp:263
ptrdiff_t difference_type
Iterator difference type.
Definition param_iterator.hpp:57
param_iterator operator+(difference_type offset) const noexcept
Add offset entries to the iterator.
Definition param_iterator.hpp:177
value_type operator*() const noexcept
Dereference the iterator at the current position to get a row index/row pair.
Definition param_iterator.hpp:112
param_iterator(const param_iterator &other) noexcept
Construct a new param iterator (copy constructor).
Definition param_iterator.hpp:93
value_type * pointer
Iterator pointer type.
Definition param_iterator.hpp:63
param_iterator & operator++() noexcept
Advance the iterator forwards by one entry (precrement).
Definition param_iterator.hpp:123
bool operator==(const param_iterator< OtherDef > &rhs) const noexcept
The iterator equality comparison operator.
Definition param_iterator.hpp:249
difference_type operator-(const param_iterator< OtherDef > &rhs) const noexcept
How many steps would it take from this iterator to reach iterator rhs?
Definition param_iterator.hpp:218
param_iterator & operator--() noexcept
Advance the iterator backwards by one entry (predecrement).
Definition param_iterator.hpp:144
param_iterator(const param_iterator< std::remove_const_t< Def > > &other) noexcept
Construct a new param iterator (const iterator promotion).
Definition param_iterator.hpp:100
value_type & reference
Iterator reference type.
Definition param_iterator.hpp:69
param_iterator operator++(int) noexcept
Advance the iterator forwards by one entry (postcrement).
Definition param_iterator.hpp:133
value_type operator[](difference_type offset) const noexcept
Param table iterator subscript.
Definition param_iterator.hpp:231
param_iterator() noexcept
Default construct a param iterator.
Definition param_iterator.hpp:77
std::pair< row_index_type, Def & > value_type
Dereferencing returns a row index/row pair.
Definition param_iterator.hpp:51
param_iterator & operator+=(difference_type offset) noexcept
Advance the iterator forwards by offset entries.
Definition param_iterator.hpp:166
std::bidirectional_iterator_tag iterator_concept
Bidirectional iterator concept tag.
Definition param_iterator.hpp:39
param_iterator operator--(int) noexcept
Advance the iterator backwards by one entry (postdecrement).
Definition param_iterator.hpp:154
An interface to a param table of one of the predefined types.
Definition param_table.hpp:34
ELDEN RING param defines and enums.
ELDEN RING param file layouts.
An instance of a structure describing a param table entry later in the file.
Definition param_file.hpp:77
uintptr_t file_offset
The offset (from the start of the file) to this param's row data.
Definition param_file.hpp:89
row_index_type row
The param row index.
Definition param_file.hpp:82
The layout of a .param file.
Definition param_file.hpp:24