Cut core/model, reclaim, json, util comment bloat ~26% (comments only, zero code change)
This commit is contained in:
@@ -4,21 +4,14 @@
|
||||
|
||||
#include "core/json/json.h"
|
||||
|
||||
// bank_model implementation.
|
||||
//
|
||||
// JSON rides on the shared core/json lexical layer (Q-W1: one reader/writer,
|
||||
// no per-module Parser copy). The field set is a flat struct of primitives,
|
||||
// strings, one enum, a small string array, and a few optionals, so a compact
|
||||
// writer + recursive-descent DOMAIN parser over json::Reader is the simplest
|
||||
// thing that works. Doubles are emitted with 17 significant digits (%.17g), the
|
||||
// shortest form that round-trips every IEEE-754 double exactly, so the
|
||||
// deserialize(serialize(x)) == x invariant holds bit-for-bit.
|
||||
// bank_model implementation. JSON rides on the shared core/json lexical layer;
|
||||
// only the Sample/index DOMAIN grammar lives here. Doubles are emitted with 17
|
||||
// significant digits (%.17g), the shortest form that round-trips every
|
||||
// IEEE-754 double exactly, so deserialize(serialize(x)) == x holds bit-for-bit.
|
||||
|
||||
namespace reasampler::model {
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// equality
|
||||
// ---------------------------------------------------------------------------
|
||||
// -- equality -----------------------------------------------------------
|
||||
|
||||
bool SourceRange::operator==(const SourceRange& o) const {
|
||||
return startSeconds == o.startSeconds && endSeconds == o.endSeconds &&
|
||||
@@ -51,20 +44,15 @@ bool Sample::operator==(const Sample& o) const {
|
||||
provenance == o.provenance && createdTimestamp == o.createdTimestamp;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// path invariant
|
||||
// ---------------------------------------------------------------------------
|
||||
// -- path invariant -------------------------------------------------------
|
||||
|
||||
// DECISION: reject absolute paths rather than normalize them. The pure model has
|
||||
// no knowledge of the project root, so it cannot correctly relativize an absolute
|
||||
// path — any "normalization" would be a guess that could point at the wrong file.
|
||||
// Rejecting at the boundary is honest and deterministic; the capture backend (M3)
|
||||
// is responsible for handing us an already-relative path. Covers POSIX ("/x"),
|
||||
// Windows drive ("C:\x", "C:/x", "C:foo" drive-relative), and UNC ("\\host\share")
|
||||
// forms. Any leading <alpha>: is rejected regardless of the character that follows —
|
||||
// drive-relative paths ("C:foo.wav") resolve against the drive's current directory,
|
||||
// not the project root, so they violate the relative-paths-only invariant just as
|
||||
// much as "C:\foo.wav" does.
|
||||
// Rejects absolute paths rather than normalizing them: the pure model has no
|
||||
// knowledge of the project root, so any "normalization" would be a guess that
|
||||
// could point at the wrong file. Covers POSIX ("/x"), Windows drive ("C:\x",
|
||||
// "C:/x", "C:foo" drive-relative), and UNC ("\\host\share") forms. Any leading
|
||||
// <alpha>: is rejected regardless of what follows — drive-relative paths
|
||||
// ("C:foo.wav") resolve against the drive's current directory, not the project
|
||||
// root, so they violate relative-paths-only just as much as "C:\foo.wav" does.
|
||||
static bool isAbsolutePath(const std::string& p) {
|
||||
if (p.empty()) return false;
|
||||
if (p[0] == '/' || p[0] == '\\') return true; // POSIX root or UNC
|
||||
@@ -73,9 +61,7 @@ static bool isAbsolutePath(const std::string& p) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// BankModel
|
||||
// ---------------------------------------------------------------------------
|
||||
// -- BankModel ------------------------------------------------------------
|
||||
|
||||
AddResult BankModel::add(const Sample& sample) {
|
||||
if (sample.id.empty()) return AddResult::RejectedEmptyId;
|
||||
@@ -139,9 +125,7 @@ std::vector<Sample> BankModel::byTier(Tier tier) const {
|
||||
return out;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// JSON writer
|
||||
// ---------------------------------------------------------------------------
|
||||
// -- JSON writer ------------------------------------------------------------
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -182,9 +166,9 @@ void writeSample(std::string& out, const Sample& s) {
|
||||
w.keyBegin("key");
|
||||
if (s.key) writeEscaped(out, *s.key); else out += "null";
|
||||
|
||||
// Phase S seam fields (D-B). Emitted as null when absent (same shape as `key`
|
||||
// and `provenance`) so pre-Phase-S JSON — which lacks these keys entirely —
|
||||
// parses to empty optionals and re-serializes without invention.
|
||||
// Emitted as null when absent (same shape as `key`/`provenance`) so JSON that
|
||||
// lacks these keys entirely parses to empty optionals and re-serializes
|
||||
// without invention.
|
||||
w.keyBegin("rootNote");
|
||||
if (s.rootNote) out += numToStr(*s.rootNote); else out += "null";
|
||||
|
||||
@@ -240,12 +224,9 @@ std::string BankModel::serialize() const {
|
||||
return out;
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
// JSON parser (recursive descent over the shared json::Reader). Returns false
|
||||
// on any malformed input; never reads out of bounds. Only supports the subset
|
||||
// our writer emits. The lexical layer (strings, numbers, skip) lives in
|
||||
// core/json; only the Sample/index DOMAIN grammar lives here.
|
||||
// ---------------------------------------------------------------------------
|
||||
// -- JSON parser (recursive descent over the shared json::Reader) -----------
|
||||
// Returns false on any malformed input; never reads out of bounds. Only
|
||||
// supports the subset our writer emits.
|
||||
|
||||
namespace {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user