amos 8b7616bfd8 Batch 22 (20261027-C-hwe-hard-22): add 63 calibrated HWE hard-design tasks
From the 101 lk/man/pth code-gen sources: 63 tasks (C11 36, C++17 27,
11 canonical families), 38 skipped for scope or duplication. Each task
has at least one independent contract-edge defect, boundary types
rotate, and public docs state trap clauses as plain contract prose.
Claude reviewed 63/63 USABLE against current digests. Difficulty is
unmeasured.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 16:14:57 +08:00

80 lines
2.1 KiB
C++

#ifndef ATTRIBUTE_HPP
#define ATTRIBUTE_HPP
#include <cstddef>
#include <cstdint>
#include <functional>
#include <string>
#include <vector>
namespace attr {
constexpr int invalid = -22;
constexpr int missing = -2;
constexpr int duplicate = -17;
constexpr int full = -28;
constexpr int denied = -13;
constexpr int range = -34;
constexpr int busy = -16;
constexpr int slot_count = 8;
constexpr int watch_count = 16;
struct Snapshot {
int32_t value;
uint64_t epoch;
uint64_t generation;
int32_t minimum;
int32_t maximum;
bool writable;
};
struct Notice {
int slot;
int64_t token;
uint64_t epoch;
uint64_t generation;
};
using Callback = std::function<void(const Notice&)>;
int parse_value(const std::string& bytes, int32_t& output);
int format_value(int32_t value, char* output, size_t capacity);
bool valid_name(const std::string& name);
class Service {
public:
Service();
int create(int slot, const std::string& name, int32_t minimum,
int32_t maximum, int32_t initial, bool writable);
int drop(int slot);
int lookup(const std::string& name) const;
int snapshot(int slot, Snapshot& output) const;
int show(int slot, char* output, size_t capacity) const;
int store(int slot, const std::string& bytes);
int64_t watch(int slot, Callback callback);
int cancel(int64_t token);
size_t active_count() const;
size_t watcher_count() const;
private:
struct Attribute {
bool active = false;
std::string name;
int32_t minimum = 0;
int32_t maximum = 0;
int32_t value = 0;
uint64_t epoch = 0;
uint64_t generation = 0;
bool writable = false;
};
struct Observer {
int slot;
int64_t token;
uint64_t generation;
Callback callback;
bool active;
};
std::vector<Attribute> attributes_;
std::vector<Observer> observers_;
int64_t next_token_;
bool notifying_;
bool slot_valid(int slot) const;
int readable(int slot) const;
Observer* observer(int64_t token);
void compact();
void notify(int slot, uint64_t epoch);
};
}
#endif