47 [[nodiscard]]
auto Size() const -> std::
size_t {
return entries.size(); }
52 std::vector<DiffEntry> result;
53 for (
const auto& entry :
entries) {
54 if (entry.type == type) {
55 result.push_back(entry);
71 [[nodiscard]]
auto ToString() const -> std::
string
74 return "No differences found.\n";
77 std::ostringstream ss;
78 ss <<
"Configuration differences:\n";
80 for (
const auto& entry :
entries) {
81 ss <<
" [" << entry.TypeString() <<
"] " << entry.path;
84 ss <<
" = " << entry.new_value;
87 ss <<
" (was: " << entry.old_value <<
")";
90 ss <<
": " << entry.old_value <<
" -> " << entry.new_value;
108 for (
const auto& [key, value] : target.
Items()) {
109 std::string path = prefix.empty() ? key : prefix +
"." + key;
114 else if (base[key] != value) {
115 if (base[key].IsObject() && value.
IsObject()) {
127 for (
const auto& [key, value] : base.
Items()) {
128 std::string path = prefix.empty() ? key : prefix +
"." + key;
Result of comparing two configurations.
Definition diff.h:39
auto Added() const -> std::vector< DiffEntry >
Returns entries that were added.
Definition diff.h:62
auto Size() const -> std::size_t
Returns the number of differences.
Definition diff.h:47
auto Removed() const -> std::vector< DiffEntry >
Returns entries that were removed.
Definition diff.h:65
auto HasDifferences() const -> bool
Checks if there are any differences.
Definition diff.h:44
auto ToString() const -> std::string
Converts the diff to a human-readable string.
Definition diff.h:71
auto Filter(DiffType type) const -> std::vector< DiffEntry >
Filters entries by type.
Definition diff.h:50
std::vector< DiffEntry > entries
Definition diff.h:41
auto Modified() const -> std::vector< DiffEntry >
Returns entries that were modified.
Definition diff.h:68
A self-contained, recursive value type for configuration data.
Definition value.h:26
auto Items() const -> const ObjectType &
Returns const reference to the object entries.
Definition value.h:245
auto Contains(std::string_view key) const -> bool
Checks whether the given key exists in an object value.
Definition value.h:210
auto IsObject() const -> bool
Returns true if this value is an object (key-value map).
Definition value.h:167
auto Dump(int indent=0) const -> std::string
Produces a JSON-like string representation.
Definition value.h:337
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:103
C++20 compile-time type-safe configuration library.
Definition conf.h:13
auto DiffDefaultsFromFile(const Value &defaults, const Value &file_values) -> ConfigDiff
Compares defaults against file configuration.
Definition diff.h:168
DiffType
Type of change detected in a diff.
Definition diff.h:13
auto DiffFileFromDefaults(const Value &defaults, const Value &file_values) -> ConfigDiff
Compares file configuration against defaults.
Definition diff.h:157
auto DiffValues(const Value &base, const Value &target) -> ConfigDiff
Compares two Value configurations and returns the differences.
Definition diff.h:144
Represents a single difference between two configurations.
Definition diff.h:18
std::string new_value
Definition diff.h:22
std::string path
Definition diff.h:20
std::string old_value
Definition diff.h:21
auto TypeString() const -> std::string
Definition diff.h:24
DiffType type
Definition diff.h:19