48 [[nodiscard]]
auto Size() const -> std::
size_t {
return entries.size(); }
53 std::vector<DiffEntry> result;
54 for (
const auto& entry :
entries) {
55 if (entry.type == type) {
56 result.push_back(entry);
72 [[nodiscard]]
auto ToString() const -> std::
string
75 return "No differences found.\n";
78 std::ostringstream ss;
79 ss <<
"Configuration differences:\n";
81 for (
const auto& entry :
entries) {
82 ss <<
" [" << entry.TypeString() <<
"] " << entry.path;
85 ss <<
" = " << entry.new_value;
88 ss <<
" (was: " << entry.old_value <<
")";
91 ss <<
": " << entry.old_value <<
" -> " << entry.new_value;
109 for (
const auto& [key, value] : target.
Items()) {
110 std::string path = prefix.empty() ? key : prefix +
"." + key;
115 else if (base[key] != value) {
116 if (base[key].IsObject() && value.
IsObject()) {
128 for (
const auto& [key, value] : base.
Items()) {
129 std::string path = prefix.empty() ? key : prefix +
"." + key;
Result of comparing two configurations.
Definition diff.h:40
auto Added() const -> std::vector< DiffEntry >
Returns entries that were added.
Definition diff.h:63
auto Size() const -> std::size_t
Returns the number of differences.
Definition diff.h:48
auto Removed() const -> std::vector< DiffEntry >
Returns entries that were removed.
Definition diff.h:66
auto HasDifferences() const -> bool
Checks if there are any differences.
Definition diff.h:45
auto ToString() const -> std::string
Converts the diff to a human-readable string.
Definition diff.h:72
auto Filter(DiffType type) const -> std::vector< DiffEntry >
Filters entries by type.
Definition diff.h:51
std::vector< DiffEntry > entries
Definition diff.h:42
auto Modified() const -> std::vector< DiffEntry >
Returns entries that were modified.
Definition diff.h:69
A self-contained, recursive value type for configuration data.
Definition value.h:32
auto Items() const -> const ObjectType &
Returns const reference to the object entries.
Definition value.h:368
auto Contains(std::string_view key) const -> bool
Checks whether the given key exists in an object value.
Definition value.h:333
auto IsObject() const -> bool
Returns true if this value is an object (key-value map).
Definition value.h:173
auto Dump(int indent=0) const -> std::string
Produces a JSON-like string representation.
Definition value.h:512
void CompareValueRecursive(const Value &base, const Value &target, const std::string &prefix, ConfigDiff &diff)
Recursively compares two Value objects and collects differences.
Definition diff.h:104
C++20 compile-time type-safe configuration library.
Definition conf.h:17
auto DiffDefaultsFromFile(const Value &defaults, const Value &file_values) -> ConfigDiff
Compares defaults against file configuration.
Definition diff.h:169
DiffType
Type of change detected in a diff.
Definition diff.h:14
auto DiffFileFromDefaults(const Value &defaults, const Value &file_values) -> ConfigDiff
Compares file configuration against defaults.
Definition diff.h:158
auto DiffValues(const Value &base, const Value &target) -> ConfigDiff
Compares two Value configurations and returns the differences.
Definition diff.h:145
Represents a single difference between two configurations.
Definition diff.h:19
std::string new_value
Definition diff.h:23
std::string path
Definition diff.h:21
std::string old_value
Definition diff.h:22
auto TypeString() const -> std::string
Definition diff.h:25
DiffType type
Definition diff.h:20