summaryrefslogtreecommitdiff
path: root/src/state.cpp
blob: bf4ab0f093629ff58dc85fa593317d88e077042e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include "state.hpp"

void to_json(nlohmann::json &j, const ExpansionStateRoot &m) {
    if (m.Children.empty()) {
        j = nlohmann::json::object();
    } else {
        for (const auto &[id, state] : m.Children)
            j[std::to_string(id)] = state;
    }
}

void from_json(const nlohmann::json &j, ExpansionStateRoot &m) {
    for (const auto &[key, value] : j.items())
        m.Children[key] = value;
}

void to_json(nlohmann::json &j, const ExpansionState &m) {
    j["e"] = m.IsExpanded;
    j["c"] = m.Children;
}

void from_json(const nlohmann::json &j, ExpansionState &m) {
    j.at("e").get_to(m.IsExpanded);
    j.at("c").get_to(m.Children);
}

void to_json(nlohmann::json &j, const TabsState &m) {
    j = m.Channels;
}

void from_json(const nlohmann::json &j, TabsState &m) {
    j.get_to(m.Channels);
}

void to_json(nlohmann::json &j, const AbaddonApplicationState &m) {
    j["active_channel"] = m.ActiveChannel;
    j["expansion"] = m.Expansion;
    j["tabs"] = m.Tabs;
}

void from_json(const nlohmann::json &j, AbaddonApplicationState &m) {
    if (j.contains("active_channel"))
        j.at("active_channel").get_to(m.ActiveChannel);
    if (j.contains("expansion"))
        j.at("expansion").get_to(m.Expansion);
    if (j.contains("tabs"))
        j.at("tabs").get_to(m.Tabs);
}