libER 0.1.4.2
ELDEN RING API library
Loading...
Searching...
No Matches
param_table.hpp
Go to the documentation of this file.
1
8#pragma once
9
10#include <coresystem/cs_param.hpp>
11#include <detail/optref.hpp>
12#include <detail/preprocessor.hpp>
13#include <param/detail/paramdef.hpp>
16
17#include <algorithm>
18#include <atomic>
19#include <cstddef>
20#include <cstdint>
21#include <iterator>
22#include <memory>
23#include <type_traits>
24#include <utility>
25
26namespace from {
27namespace param {
33template <typename ParamType>
35public:
40 using paramdef_type = typename ParamType::paramdef_type;
41
46 static constexpr param_index index = ParamType::index;
47
53
58 using reverse_iterator = std::reverse_iterator<iterator>;
59
65
70 using const_reverse_iterator = std::reverse_iterator<const_iterator>;
71
72 constexpr param_table() = default;
73
90 std::pair<paramdef_type&, bool> operator[](
91 row_index_type row) const noexcept {
92 iterator first = this->begin();
93 iterator last = this->end();
94 iterator found = std::lower_bound(first, last, row,
95 [](const auto& cmp, const auto& row) { return cmp.first < row; });
96 if (found == last || (*found).first != row) {
97 if (!this->dummy_param) {
98 auto swap = std::make_unique<paramdef_type>();
99 std::atomic_thread_fence(std::memory_order_seq_cst);
100 this->dummy_param.swap(swap);
101 std::atomic_thread_fence(std::memory_order_seq_cst);
102 }
103 return { *this->dummy_param, false };
104 }
105 return { (*found).second, true };
106 }
107
117 iterator begin() noexcept {
118 auto file = this->get_file();
119 // Param table is not loaded, return default constructed iterator
120 if (!file)
121 return iterator{};
122 auto& file_ref = *file.reference();
123 return iterator(file_ref, 0);
124 }
125
135 iterator end() noexcept {
136 auto file = this->get_file();
137 // Param table is not loaded, return default constructed iterator
138 if (!file)
139 return iterator{};
140 auto& file_ref = *file.reference();
141 return iterator(file_ref, file_ref.row_count);
142 }
143
153 const_iterator begin() const noexcept {
154 return const_cast<param_table*>(this)->begin();
155 }
156
166 const_iterator end() const noexcept {
167 return const_cast<param_table*>(this)->end();
168 }
169
179 const_iterator cbegin() const noexcept {
180 return this->begin();
181 }
182
192 const_iterator cend() const noexcept {
193 return this->end();
194 }
195
206 return this->end();
207 }
208
219 return this->begin();
220 }
221
232 return this->end();
233 }
234
244 const_reverse_iterator rend() const noexcept {
245 return this->begin();
246 }
247
258 return this->end();
259 }
260
270 const_reverse_iterator crend() const noexcept {
271 return this->begin();
272 }
273
274private:
275 mutable std::unique_ptr<paramdef_type> dummy_param;
276
277 liber::optref<param_file*> get_file() noexcept {
278 auto repository = CS::SoloParamRepository::instance();
279 if (!repository)
280 return std::nullopt;
281 return repository.reference().get_param_file(index);
282 }
283};
284
289template <param_index Index, typename Def>
295 using paramdef_type = Def;
296
301 static constexpr param_index index = Index;
302};
303
304#define LIBER_PARAM_ENTRY(PARAM, PARAMDEF) \
305 inline param_table<param_type<param_index::PARAM, paramdef::PARAMDEF>> \
306 PARAM;
307
308#include <param/detail/paramlist.inl>
309
310#undef LIBER_PARAM_ENTRY
311} // namespace param
312} // namespace from
The bidirectional param table iterator.
Definition param_iterator.hpp:30
value_type & reference
Iterator reference type.
Definition param_iterator.hpp:69
An interface to a param table of one of the predefined types.
Definition param_table.hpp:34
const_reverse_iterator rend() const noexcept
Get the reverse iterator before the first param row in the table.
Definition param_table.hpp:244
const_reverse_iterator crbegin() const noexcept
Get the reverse iterator to the last param row in the table.
Definition param_table.hpp:257
std::reverse_iterator< iterator > reverse_iterator
Reverse order param iterator type.
Definition param_table.hpp:58
const_iterator cbegin() const noexcept
Get the const iterator to the first param row in the table.
Definition param_table.hpp:179
const_iterator begin() const noexcept
Get the iterator to the first param row in the table.
Definition param_table.hpp:153
param_iterator< paramdef_type > iterator
Param iterator type.
Definition param_table.hpp:52
iterator begin() noexcept
Get the iterator to the first param row in the table.
Definition param_table.hpp:117
typename ParamType::paramdef_type paramdef_type
The paramdefs this param type uses.
Definition param_table.hpp:40
std::reverse_iterator< const_iterator > const_reverse_iterator
Reverse order param const iterator type.
Definition param_table.hpp:70
const_iterator end() const noexcept
Get the iterator after the last param row in the table.
Definition param_table.hpp:166
const_reverse_iterator crend() const noexcept
Get the reverse iterator before the first param row in the table.
Definition param_table.hpp:270
iterator end() noexcept
Get the iterator after the last param row in the table.
Definition param_table.hpp:135
reverse_iterator rend() noexcept
Get the reverse iterator before the first param row in the table.
Definition param_table.hpp:218
reverse_iterator rbegin() noexcept
Get the reverse iterator to the last param row in the table.
Definition param_table.hpp:205
const_reverse_iterator rbegin() const noexcept
Get the reverse iterator to the last param row in the table.
Definition param_table.hpp:231
const_iterator cend() const noexcept
Get the const iterator after the last param row in the table.
Definition param_table.hpp:192
std::pair< paramdef_type &, bool > operator[](row_index_type row) const noexcept
Get a param row from this param table by its row index.
Definition param_table.hpp:90
static constexpr param_index index
The param index of this param table.
Definition param_table.hpp:46
Optional references based on std::optional.
ELDEN RING param defines and enums.
param_index
An enum of all param tables as they appear in order.
Definition param_defines.hpp:56
int32_t row_index_type
Signed 32-bit integers are used to represent param row indices.
Definition param_defines.hpp:22
param_table iterator
A helper structure with param type data.
Definition param_table.hpp:290
static constexpr param_index index
The param index of this param table.
Definition param_table.hpp:301
Def paramdef_type
The paramdefs this param uses.
Definition param_table.hpp:295
A std::optional<std::reference_wrapper<T>> wrapper for lvalue references.
Definition optref.hpp:31