~aleteoryx/muditaos

ref: 9ba4d8cea949692768b4cbb0042fad7999362faa muditaos/module-gui/gui/dom/Item2JsonSerializer.hpp -rw-r--r-- 1.0 KiB
9ba4d8ce — Lukasz Mastalerz [BH-1838] Relaxation plays in the background for certain song lengths 2 years ago
                                                                                
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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "Item2JsonSerializingVisitor.hpp"
#include <json11.hpp>
#include <list>

namespace gui
{
    class ItemNode;

    class Item2JsonSerializer
    {
        using prototype = std::map<int, std::list<json11::Json::object>>;
        json11::Json document;
        Item2JsonSerializingVisitor visitor;

        void handleSibling(gui::ItemNode &node, prototype &doc, int &level);
        void handleParent(gui::ItemNode &node, prototype &doc, int &level);
        void handleOther(gui::ItemNode &node, prototype &doc, int &level);

      public:
        /// On traverse all `gui::Item`-based classes in the parent-children tree of given root will be serialized into
        /// JSON format and kept in `document`.
        void traverse(gui::Item &root);
        void dump(std::ostream &stream);
        [[nodiscard]] auto get() -> json11::Json &&;
    };
} // namespace gui