-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathconfig_set.h.mako
217 lines (184 loc) · 7.54 KB
/
config_set.h.mako
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
## -*- coding: utf-8 -*-
<%!
import time
%><%
cpp_include_prefix = pb_set.get_custom_variable("cpp_include_prefix", "config/excel/")
xresloader_include_prefix = pb_set.get_custom_variable("xresloader_include_prefix", pb_set.pb_include_prefix)
%><%namespace name="pb_loader" module="pb_loader"/>
// Copyright ${time.strftime("%Y")} xresloader. All rights reserved.
// Generated by xres-code-generator, please don't edit it
//
#pragma once
#include <stdint.h>
#include <cstddef>
#include <functional>
#include <vector>
#include <string>
#include <map>
#include <unordered_map>
#include <memory>
#include <cstring>
#include <list>
% for block_file in pb_set.get_custom_blocks("custom_config_include"):
// include custom_config_include: ${block_file}
<%include file="${block_file}" />
% endfor
#include "${cpp_include_prefix}config_traits.h"
#include "${cpp_include_prefix}spin_rw_lock.h"
#ifndef EXCEL_CONFIG_LOADER_API
# define EXCEL_CONFIG_LOADER_API
#endif
#if defined(_MSC_VER)
# pragma warning(push)
# if ((defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201703L))
# pragma warning(disable : 4996)
# pragma warning(disable : 4309)
# if _MSC_VER >= 1922
# pragma warning(disable : 5054)
# endif
# endif
# pragma warning(disable : 4100)
# pragma warning(disable : 4244)
# pragma warning(disable : 4251)
# pragma warning(disable : 4267)
# pragma warning(disable : 4668)
# pragma warning(disable : 4715)
# pragma warning(disable : 4800)
# pragma warning(disable : 4946)
# pragma warning(disable : 6001)
# pragma warning(disable : 6244)
# pragma warning(disable : 6246)
# ifndef WIN32_LEAN_AND_MEAN
# define WIN32_LEAN_AND_MEAN
# endif
# include <Windows.h>
#endif
#ifdef max
#undef max
#endif
#ifdef min
#undef min
#endif
#if defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
# if (__GNUC__ * 100 + __GNUC_MINOR__ * 10) >= 460
# pragma GCC diagnostic push
# endif
# pragma GCC diagnostic ignored "-Wunused-parameter"
# pragma GCC diagnostic ignored "-Wtype-limits"
# pragma GCC diagnostic ignored "-Wsign-compare"
# pragma GCC diagnostic ignored "-Wsign-conversion"
# pragma GCC diagnostic ignored "-Wshadow"
# pragma GCC diagnostic ignored "-Wuninitialized"
# pragma GCC diagnostic ignored "-Wconversion"
# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 409
# pragma GCC diagnostic ignored "-Wfloat-conversion"
# endif
# if (__GNUC__ * 100 + __GNUC_MINOR__) >= 501
# pragma GCC diagnostic ignored "-Wsuggest-override"
# endif
#elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunused-parameter"
# pragma clang diagnostic ignored "-Wtype-limits"
# pragma clang diagnostic ignored "-Wsign-compare"
# pragma clang diagnostic ignored "-Wsign-conversion"
# pragma clang diagnostic ignored "-Wshadow"
# pragma clang diagnostic ignored "-Wuninitialized"
# pragma clang diagnostic ignored "-Wconversion"
# if ((__clang_major__ * 100) + __clang_minor__) >= 305
# pragma clang diagnostic ignored "-Wfloat-conversion"
# endif
# if ((__clang_major__ * 100) + __clang_minor__) >= 306
# pragma clang diagnostic ignored "-Winconsistent-missing-override"
# endif
# if ((__clang_major__ * 100) + __clang_minor__) >= 1100
# pragma clang diagnostic ignored "-Wsuggest-override"
# endif
#endif
#include <${pb_set.pb_include_prefix}${loader.get_pb_header_path()}>
#include <${xresloader_include_prefix}pb_header_v3.pb.h>
#if defined(__GNUC__) && !defined(__clang__) && !defined(__apple_build_version__)
# if (__GNUC__ * 100 + __GNUC_MINOR__ * 10) >= 460
# pragma GCC diagnostic pop
# endif
#elif defined(__clang__) || defined(__apple_build_version__)
# pragma clang diagnostic pop
#endif
#if defined(_MSC_VER)
# pragma warning(pop)
#endif
#ifndef EXCEL_CONFIG_LOADER_API
# define EXCEL_CONFIG_LOADER_API
#endif
${pb_loader.CppNamespaceBegin(global_package)}
#ifndef EXCEL_CONFIG_LOADER_TRAITS
# define EXCEL_CONFIG_LOADER_TRAITS
using excel_config_type_traits = ::excel::traits::config_traits<::excel::traits::type_guard>;
#endif
${loader.get_cpp_namespace_decl_begin()}
class ${loader.get_cpp_class_name()} {
public:
using item_type = const ${loader.get_pb_inner_class_name()};
using proto_type = ${loader.get_pb_inner_class_name()};
using item_ptr_type = excel_config_type_traits::shared_ptr<item_type>;
public:
EXCEL_CONFIG_LOADER_API ${loader.get_cpp_class_name()}();
EXCEL_CONFIG_LOADER_API ~${loader.get_cpp_class_name()}();
EXCEL_CONFIG_LOADER_API int on_inited(bool enable_multithread_lock);
EXCEL_CONFIG_LOADER_API int load_all();
EXCEL_CONFIG_LOADER_API void clear();
EXCEL_CONFIG_LOADER_API const std::list<org::xresloader::pb::xresloader_data_source>& get_data_source() const;
EXCEL_CONFIG_LOADER_API std::size_t get_data_hash_code_verison() const noexcept;
EXCEL_CONFIG_LOADER_API const std::vector<item_ptr_type>& get_all_data() const noexcept;
private:
int load_file(const std::string& file_path);
int load_list(const char*);
int reload_file_lists();
void merge_data(item_ptr_type);
private:
::excel::lock::spin_rw_lock load_file_lock_;
std::unordered_map<std::string, bool> file_status_; // true: already loaded
std::list<org::xresloader::pb::xresloader_data_source> datasource_;
bool all_loaded_;
bool enable_multithread_lock_;
std::size_t hash_code_verison_;
std::vector<item_ptr_type> all_data_;
% for code_index in loader.code.indexes:
// ------------------------- index: ${code_index.name} -------------------------
public:
% if code_index.is_list():
using ${code_index.name}_value_type = excel_config_type_traits::shared_ptr<const std::vector<item_ptr_type> >;
EXCEL_CONFIG_LOADER_API ${code_index.name}_value_type
get_list_by_${code_index.name}(${code_index.get_key_decl()});
EXCEL_CONFIG_LOADER_API item_ptr_type get_by_${code_index.name}(${code_index.get_key_decl()}, size_t index);
EXCEL_CONFIG_LOADER_API bool contains_${code_index.name}(${code_index.get_key_decl()}, size_t index);
EXCEL_CONFIG_LOADER_API std::size_t get_sizeof_${code_index.name}(${code_index.get_key_decl()});
private:
${code_index.name}_value_type _get_list_by_${code_index.name}(${code_index.get_key_decl()}, bool ignore_not_found);
public:
% else:
using ${code_index.name}_value_type = item_ptr_type;
EXCEL_CONFIG_LOADER_API ${code_index.name}_value_type get_by_${code_index.name}(${code_index.get_key_decl()});
EXCEL_CONFIG_LOADER_API bool contains_${code_index.name}(${code_index.get_key_decl()});
private:
${code_index.name}_value_type _get_by_${code_index.name}(${code_index.get_key_decl()}, bool ignore_not_found);
public:
% endif
% if code_index.is_vector():
using ${code_index.name}_container_type = excel_config_type_traits::shared_ptr<const std::vector<${code_index.name}_value_type> >;
% else:
using ${code_index.name}_container_type = excel_config_type_traits::map_type<
std::tuple<${code_index.get_key_type_list()}>,
${code_index.name}_value_type>;
% endif
EXCEL_CONFIG_LOADER_API const ${code_index.name}_container_type& get_all_of_${code_index.name}() const;
private:
% if code_index.is_vector():
${code_index.name}_container_type ${code_index.name}_data_;
% else:
${code_index.name}_container_type ${code_index.name}_data_;
% endif
% endfor
};
${loader.get_cpp_namespace_decl_end()}
${pb_loader.CppNamespaceEnd(global_package)} // ${global_package}