OSDN Git Service

Merge pull request #716 from sikabane-works/release/3.0.0Alpha16
[hengbandforosx/hengbandosx.git] / src / main-win / main-win-cfg-reader.h
1 #pragma once
2
3 #include "system/h-type.h"
4
5 #include <cstddef>
6 #include <vector>
7 #include <map>
8 #include <initializer_list>
9
10 typedef uint cfg_key;
11 using cfg_values = std::vector<concptr>;
12 using cfg_map = std::unordered_map<cfg_key, cfg_values *>;
13 using key_name_func = concptr (*)(int, char *);
14
15 /*!
16  * @brief .cfgファイルの読み取り対象とCfgData格納先のキー指定
17  * @details
18  * "term_xtra()"の第1引数(action-type)、第2引数(action-val)をデータの格納キーとする。
19  * action-typeはaction_typeメンバで指定する。
20  * key_name_funcにより、action-valと.cfg内の読取対象キーの対応を取る。
21  * key_name_funcの引数にaction-valが渡され、対応する読取対象キーを返す。
22  * key_name_func引数のaction-valは0から1,2,3...と順に呼ばれ、key_name_funcがNULLを返すまで続ける。
23  */
24 struct cfg_section {
25
26     //! The name of the section in cfg file
27     concptr section_name;
28     //! the "actions" value of "term_xtra()". see:z-term.h TERM_XTRA_xxxxx
29     int action_type;
30     /*!
31      * Returns a reference to the name of the key at a specified action-val* in the section.
32      * *action-val : the 2nd parameter of "term_xtra()"
33      */
34     key_name_func key_at;
35 };
36
37 class CfgData {
38 public:
39     CfgData()
40     {
41         map = new cfg_map();
42     }
43     virtual ~CfgData()
44     {
45         delete map;
46     }
47     concptr get_rand(int key1_type, int key2_val);
48     void insert(int key1_type, int key2_val, cfg_values *value);
49
50 protected:
51     cfg_map *map;
52 };
53
54 class CfgReader {
55 public:
56     CfgReader(concptr dir, std::initializer_list<concptr> files);
57     CfgData *read_sections(std::initializer_list<cfg_section> sections);
58     concptr get_cfg_path()
59     {
60         return cfg_path.c_str();
61     }
62
63 protected:
64     concptr dir;
65     std::string cfg_path;
66 };