Updated local storage
This commit is contained in:
1 parent
30db44eaa0
commit
2218aed839
10 files changed
+548
-5
No files matched your search
@@ -0,0 +1,46 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
// SPDX-FileCopyrightText: 2026 Martino Ferrari
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace udpscope {
|
||||
|
||||
/// The user-arranged part of a session, persisted per data source in
|
||||
/// `~/.config/udpscope/<host>_<port>.toml`: the display window, the plot layout
|
||||
/// (rows and which signal each of a row's slots holds) and the per-signal
|
||||
/// calibration. Signal names are the stable identity (channel indexes are
|
||||
/// renumbered by every enable/disable, see the model's own invariant).
|
||||
struct LayoutState {
|
||||
struct Row {
|
||||
/// One entry per slot; an empty string is an empty slot.
|
||||
std::vector<std::string> signals;
|
||||
};
|
||||
|
||||
double window_s = 0.0; ///< 0 keeps the default window
|
||||
std::vector<Row> rows;
|
||||
|
||||
struct Calibration {
|
||||
std::string name;
|
||||
double gain = 1.0;
|
||||
double offset = 0.0;
|
||||
};
|
||||
std::vector<Calibration> calibration;
|
||||
};
|
||||
|
||||
/// `~/.config/udpscope/<host>_<port>.toml`, with the directory created.
|
||||
/// Characters unsafe in a filename are replaced in the host part.
|
||||
std::string layout_path(const std::string& host, std::uint16_t port);
|
||||
|
||||
/// Parses the file's TOML subset. Returns false when the file is missing or
|
||||
/// malformed; `out` is left usable either way (a malformed file loads as much as
|
||||
/// parsed, which beats refusing a hand-edited file over one stray character).
|
||||
bool load_layout(const std::string& path, LayoutState& out);
|
||||
|
||||
/// Writes `state` as TOML. Atomic in effect: writes a sibling temp file and
|
||||
/// renames it over the target.
|
||||
bool save_layout(const std::string& path, const LayoutState& state);
|
||||
|
||||
} // namespace udpscope
|
||||
Reference in new issue
Block a user