@@ -40,7 +40,7 @@ std::string compile(const nlohmann::json &value, std::size_t &obj_count, std::ve
40
40
" value_pair_t{{{}, {{{}}}}}," , json_string (itr.key ()), compile (*itr, obj_count, lines)));
41
41
}
42
42
43
- lines.push_back (fmt::format (" static constexpr std::array<value_pair_t, {}> object_data_{} = {{" ,
43
+ lines.push_back (fmt::format (" inline constexpr std::array<value_pair_t, {}> object_data_{} = {{" ,
44
44
pairs.size (),
45
45
current_object_number));
46
46
@@ -58,7 +58,7 @@ std::string compile(const nlohmann::json &value, std::size_t &obj_count, std::ve
58
58
});
59
59
60
60
61
- lines.push_back (fmt::format (" static constexpr std::array<json, {}> object_data_{} = {{{{" ,
61
+ lines.push_back (fmt::format (" inline constexpr std::array<json, {}> object_data_{} = {{{{" ,
62
62
entries.size (),
63
63
current_object_number));
64
64
@@ -99,7 +99,7 @@ compile_results compile(const std::string_view document_name, const nlohmann::js
99
99
results.hpp .emplace_back (" #include <json2cpp/json2cpp.hpp>" );
100
100
101
101
results.hpp .push_back (fmt::format (" namespace compiled_json::{} {{" , document_name));
102
- results.hpp .push_back (fmt::format (" const json2cpp::json &get_{} ();" , document_name));
102
+ results.hpp .push_back (fmt::format (" const json2cpp::json &get ();" , document_name));
103
103
results.hpp .emplace_back (" }" );
104
104
105
105
results.hpp .emplace_back (" #endif" );
@@ -112,16 +112,32 @@ compile_results compile(const std::string_view document_name, const nlohmann::js
112
112
113
113
results.impl .emplace_back (" #include <json2cpp/json2cpp.hpp>" );
114
114
115
- results.impl .push_back (fmt::format (" namespace compiled_json::{} {{\n using json = json2cpp::basic_json<char>;\n using data_t=json2cpp::data_variant<char>;\n using string_view=std::basic_string_view<char>;\n using array_t=json2cpp::basic_array_t<char>;\n using object_t=json2cpp::basic_object_t<char>;\n using value_pair_t=json2cpp::basic_value_pair_t<char>;\n " , document_name));
115
+ results.impl .push_back (
116
+ fmt::format (R"(
117
+ namespace compiled_json::{}::impl {{
118
+
119
+ using json = json2cpp::basic_json<char>;
120
+ using data_t=json2cpp::data_variant<char>;
121
+ using string_view=std::basic_string_view<char>;
122
+ using array_t=json2cpp::basic_array_t<char>;
123
+ using object_t=json2cpp::basic_object_t<char>;
124
+ using value_pair_t=json2cpp::basic_value_pair_t<char>;
125
+
126
+ )" , document_name));
116
127
117
128
118
129
const auto last_obj_name = compile (json, obj_count, results.impl );
119
130
120
- results.impl .push_back (fmt::format (" static constexpr auto document = json{{{{{}}}}};" , last_obj_name));
131
+ results.impl .push_back (fmt::format (R"(
132
+ inline constexpr auto document = json{{{{{}}}}};
133
+
134
+
135
+ }}
136
+
137
+ #endif
138
+
139
+ )" , last_obj_name));
121
140
122
- results.impl .push_back (fmt::format (" const json2cpp::json &get_{}() {{ return document; }}" , document_name));
123
- results.impl .emplace_back (" }" );
124
- results.impl .emplace_back (" #endif" );
125
141
126
142
spdlog::info (" {} JSON objects processed." , obj_count);
127
143
@@ -162,6 +178,7 @@ void write_compilation([[maybe_unused]] std::string_view document_name,
162
178
163
179
std::ofstream cpp (cpp_name);
164
180
cpp << fmt::format (" #include \" {}\"\n " , impl_name.filename ().string ());
181
+ cpp << fmt::format (" namespace compiled_json::{} {{\n const json2cpp::json &get() {{ return compiled_json::{}::impl::document; }}\n }}\n " , document_name, document_name);
165
182
}
166
183
167
184
void compile_to (const std::string_view document_name,
0 commit comments