amos 9d633e9e67 Batch 15 (20261023-C-hwe-scale-15): 320 HWE-derived repair tasks
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>
2026-10-27 01:55:56 +08:00

137 lines
4.7 KiB
C++

#include "timer_adapter.hpp"
#include <charconv>
#include <iostream>
#include <memory>
#include <sstream>
#include <string>
#include <vector>
namespace {
using namespace timerlab;
std::vector<std::string> words(const std::string &line)
{
std::vector<std::string> result;
std::string token;
std::istringstream input(line);
while (input >> token) {
result.push_back(token);
}
return result;
}
bool decimal(const std::string &text, std::int64_t &result)
{
if (text.empty()) {
return false;
}
const char *first = text.data();
const char *last = first + text.size();
const auto parsed = std::from_chars(first, last, result);
return parsed.ec == std::errc{} && parsed.ptr == last;
}
bool arguments(const std::vector<std::string> &tokens,
unsigned size, std::vector<std::int64_t> &values)
{
if (tokens.size() != size + 1) {
return false;
}
values.clear();
for (unsigned index = 1; index < tokens.size(); ++index) {
std::int64_t value = 0;
if (!decimal(tokens[index], value)) {
return false;
}
values.push_back(value);
}
return true;
}
void adapter_view(const TimerAdapter &adapter)
{
const AdapterView v = adapter.view();
std::cout << "S " << v.running << ' ' << v.pending
<< ' ' << v.next_sequence << ' ' << v.callbacks
<< ' ' << v.launched << ' ' << v.skipped
<< ' ' << v.rejected << ' ' << v.succeeded
<< ' ' << v.failed << ' ' << v.timed_out
<< ' ' << v.canceled << '\n';
}
void port_view(const ServicePort &port)
{
const PortView v = port.view();
std::cout << "P " << v.clock << ' ' << v.capacity
<< ' ' << v.live << ' ' << v.busy
<< ' ' << v.created << ' ' << v.destroyed
<< ' ' << v.submitted << ' ' << v.replied
<< ' ' << v.canceled << ' ' << v.exhausted
<< ' ' << v.errors << '\n';
}
void client_view(const ServicePort &port)
{
const auto clients = port.clients();
std::cout << "L " << clients.size() << '\n';
for (const ClientView &client : clients) {
std::cout << client.token << ' ' << client.busy << ' '
<< client.ready << '\n';
}
}
void result_view(const TimerAdapter &adapter)
{
const auto &results = adapter.results();
std::cout << "O " << results.size() << '\n';
for (const Result &r : results) {
std::cout << r.sequence << ' ' << r.payload << ' '
<< r.status << ' ' << r.value << '\n';
}
}
}
int main()
{
std::unique_ptr<ServicePort> port;
std::unique_ptr<TimerAdapter> adapter;
std::string line;
while (std::getline(std::cin, line)) {
const auto tokens = words(line);
if (tokens.empty()) {
continue;
}
std::vector<std::int64_t> a;
const std::string &op = tokens[0];
if (op == "N" && arguments(tokens, 1, a) && a[0] >= 1 && a[0] <= 16) {
adapter.reset();
port = std::make_unique<ServicePort>(static_cast<unsigned>(a[0]));
adapter = std::make_unique<TimerAdapter>(*port);
std::cout << "N 0\n";
continue;
}
if (!adapter) {
return 2;
}
if (op == "B" && arguments(tokens, 3, a) && a[0] >= -10000 && a[0] <= 10000 &&
a[1] >= -10000 && a[1] <= 10000 && a[2] >= -10000 && a[2] <= 10000) {
std::cout << "B " << adapter->start(static_cast<int>(a[0]),
static_cast<int>(a[1]), static_cast<int>(a[2])) << '\n';
} else if (op == "T" && arguments(tokens, 3, a) && a[0] >= -2000000 &&
a[0] <= 2000000 && a[1] >= -10000 && a[1] <= 10000 &&
a[2] >= -10000 && a[2] <= 10000) {
std::cout << "T " << adapter->callback(a[0], static_cast<int>(a[1]),
static_cast<int>(a[2])) << '\n';
} else if (op == "A" && arguments(tokens, 1, a) && a[0] >= 0 && a[0] <= 1000000) {
port->advance(static_cast<Tick>(a[0]));
adapter->collect();
std::cout << "A 0\n";
} else if (op == "X" && arguments(tokens, 0, a)) {
adapter->stop();
std::cout << "X 0\n";
} else if (op == "S" && arguments(tokens, 0, a)) {
adapter_view(*adapter);
} else if (op == "P" && arguments(tokens, 0, a)) {
port_view(*port);
} else if (op == "L" && arguments(tokens, 0, a)) {
client_view(*port);
} else if (op == "O" && arguments(tokens, 0, a)) {
result_view(*adapter);
} else {
return 2;
}
}
return std::cin.bad() ? 2 : 0;
}