@@ -40,7 +40,7 @@ std::string compile(const nlohmann::json &value, std::size_t &obj_count, std::ve
4040 " value_pair_t{{{}, {{{}}}}}," , json_string (itr.key ()), compile (*itr, obj_count, lines)));
4141 }
4242
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_{} = {{" ,
4444 pairs.size (),
4545 current_object_number));
4646
@@ -58,7 +58,7 @@ std::string compile(const nlohmann::json &value, std::size_t &obj_count, std::ve
5858 });
5959
6060
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_{} = {{{{" ,
6262 entries.size (),
6363 current_object_number));
6464
@@ -99,7 +99,7 @@ compile_results compile(const std::string_view document_name, const nlohmann::js
9999 results.hpp .emplace_back (" #include <json2cpp/json2cpp.hpp>" );
100100
101101 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));
103103 results.hpp .emplace_back (" }" );
104104
105105 results.hpp .emplace_back (" #endif" );
@@ -112,16 +112,32 @@ compile_results compile(const std::string_view document_name, const nlohmann::js
112112
113113 results.impl .emplace_back (" #include <json2cpp/json2cpp.hpp>" );
114114
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));
116127
117128
118129 const auto last_obj_name = compile (json, obj_count, results.impl );
119130
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));
121140
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" );
125141
126142 spdlog::info (" {} JSON objects processed." , obj_count);
127143
@@ -162,6 +178,7 @@ void write_compilation([[maybe_unused]] std::string_view document_name,
162178
163179 std::ofstream cpp (cpp_name);
164180 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);
165182}
166183
167184void compile_to (const std::string_view document_name,
0 commit comments