Skip to content

Commit e67e7ed

Browse files
committed
Merge branch 'fix_build_errors' of github.com:lefticus/json2cpp into fix_build_errors
2 parents 12696d6 + ad8486f commit e67e7ed

File tree

5 files changed

+30
-39
lines changed

5 files changed

+30
-39
lines changed

include/json2cpp/json2cpp.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ template<typename CharType> struct basic_json
373373
}
374374
}
375375

376-
template<typename Key>[[nodiscard]] constexpr std::size_t count(const Key &key) const
376+
template<typename Key> [[nodiscard]] constexpr std::size_t count(const Key &key) const
377377
{
378378
if (is_object()) {
379379
const auto found = find(key);
@@ -421,7 +421,7 @@ template<typename CharType> struct basic_json
421421
constexpr static basic_json object() { return basic_json{ data_t{ basic_object_t<CharType>{} } }; }
422422
constexpr static basic_json array() { return basic_json{ data_t{ basic_array_t<CharType>{} } }; }
423423

424-
template<typename Type>[[nodiscard]] constexpr auto get() const
424+
template<typename Type> [[nodiscard]] constexpr auto get() const
425425
{
426426
// I don't like this level of implicit conversions in the `get()` function,
427427
// but it's necessary for API compatibility with nlohmann::json

include/json2cpp/json2cpp_adapter.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,23 +494,23 @@ namespace adapters {
494494

495495
bool operator!=(const json2cppJsonArrayValueIterator &other) const { return !(m_itr == other.m_itr); }
496496

497-
// cppcheck-suppress functionConst
497+
// cppcheck-suppress functionConst
498498
const json2cppJsonArrayValueIterator &operator++()
499499
{
500500
++m_itr;
501501

502502
return *this;
503503
}
504504

505-
// cppcheck-suppress functionConst
505+
// cppcheck-suppress functionConst
506506
json2cppJsonArrayValueIterator operator++(int)
507507
{
508508
json2cppJsonArrayValueIterator iterator_pre(m_itr);
509509
++(*this);
510510
return iterator_pre;
511511
}
512512

513-
// cppcheck-suppress functionConst
513+
// cppcheck-suppress functionConst
514514
const json2cppJsonArrayValueIterator &operator--()
515515
{
516516
--m_itr;
@@ -575,23 +575,23 @@ namespace adapters {
575575

576576
bool operator!=(const json2cppJsonObjectMemberIterator &other) const { return !(m_itr == other.m_itr); }
577577

578-
// cppcheck-suppress functionConst
578+
// cppcheck-suppress functionConst
579579
const json2cppJsonObjectMemberIterator &operator++()
580580
{
581581
++m_itr;
582582

583583
return *this;
584584
}
585585

586-
// cppcheck-suppress functionConst
586+
// cppcheck-suppress functionConst
587587
json2cppJsonObjectMemberIterator operator++(int)
588588
{
589589
json2cppJsonObjectMemberIterator iterator_pre(m_itr);
590590
++(*this);
591591
return iterator_pre;
592592
}
593593

594-
// cppcheck-suppress functionConst
594+
// cppcheck-suppress functionConst
595595
const json2cppJsonObjectMemberIterator &operator--()
596596
{
597597
--m_itr;

src/json2cpp.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ SOFTWARE.
2323
*/
2424

2525

26-
2726
#include "json2cpp.hpp"
2827
#include <fstream>
2928

@@ -36,13 +35,12 @@ std::string compile(const nlohmann::json &value, std::size_t &obj_count, std::ve
3635
if (value.is_object()) {
3736
std::vector<std::string> pairs;
3837
for (auto itr = value.begin(); itr != value.end(); ++itr) {
39-
pairs.push_back(fmt::format(
40-
"value_pair_t{{{}, {{{}}}}},", json_string(itr.key()), compile(*itr, obj_count, lines)));
38+
pairs.push_back(
39+
fmt::format("value_pair_t{{{}, {{{}}}}},", json_string(itr.key()), compile(*itr, obj_count, lines)));
4140
}
4241

43-
lines.push_back(fmt::format("inline constexpr std::array<value_pair_t, {}> object_data_{} = {{",
44-
pairs.size(),
45-
current_object_number));
42+
lines.push_back(fmt::format(
43+
"inline constexpr std::array<value_pair_t, {}> object_data_{} = {{", pairs.size(), current_object_number));
4644

4745
std::transform(pairs.begin(), pairs.end(), std::back_inserter(lines), [](const auto &pair) {
4846
return fmt::format(" {}", pair);
@@ -58,9 +56,8 @@ std::string compile(const nlohmann::json &value, std::size_t &obj_count, std::ve
5856
});
5957

6058

61-
lines.push_back(fmt::format("inline constexpr std::array<json, {}> object_data_{} = {{{{",
62-
entries.size(),
63-
current_object_number));
59+
lines.push_back(fmt::format(
60+
"inline constexpr std::array<json, {}> object_data_{} = {{{{", entries.size(), current_object_number));
6461

6562
std::transform(entries.begin(), entries.end(), std::back_inserter(lines), [](const auto &entry) {
6663
return fmt::format(" {}", entry);
@@ -112,8 +109,7 @@ compile_results compile(const std::string_view document_name, const nlohmann::js
112109

113110
results.impl.emplace_back("#include <json2cpp/json2cpp.hpp>");
114111

115-
results.impl.push_back(
116-
fmt::format(R"(
112+
results.impl.push_back(fmt::format(R"(
117113
namespace compiled_json::{}::impl {{
118114
119115
using json = json2cpp::basic_json<char>;
@@ -123,7 +119,8 @@ using array_t=json2cpp::basic_array_t<char>;
123119
using object_t=json2cpp::basic_object_t<char>;
124120
using value_pair_t=json2cpp::basic_value_pair_t<char>;
125121
126-
)", document_name));
122+
)",
123+
document_name));
127124

128125

129126
const auto last_obj_name = compile(json, obj_count, results.impl);
@@ -136,7 +133,8 @@ inline constexpr auto document = json{{{{{}}}}};
136133
137134
#endif
138135
139-
)", last_obj_name));
136+
)",
137+
last_obj_name));
140138

141139

142140
spdlog::info("{} JSON objects processed.", obj_count);
@@ -178,7 +176,10 @@ void write_compilation([[maybe_unused]] std::string_view document_name,
178176

179177
std::ofstream cpp(cpp_name);
180178
cpp << fmt::format("#include \"{}\"\n", impl_name.filename().string());
181-
cpp << fmt::format("namespace compiled_json::{} {{\nconst json2cpp::json &get() {{ return compiled_json::{}::impl::document; }}\n}}\n", document_name, document_name);
179+
cpp << fmt::format(
180+
"namespace compiled_json::{} {{\nconst json2cpp::json &get() {{ return compiled_json::{}::impl::document; }}\n}}\n",
181+
document_name,
182+
document_name);
182183
}
183184

184185
void compile_to(const std::string_view document_name,

src/schema_validator.cpp

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,7 @@ void walk_internal(std::int64_t &int_sum,
163163
}
164164
}
165165

166-
template<typename JSON>
167-
void walk(const JSON &objects)
166+
template<typename JSON> void walk(const JSON &objects)
168167
{
169168
std::int64_t int_sum{};
170169
double double_sum{};
@@ -174,13 +173,7 @@ void walk(const JSON &objects)
174173

175174
spdlog::info("Starting tree walk");
176175

177-
walk_internal(int_sum,
178-
double_sum,
179-
string_sizes,
180-
array_count,
181-
object_count,
182-
objects
183-
);
176+
walk_internal(int_sum, double_sum, string_sizes, array_count, object_count, objects);
184177

185178
spdlog::info("{} {} {} {} {}", int_sum, double_sum, string_sizes, array_count, object_count);
186179
}
@@ -193,9 +186,9 @@ int main(int argc, const char **argv)
193186
true,// show help if requested
194187
"schema_validator 0.0.1 Copyright 2022 Jason Turner");// version string
195188

196-
if (args.at("--walk").asBool()) {
189+
if (args.at("--walk").asBool()) {
197190
if (args.at("--internal").asBool()) {
198-
walk(compiled_json::energyplus_schema::get());
191+
walk(compiled_json::energyplus_schema::get());
199192
} else {
200193
std::filesystem::path schema_file_name = args.at("<schema_file>").asString();
201194
spdlog::info("Creating nlohmann::json object");

test/valijson_tests.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,7 @@ TEST_CASE("Can load a valijson schema")
1919
// Parse JSON schema content using valijson
2020
Schema mySchema;
2121
SchemaParser parser;
22-
json2cppJsonAdapter mySchemaAdapter(
23-
compiled_json::allof_integers_and_numbers_schema::get());
22+
json2cppJsonAdapter mySchemaAdapter(compiled_json::allof_integers_and_numbers_schema::get());
2423
CHECK_NOTHROW(parser.populateSchema(mySchemaAdapter, mySchema));
2524
}
2625

@@ -36,8 +35,7 @@ TEST_CASE("Validation fails where expected")
3635
// Parse JSON schema content using valijson
3736
Schema mySchema;
3837
SchemaParser parser;
39-
json2cppJsonAdapter mySchemaAdapter(
40-
compiled_json::allof_integers_and_numbers_schema::get());
38+
json2cppJsonAdapter mySchemaAdapter(compiled_json::allof_integers_and_numbers_schema::get());
4139
CHECK_NOTHROW(parser.populateSchema(mySchemaAdapter, mySchema));
4240

4341
Validator validator;
@@ -58,8 +56,7 @@ TEST_CASE("Can validate a document")
5856
// Parse JSON schema content using valijson
5957
Schema mySchema;
6058
SchemaParser parser;
61-
json2cppJsonAdapter mySchemaAdapter(
62-
compiled_json::allof_integers_and_numbers_schema::get());
59+
json2cppJsonAdapter mySchemaAdapter(compiled_json::allof_integers_and_numbers_schema::get());
6360
CHECK_NOTHROW(parser.populateSchema(mySchemaAdapter, mySchema));
6461

6562
Validator validator;

0 commit comments

Comments
 (0)