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>
249 lines
8.8 KiB
C++
249 lines
8.8 KiB
C++
#include "param.h"
|
|
|
|
#include <algorithm>
|
|
#include <map>
|
|
#include <string>
|
|
#include <utility>
|
|
#include <vector>
|
|
|
|
namespace param {
|
|
|
|
void Store::clear() {
|
|
values_.clear();
|
|
}
|
|
|
|
bool Store::declared(const std::string& name) const {
|
|
return values_.find(name) != values_.end();
|
|
}
|
|
|
|
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;
|
|
if (!declared(name)) return Error::Undeclared;
|
|
return Error::None;
|
|
}
|
|
|
|
Result Store::declare_one(const std::string& name) {
|
|
const auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
if (declared(name)) return {Error::AlreadyDeclared, {}};
|
|
values_.emplace(name, schema->default_value);
|
|
return {Error::None, "declare " + name};
|
|
}
|
|
|
|
Result Store::declare_defaults() {
|
|
clear();
|
|
for (const auto name : schema_order()) {
|
|
const Result 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 {
|
|
const auto position = values_.find(name);
|
|
if (position == values_.end()) return {Error::Undeclared, {}};
|
|
if (position->second.kind != schema.kind) return {Error::Value, {}};
|
|
return {Error::None, name + " " + kind_name(schema.kind) + " " + format_value(position->second)};
|
|
}
|
|
|
|
Result Store::get(const std::string& name) const {
|
|
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 position = values_.find(name);
|
|
if (position == values_.end()) return {Error::Undeclared, {}};
|
|
if (position->second.kind != value.kind) return {Error::Value, {}};
|
|
position->second = value;
|
|
return {Error::None, "set " + name};
|
|
}
|
|
|
|
Result Store::set(const std::string& name, const std::string& token) {
|
|
const auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
if (!declared(name)) return {Error::Undeclared, {}};
|
|
const auto parsed = parse_value(*schema, token);
|
|
if (!parsed) return {Error::Value, {}};
|
|
return write_one(name, *parsed);
|
|
}
|
|
|
|
Result Store::patch(const std::vector<Assignment>& assignments) {
|
|
if (assignments.empty() || assignments.size() > 8) return {Error::Syntax, {}};
|
|
std::vector<std::pair<std::string, Value>> staged;
|
|
staged.reserve(assignments.size());
|
|
for (const Assignment& assignment : assignments) {
|
|
const auto schema = find_schema(assignment.name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
if (!declared(assignment.name)) return {Error::Undeclared, {}};
|
|
const auto parsed = parse_value(*schema, assignment.token);
|
|
if (!parsed) return {Error::Value, {}};
|
|
staged.emplace_back(assignment.name, *parsed);
|
|
}
|
|
for (const auto& item : staged) {
|
|
const Result result = write_one(item.first, item.second);
|
|
if (result.error != Error::None) return result;
|
|
}
|
|
return {Error::None, "patch " + std::to_string(assignments.size())};
|
|
}
|
|
|
|
Result Store::reset(const std::string& name) {
|
|
const auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
if (!declared(name)) return {Error::Undeclared, {}};
|
|
values_[name] = schema->default_value;
|
|
return {Error::None, "reset " + name};
|
|
}
|
|
|
|
Result Store::list() const {
|
|
std::string payload = "list";
|
|
for (const auto name : schema_order()) {
|
|
const auto position = values_.find(std::string(name));
|
|
if (position == values_.end()) continue;
|
|
payload += " ";
|
|
payload += name;
|
|
payload += ":";
|
|
payload += kind_name(position->second.kind);
|
|
payload += ":";
|
|
payload += format_value(position->second);
|
|
}
|
|
return {Error::None, payload};
|
|
}
|
|
|
|
Result Store::count() const {
|
|
return {Error::None, "count " + std::to_string(size())};
|
|
}
|
|
|
|
Result Store::describe(const std::string& name) const {
|
|
const auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
return {Error::None, "describe " + schema->name + " " + kind_name(schema->kind) +
|
|
" " + format_value(schema->default_value)};
|
|
}
|
|
|
|
Result Store::compare(const std::string& name, const std::string& token) const {
|
|
const auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
const auto position = values_.find(name);
|
|
if (position == values_.end()) return {Error::Undeclared, {}};
|
|
const auto parsed = parse_value(*schema, token);
|
|
if (!parsed) return {Error::Value, {}};
|
|
const bool equal = equal_value(position->second, *parsed);
|
|
return {Error::None, std::string("equal ") + (equal ? "true" : "false")};
|
|
}
|
|
|
|
Result Store::changes() const {
|
|
std::string payload = "changes";
|
|
for (const auto name : schema_order()) {
|
|
const auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
const auto position = values_.find(std::string(name));
|
|
if (position == values_.end()) continue;
|
|
if (equal_value(position->second, schema->default_value)) continue;
|
|
payload += " ";
|
|
payload += name;
|
|
payload += ":";
|
|
payload += format_value(position->second);
|
|
}
|
|
return {Error::None, payload};
|
|
}
|
|
|
|
Result Store::restore_all() {
|
|
std::size_t restored = 0;
|
|
for (const auto name : schema_order()) {
|
|
const auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
auto position = values_.find(std::string(name));
|
|
if (position == values_.end()) continue;
|
|
if (!equal_value(position->second, schema->default_value)) ++restored;
|
|
position->second = schema->default_value;
|
|
}
|
|
return {Error::None, "restore " + std::to_string(restored)};
|
|
}
|
|
|
|
Result Store::remove(const std::string& name) {
|
|
if (!find_schema(name)) return {Error::Unknown, {}};
|
|
const auto position = values_.find(name);
|
|
if (position == values_.end()) return {Error::Undeclared, {}};
|
|
values_.erase(position);
|
|
return {Error::None, "remove " + name};
|
|
}
|
|
|
|
Result Store::remove_all() {
|
|
const std::size_t removed = values_.size();
|
|
values_.clear();
|
|
return {Error::None, "clear " + std::to_string(removed)};
|
|
}
|
|
|
|
Result Store::validate(const std::string& name, const std::string& token) const {
|
|
const auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
const auto parsed = parse_value(*schema, token);
|
|
if (!parsed) return {Error::Value, {}};
|
|
return {Error::None, "valid " + name + " " + format_value(*parsed)};
|
|
}
|
|
|
|
Result Store::missing() const {
|
|
std::string payload = "missing";
|
|
for (const auto name : schema_order()) {
|
|
if (declared(std::string(name))) continue;
|
|
payload += " ";
|
|
payload += name;
|
|
}
|
|
return {Error::None, payload};
|
|
}
|
|
|
|
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, {}};
|
|
std::map<std::string, Value> next = values_;
|
|
for (const auto& name : names) {
|
|
const auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
if (next.find(name) != next.end()) return {Error::AlreadyDeclared, {}};
|
|
next.emplace(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) {
|
|
const auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
const auto position = values_.find(name);
|
|
if (position == values_.end()) return {Error::Undeclared, {}};
|
|
const auto before = parse_value(*schema, expected);
|
|
const auto after = parse_value(*schema, replacement);
|
|
if (!before || !after) return {Error::Value, {}};
|
|
if (!equal_value(position->second, *before)) return {Error::Mismatch, {}};
|
|
const Result written = write_one(name, *after);
|
|
if (written.error != Error::None) return written;
|
|
return {Error::None, "cas " + name};
|
|
}
|
|
|
|
Result Store::defaults() const {
|
|
std::string payload = "defaults";
|
|
for (const auto name : schema_order()) {
|
|
const auto schema = find_schema(name);
|
|
if (!schema) return {Error::Unknown, {}};
|
|
payload += " ";
|
|
payload += name;
|
|
payload += ":";
|
|
payload += kind_name(schema->kind);
|
|
payload += ":";
|
|
payload += format_value(schema->default_value);
|
|
}
|
|
return {Error::None, payload};
|
|
}
|
|
|
|
} // namespace param
|