Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
json_utils.cpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
17#include "shambase/string.hpp"
19#include "shamcomm/logs.hpp"
23#include <nlohmann/json.hpp>
24#include <optional>
25#include <sstream>
26
27namespace shamrock {
28
29 std::string log_json_changes(
30 const nlohmann::json &j_current,
31 const nlohmann::json &j,
32 bool has_used_defaults,
33 bool has_updated_config) {
34
35 int dash_count = 50;
36
37 std::string faint_line = shambase::format(
38 "{}{:-^{}}{}\n",
39 shambase::term_colors::faint(),
40 "", // empty string
41 dash_count, // dynamic width
42 shambase::term_colors::reset());
43
44 auto green = shambase::term_colors::col8b_green();
45 auto reset = shambase::term_colors::reset();
46 auto red = shambase::term_colors::col8b_red();
47
48 std::string newold_text
49 = shambase::format("[{}+ | added{}] [{}- | removed{}]", green, reset, red, reset);
50 std::string nice_plus = shambase::format("{}+{}", green, reset);
51 std::string nice_minus = shambase::format("{}-{}", red, reset);
52
53 std::string log = shambase::format(
54 "Used config parameters are listed below;\n "
55 "Possible cases for highlighted entries:\n "
56 " - ({}) default-added\n "
57 " - ({}/{}) updated \n "
58 " - ({}) ignored values \n "
59 "List of changes: {}\n",
60 nice_plus,
61 nice_plus,
62 nice_minus,
63 nice_minus,
64 newold_text);
65
66 std::stringstream ss;
67 ss << log;
68
69 ss << faint_line;
70 ss << shamrock::json_diff_str(j, j_current);
71 ss << faint_line;
72
73 return ss.str();
74 }
75
76} // namespace shamrock
namespace for the main framework
Definition __init__.py:1
std::string log_json_changes(const nlohmann::json &j_current, const nlohmann::json &j, bool has_used_defaults, bool has_updated_config)
Shown the changes between two JSON objects to log config changes.
Functions related to the MPI communicator.