MCPcopy Create free account
hub / github.com/Niko1221/Strata / read_value

Function read_value

engine/src/core/conversation_memory.cpp:161–180  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159};
160
161Value read_value(const fs::path& path) {
162 std::error_code ec;
163 const bool there = fs::exists(path, ec);
164 if (ec) return {Value::bad, 0};
165 if (!there) return {};
166 std::ifstream file(path);
167 if (!file) return {Value::bad, 0};
168 char buf[64];
169 file.read(buf, sizeof buf);
170 if (file.bad()) return {Value::bad, 0};
171 size_t len = (size_t) file.gcount();
172 if (len == sizeof buf) return {Value::bad, 0};
173 while (len > 0 && (buf[len - 1] == '\n' || buf[len - 1] == '\r' || buf[len - 1] == ' ' || buf[len - 1] == '\t')) --len;
174 if (len == 0) return {Value::bad, 0};
175 if (len == 3 && std::string(buf, 3) == "max") return {Value::max, 0};
176 Value v{Value::number, 0};
177 const auto parsed = std::from_chars(buf, buf + len, v.n);
178 if (parsed.ec != std::errc{} || parsed.ptr != buf + len) return {Value::bad, 0};
179 return v;
180}
181
182// The reclaimable file cache of one group, from its memory.stat, in the two forms the guard uses
183// (cache_credit_from_stat in the header has the rules). A memory.stat that is missing gives no credit - not an

Callers 1

scan_levelsFunction · 0.70

Calls 3

existsFunction · 0.50
stringFunction · 0.50
readMethod · 0.45

Tested by

no test coverage detected