OSDN Git Service

Merge pull request #2498 from sikabane-works/release/3.0.0Alpha59
[hengbandforosx/hengbandosx.git] / src / info-reader / info-reader-util.h
1 #pragma once
2
3 #include "system/angband.h"
4 #include "util/bit-flags-calculator.h"
5 #include <string>
6 #include <string_view>
7 #include <unordered_map>
8
9 /*
10  * Size of memory reserved for initialization of some arrays
11  */
12 extern int error_idx; //!< エラーが発生したinfo ID
13 extern int error_line; //!< エラーが発生した行
14
15 enum class RandomArtActType : short;
16 RandomArtActType grab_one_activation_flag(concptr what);
17
18 #ifndef JP
19 void append_english_text(std::string &text, std::string_view add);
20 #endif
21
22 /*!
23  * @brief infoフラグ文字列をフラグビットに変換する
24  * @param flags ビットフラグ変数
25  * @param names フラグ文字列変換表
26  * @param what フラグ文字列
27  * @return 見つけたらtrue
28  */
29 template <typename T>
30 bool info_grab_one_flag(uint32_t &flags, const std::unordered_map<std::string_view, T> &names, std::string_view what)
31 {
32     if (auto it = names.find(what); it != names.end()) {
33         set_bits(flags, it->second);
34         return true;
35     }
36     return false;
37 }
38
39 /*!
40  * @brief infoパラメータに値をセットする
41  * @param パラメータ変数
42  * @val 値
43  */
44 template <typename T>
45 void info_set_value(T &arg, const std::string &val, int base = 10)
46 {
47     arg = static_cast<T>(std::stoi(val, nullptr, base));
48 }