One user-space repair task per eligible HWE debug-diag / compile-deploy base ID: 320 admitted (C 218, C++ 97, build scripts 5), 1 skipped by the content filter. Each ships a public spec with a check-to-basis table, at least two defects with single-fix fixtures, a symptom-masking fixture and an alternative correct implementation. Claude re-checked all 320: structure, the HWE quality items and trace6 Docker calibration receipts against current digests (320/320 USABLE). Difficulty is unmeasured. Known follow-up: 212 tasks use 120 ad-hoc family names; the next batch maps them to the canonical list. The batch's 1,256-line progress log stays in its factory report and the 36-local branch batch15-hwe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
194 lines
7.9 KiB
C++
194 lines
7.9 KiB
C++
#include "param.h"
|
|
|
|
#include <algorithm>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace param {
|
|
namespace {
|
|
using Entry = std::pair<std::string, Value>;
|
|
using Entries = std::vector<Entry>;
|
|
Entries::iterator locate(Entries& entries, const std::string& name) {
|
|
return std::find_if(entries.begin(), entries.end(), [&](const Entry& item) { return item.first == name; });
|
|
}
|
|
Entries::const_iterator locate(const Entries& entries, const std::string& name) {
|
|
return std::find_if(entries.cbegin(), entries.cend(), [&](const Entry& item) { return item.first == name; });
|
|
}
|
|
}
|
|
|
|
void Store::clear() { values_.clear(); }
|
|
bool Store::declared(const std::string& name) const { return locate(values_, name) != values_.cend(); }
|
|
std::size_t Store::size() const { return values_.size(); }
|
|
Error Store::validate_target(const std::string& name) const {
|
|
if (!find_schema(name)) return Error::Unknown;
|
|
return declared(name) ? Error::None : Error::Undeclared;
|
|
}
|
|
Result Store::declare_one(const std::string& name) {
|
|
auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
if (declared(name)) return {Error::AlreadyDeclared, {}};
|
|
values_.push_back({name, schema->default_value});
|
|
return {Error::None, "declare " + name};
|
|
}
|
|
Result Store::declare_defaults() {
|
|
values_.clear();
|
|
for (auto name : schema_order()) {
|
|
auto result = declare_one(std::string(name));
|
|
if (result.error != Error::None) return result;
|
|
}
|
|
return {Error::None, "boot 4"};
|
|
}
|
|
Result Store::read_with_schema(const std::string& name, const Schema& schema) const {
|
|
auto item = locate(values_, name);
|
|
if (item == values_.cend()) return {Error::Undeclared, {}};
|
|
return {Error::None, name + " " + kind_name(schema.kind) + " " + format_value(item->second)};
|
|
}
|
|
Result Store::get(const std::string& name) const {
|
|
auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
return read_with_schema(name, *schema);
|
|
}
|
|
Result Store::write_one(const std::string& name, const Value& value) {
|
|
auto item = locate(values_, name);
|
|
if (item == values_.end()) return {Error::Undeclared, {}};
|
|
item->second = value;
|
|
return {Error::None, "set " + name};
|
|
}
|
|
Result Store::set(const std::string& name, const std::string& token) {
|
|
auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
if (!declared(name)) return {Error::Undeclared, {}};
|
|
auto value = parse_value(*schema, token);
|
|
if (!value) return {Error::Value, {}};
|
|
return write_one(name, *value);
|
|
}
|
|
Result Store::patch(const std::vector<Assignment>& assignments) {
|
|
if (assignments.empty() || assignments.size() > 8) return {Error::Syntax, {}};
|
|
Entries next = values_;
|
|
for (const auto& assignment : assignments) {
|
|
auto schema = find_schema(assignment.name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
auto item = locate(next, assignment.name);
|
|
if (item == next.end()) return {Error::Undeclared, {}};
|
|
auto value = parse_value(*schema, assignment.token);
|
|
if (!value) return {Error::Value, {}};
|
|
item->second = *value;
|
|
}
|
|
values_.swap(next);
|
|
return {Error::None, "patch " + std::to_string(assignments.size())};
|
|
}
|
|
Result Store::reset(const std::string& name) {
|
|
auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
auto item = locate(values_, name);
|
|
if (item == values_.end()) return {Error::Undeclared, {}};
|
|
item->second = schema->default_value;
|
|
return {Error::None, "reset " + name};
|
|
}
|
|
Result Store::list() const {
|
|
std::string result = "list";
|
|
for (auto name : schema_order()) {
|
|
auto item = locate(values_, std::string(name));
|
|
if (item == values_.cend()) continue;
|
|
result += " " + std::string(name) + ":" + kind_name(item->second.kind) + ":" + format_value(item->second);
|
|
}
|
|
return {Error::None, result};
|
|
}
|
|
Result Store::count() const { return {Error::None, "count " + std::to_string(values_.size())}; }
|
|
Result Store::describe(const std::string& name) const {
|
|
auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
return {Error::None, "describe " + name + " " + kind_name(schema->kind) + " " + format_value(schema->default_value)};
|
|
}
|
|
Result Store::compare(const std::string& name, const std::string& token) const {
|
|
auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
auto item = locate(values_, name);
|
|
if (item == values_.cend()) return {Error::Undeclared, {}};
|
|
auto value = parse_value(*schema, token);
|
|
if (!value) return {Error::Value, {}};
|
|
return {Error::None, std::string("equal ") + (equal_value(item->second, *value) ? "true" : "false")};
|
|
}
|
|
Result Store::changes() const {
|
|
std::string result = "changes";
|
|
for (auto name : schema_order()) {
|
|
auto item = locate(values_, std::string(name));
|
|
if (item == values_.cend()) continue;
|
|
auto schema = find_schema(name);
|
|
if (!equal_value(item->second, schema->default_value)) result += " " + std::string(name) + ":" + format_value(item->second);
|
|
}
|
|
return {Error::None, result};
|
|
}
|
|
Result Store::restore_all() {
|
|
std::size_t changed = 0;
|
|
for (auto& item : values_) {
|
|
auto schema = find_schema(item.first);
|
|
if (!equal_value(item.second, schema->default_value)) ++changed;
|
|
item.second = schema->default_value;
|
|
}
|
|
return {Error::None, "restore " + std::to_string(changed)};
|
|
}
|
|
Result Store::remove(const std::string& name) {
|
|
if (!find_schema(name)) return {Error::Unknown, {}};
|
|
auto item = locate(values_, name);
|
|
if (item == values_.end()) return {Error::Undeclared, {}};
|
|
values_.erase(item);
|
|
return {Error::None, "remove " + name};
|
|
}
|
|
Result Store::remove_all() {
|
|
auto count = values_.size();
|
|
values_.clear();
|
|
return {Error::None, "clear " + std::to_string(count)};
|
|
}
|
|
Result Store::validate(const std::string& name, const std::string& token) const {
|
|
auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
auto value = parse_value(*schema, token);
|
|
if (!value) return {Error::Value, {}};
|
|
return {Error::None, "valid " + name + " " + format_value(*value)};
|
|
}
|
|
Result Store::missing() const {
|
|
std::string result = "missing";
|
|
for (auto name : schema_order()) if (!declared(std::string(name))) result += " " + std::string(name);
|
|
return {Error::None, result};
|
|
}
|
|
Result Store::declared_query(const std::string& name) const {
|
|
if (!find_schema(name)) return {Error::Unknown, {}};
|
|
return {Error::None, "declared " + name + " " + (declared(name) ? "true" : "false")};
|
|
}
|
|
|
|
Result Store::declare_many(const std::vector<std::string>& names) {
|
|
if (names.empty() || names.size() > 4) return {Error::Syntax, {}};
|
|
Entries next = values_;
|
|
for (const auto& name : names) {
|
|
auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
if (locate(next, name) != next.end()) return {Error::AlreadyDeclared, {}};
|
|
next.push_back({name, schema->default_value});
|
|
}
|
|
values_.swap(next);
|
|
return {Error::None, "declare_many " + std::to_string(names.size())};
|
|
}
|
|
Result Store::cas(const std::string& name, const std::string& expected, const std::string& replacement) {
|
|
auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
auto item = locate(values_, name);
|
|
if (item == values_.end()) return {Error::Undeclared, {}};
|
|
auto before = parse_value(*schema, expected);
|
|
auto after = parse_value(*schema, replacement);
|
|
if (!before || !after) return {Error::Value, {}};
|
|
if (!equal_value(item->second, *before)) return {Error::Mismatch, {}};
|
|
item->second = *after;
|
|
return {Error::None, "cas " + name};
|
|
}
|
|
Result Store::defaults() const {
|
|
std::string result = "defaults";
|
|
for (auto name : schema_order()) {
|
|
auto schema = find_schema(name);
|
|
result += " " + std::string(name) + ":" + kind_name(schema->kind) + ":" + format_value(schema->default_value);
|
|
}
|
|
return {Error::None, result};
|
|
}
|
|
}
|