-
Notifications
You must be signed in to change notification settings - Fork 5
/
config_easy_api.cpp.mako
181 lines (148 loc) · 7.53 KB
/
config_easy_api.cpp.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
## -*- coding: utf-8 -*-
<%!
import time
%><%
cpp_include_prefix = pb_set.get_custom_variable("cpp_include_prefix", "config/excel/")
config_manager_include = pb_set.get_custom_variable("config_manager_include", "config/excel/config_manager.h")
generated_get_version_loaders = set()
%><%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
//
#include "${cpp_include_prefix}config_easy_api.h"
#include <cstdlib>
#include <cstring>
#include <map>
#include <memory>
#include <vector>
#include "${config_manager_include}"
${pb_loader.CppNamespaceBegin(global_package)}
EXCEL_CONFIG_LOADER_API const excel_config_type_traits::shared_ptr<config_group_t>& get_current_config_group() noexcept {
return config_manager::me()->get_current_config_group();
}
EXCEL_CONFIG_LOADER_API const std::string& get_config_group_version(const excel_config_type_traits::shared_ptr<config_group_t>& group) noexcept {
if (!group) {
static std::string empty;
return empty;
}
return group->version;
}
EXCEL_CONFIG_LOADER_API const std::string& get_config_group_version() noexcept {
return get_config_group_version(get_current_config_group());
}
% for pb_msg in pb_set.generate_message:
% for loader in pb_msg.loaders:
// ======================================== ${loader.code.class_name} ========================================
% for code_index in loader.code.indexes:
<%
current_code_proto_ptr_type = 'excel_config_type_traits::shared_ptr<const ' + loader.get_pb_inner_class_name() + '>'
if code_index.is_list():
current_code_item_value_type = 'excel_config_type_traits::shared_ptr<const std::vector<' + current_code_proto_ptr_type + ' > >'
else:
current_code_item_value_type = current_code_proto_ptr_type
if code_index.is_vector():
get_all_of_result = 'const std::vector<' + current_code_item_value_type + '>&'
else:
get_all_of_result = 'const excel_config_type_traits::map_type<\n std::tuple<' + code_index.get_key_type_list() + '>,\n ' + current_code_item_value_type + ' >&'
if loader.code.class_name in generated_get_version_loaders:
generate_get_version_function = False
else:
generate_get_version_function = True
generated_get_version_loaders.add(loader.code.class_name)
%>
% if generate_get_version_function:
EXCEL_CONFIG_LOADER_API std::size_t get_${loader.code.class_name}_version(const excel_config_type_traits::shared_ptr<config_group_t>& group) {
if (!group) {
return 0;
}
return group->${loader.get_cpp_public_var_name()}.get_data_hash_code_verison();
}
EXCEL_CONFIG_LOADER_API std::size_t get_${loader.code.class_name}_version() {
return get_${loader.code.class_name}_version(config_manager::me()->get_current_config_group());
}
% endif
EXCEL_CONFIG_LOADER_API ${get_all_of_result}
get_${loader.code.class_name}_all_of_${code_index.name}(const excel_config_type_traits::shared_ptr<config_group_t>& group) {
static ${pb_loader.CppFullPath(global_package)}${loader.get_cpp_class_full_name()}::${code_index.name}_container_type empty;
if (!group) {
return empty;
}
return group->${loader.get_cpp_public_var_name()}.get_all_of_${code_index.name}();
}
EXCEL_CONFIG_LOADER_API ${get_all_of_result}
get_${loader.code.class_name}_all_of_${code_index.name}() {
return get_${loader.code.class_name}_all_of_${code_index.name}(config_manager::me()->get_current_config_group());
}
% if code_index.is_list():
EXCEL_CONFIG_LOADER_API ${current_code_item_value_type}
get_${loader.code.class_name}_by_${code_index.name}(const excel_config_type_traits::shared_ptr<config_group_t>& group, ${code_index.get_key_decl()}) {
if (!group) {
return nullptr;
}
return group->${loader.get_cpp_public_var_name()}.get_list_by_${code_index.name}(${code_index.get_key_params()});
}
EXCEL_CONFIG_LOADER_API ${current_code_item_value_type}
get_${loader.code.class_name}_by_${code_index.name}(${code_index.get_key_decl()}) {
return get_${loader.code.class_name}_by_${code_index.name}(config_manager::me()->get_current_config_group(), ${code_index.get_key_params()});
}
EXCEL_CONFIG_LOADER_API std::size_t count_${loader.code.class_name}_in_${code_index.name}(
const excel_config_type_traits::shared_ptr<config_group_t>& group, ${code_index.get_key_decl()}) {
if (!group) {
return 0;
}
return group->${loader.get_cpp_public_var_name()}.get_sizeof_${code_index.name}(${code_index.get_key_params()});
}
EXCEL_CONFIG_LOADER_API std::size_t count_${loader.code.class_name}_in_${code_index.name}(
${code_index.get_key_decl()}) {
return count_${loader.code.class_name}_in_${code_index.name}(config_manager::me()->get_current_config_group(), ${code_index.get_key_params()});
}
EXCEL_CONFIG_LOADER_API ${current_code_proto_ptr_type}
get_${loader.code.class_name}_by_${code_index.name}(const excel_config_type_traits::shared_ptr<config_group_t>& group, ${code_index.get_key_decl()}, size_t idx) {
if (!group) {
return nullptr;
}
return group->${loader.get_cpp_public_var_name()}.get_by_${code_index.name}(${code_index.get_key_params()}, idx);
}
EXCEL_CONFIG_LOADER_API ${current_code_proto_ptr_type}
get_${loader.code.class_name}_by_${code_index.name}(${code_index.get_key_decl()}, size_t idx) {
return get_${loader.code.class_name}_by_${code_index.name}(config_manager::me()->get_current_config_group(), ${code_index.get_key_params()}, idx);
}
EXCEL_CONFIG_LOADER_API bool contains_${loader.code.class_name}_in_${code_index.name}(
const excel_config_type_traits::shared_ptr<config_group_t>& group, ${code_index.get_key_decl()}, size_t idx) {
if (!group) {
return false;
}
return group->${loader.get_cpp_public_var_name()}.contains_${code_index.name}(${code_index.get_key_params()}, idx);
}
EXCEL_CONFIG_LOADER_API bool contains_${loader.code.class_name}_in_${code_index.name}(
${code_index.get_key_decl()}, size_t idx) {
return contains_${loader.code.class_name}_in_${code_index.name}(config_manager::me()->get_current_config_group(), ${code_index.get_key_params()}, idx);
}
% else:
EXCEL_CONFIG_LOADER_API ${current_code_item_value_type}
get_${loader.code.class_name}_by_${code_index.name}(const excel_config_type_traits::shared_ptr<config_group_t>& group, ${code_index.get_key_decl()}) {
if (!group) {
return nullptr;
}
return group->${loader.get_cpp_public_var_name()}.get_by_${code_index.name}(${code_index.get_key_params()});
}
EXCEL_CONFIG_LOADER_API ${current_code_item_value_type}
get_${loader.code.class_name}_by_${code_index.name}(${code_index.get_key_decl()}) {
return get_${loader.code.class_name}_by_${code_index.name}(config_manager::me()->get_current_config_group(), ${code_index.get_key_params()});
}
EXCEL_CONFIG_LOADER_API bool contains_${loader.code.class_name}_in_${code_index.name}(
const excel_config_type_traits::shared_ptr<config_group_t>& group, ${code_index.get_key_decl()}) {
if (!group) {
return false;
}
return group->${loader.get_cpp_public_var_name()}.contains_${code_index.name}(${code_index.get_key_params()});
}
EXCEL_CONFIG_LOADER_API bool contains_${loader.code.class_name}_in_${code_index.name}(
${code_index.get_key_decl()}) {
return contains_${loader.code.class_name}_in_${code_index.name}(config_manager::me()->get_current_config_group(), ${code_index.get_key_params()});
}
% endif
% endfor
% endfor
% endfor
${pb_loader.CppNamespaceEnd(global_package)} // ${global_package}