Slick Trader 0.11.0
Multi-broker algorithmic trading engine with plugin strategies and a live web dashboard
Loading...
Searching...
No Matches
workspace_store.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <nlohmann/json.hpp>
4#include <string>
5#include <string_view>
6
7namespace slick::trader {
8
9// The dashboard's workspaces: each a named set of tool windows, where each sat and what it showed,
10// kept in one JSON file as {"last":<name>,"workspaces":{<name>:{"windows":[...]}}}. "Default" is
11// always there and can't be removed. `last` is the one the main window opens as it starts.
12// Single-threaded: the WebServer's event loop owns it.
14public:
15 static constexpr std::string_view DEFAULT = "Default";
16
17 // 200, or the HTTP status a change is refused with and why.
18 struct Result {
19 int status{200};
20 std::string error;
21 bool ok() const { return status == 200; }
22 };
23
24 // Reads `path`, where every change is written. A file missing, or unreadable (with a warning),
25 // leaves Default alone. An empty path keeps the workspaces in memory only.
26 void load(std::string path);
27
28 const nlohmann::json& doc() const { return doc_; }
29
30 // Keeps `windows` as workspace `name`, which becomes the last used.
31 Result save(std::string_view name, const nlohmann::json& windows);
32 Result remove(std::string_view name);
33 // Marks `name` the last used.
34 Result use(std::string_view name);
35
36private:
37 // Writes doc_ to path_ by a temp file renamed over it. On failure doc_ goes back to `before`.
38 Result commit(nlohmann::json before);
39
40 std::string path_;
41 nlohmann::json doc_;
42};
43
44} // namespace slick::trader
const nlohmann::json & doc() const
static constexpr std::string_view DEFAULT
Result save(std::string_view name, const nlohmann::json &windows)
Result remove(std::string_view name)
Result use(std::string_view name)