WebCFace 2.9.0
Web-based Communication Framework & Dashboard-like UI
Loading...
Searching...
No Matches
view.h
Go to the documentation of this file.
1#pragma once
2#include "./base.h"
5#include <map>
6#include <optional>
7#include <unordered_map>
8
9#ifndef MSGPACK_DEFINE_MAP
10#define MSGPACK_DEFINE_MAP(...)
11#endif
12
14namespace message {
15
24 int type = 0;
26 std::optional<SharedString> on_click_member, on_click_field;
27 std::optional<SharedString> text_ref_member, text_ref_field;
28 int text_color = 0, bg_color = 0;
29 std::optional<double> min_ = std::nullopt, max_ = std::nullopt,
30 step_ = std::nullopt;
31 std::vector<ValAdaptor> option_;
32 int width = 0, height = 0;
33
34 ViewComponentData() = default;
35 bool operator==(const ViewComponentData &other) const {
36 return type == other.type && text == other.text &&
37 on_click_member == other.on_click_member &&
38 on_click_field == other.on_click_field &&
39 text_ref_member == other.text_ref_member &&
40 text_ref_field == other.text_ref_field &&
41 text_color == other.text_color && bg_color == other.bg_color &&
42 min_ == other.min_ && max_ == other.max_ &&
43 step_ == other.step_ && option_ == other.option_ &&
44 width == other.width && height == other.height;
45 }
46 bool operator!=(const ViewComponentData &other) const {
47 return !(*this == other);
48 }
49
50 MSGPACK_DEFINE_MAP(MSGPACK_NVP("t", type), MSGPACK_NVP("x", text),
51 MSGPACK_NVP("L", on_click_member),
52 MSGPACK_NVP("l", on_click_field),
53 MSGPACK_NVP("R", text_ref_member),
54 MSGPACK_NVP("r", text_ref_field),
55 MSGPACK_NVP("c", text_color), MSGPACK_NVP("b", bg_color),
56 MSGPACK_NVP("im", min_), MSGPACK_NVP("ix", max_),
57 MSGPACK_NVP("is", step_), MSGPACK_NVP("io", option_),
58 MSGPACK_NVP("w", width), MSGPACK_NVP("h", height))
59};
65struct ViewData {
66 std::map<std::string, std::shared_ptr<message::ViewComponentData>>
68 std::vector<SharedString> data_ids;
69};
70
71
72struct ViewOld : public MessageBase<MessageKind::view_old> {
74 std::map<std::string, std::shared_ptr<ViewComponentData>> data_diff;
75 std::size_t length = 0;
76 ViewOld() = default;
77 ViewOld(const SharedString &field,
78 const std::unordered_map<int, std::shared_ptr<ViewComponentData>>
79 &data_diff,
80 std::size_t length)
81 : field(field), data_diff(), length(length) {
82 for (auto &&vc : data_diff) {
83 this->data_diff.emplace(std::to_string(vc.first), vc.second);
84 }
85 }
86 ViewOld(const SharedString &field,
87 const std::map<std::string, std::shared_ptr<ViewComponentData>>
88 &data_diff,
89 std::size_t length)
90 : field(field), data_diff(data_diff), length(length) {}
91 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("d", data_diff),
92 MSGPACK_NVP("l", length))
93};
94struct View : public MessageBase<MessageKind::view> {
96 std::map<std::string, std::shared_ptr<ViewComponentData>> data_diff;
97 std::optional<std::vector<SharedString>> data_ids;
98 View() = default;
99 View(const SharedString &field,
100 std::map<std::string, std::shared_ptr<ViewComponentData>> data_diff,
101 std::optional<std::vector<SharedString>> data_ids)
102 : field(field), data_diff(std::move(data_diff)),
103 data_ids(std::move(data_ids)) {}
104 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("d", data_diff),
105 MSGPACK_NVP("l", data_ids))
106};
107
108template <>
110 : public MessageBase<MessageKind::view_old + MessageKind::res> {
111 unsigned int req_id = 0;
113 std::map<std::string, std::shared_ptr<ViewComponentData>> data_diff;
114 std::size_t length = 0;
115 Res() = default;
116 Res(unsigned int req_id, const SharedString &sub_field,
117 const std::map<std::string, std::shared_ptr<ViewComponentData>>
118 &data_diff,
119 std::size_t length)
120 : req_id(req_id), sub_field(sub_field), data_diff(data_diff),
121 length(length) {}
122 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
123 MSGPACK_NVP("d", data_diff), MSGPACK_NVP("l", length))
124};
125template <>
126struct Res<View> : public MessageBase<MessageKind::view + MessageKind::res> {
127 unsigned int req_id = 0;
129 std::map<std::string, std::shared_ptr<ViewComponentData>> data_diff;
130 std::optional<std::vector<SharedString>> data_ids;
131 Res() = default;
132 Res(unsigned int req_id, const SharedString &sub_field,
133 const std::map<std::string, std::shared_ptr<ViewComponentData>>
134 &data_diff,
135 const std::optional<std::vector<SharedString>> &data_ids)
136 : req_id(req_id), sub_field(sub_field), data_diff(data_diff),
137 data_ids(data_ids) {}
138 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
139 MSGPACK_NVP("d", data_diff), MSGPACK_NVP("l", data_ids))
140};
141
142} // namespace message
144
146WEBCFACE_MESSAGE_FMT(webcface::message::Res<webcface::message::View>)
147WEBCFACE_MESSAGE_FMT(webcface::message::Entry<webcface::message::View>)
148WEBCFACE_MESSAGE_FMT(webcface::message::Req<webcface::message::View>)
150WEBCFACE_MESSAGE_FMT(webcface::message::Res<webcface::message::ViewOld>)
151WEBCFACE_MESSAGE_FMT(webcface::message::Entry<webcface::message::ViewOld>)
152WEBCFACE_MESSAGE_FMT(webcface::message::Req<webcface::message::ViewOld>)
#define MSGPACK_DEFINE_MAP(...)
Definition base.h:11
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:67
#define WEBCFACE_MESSAGE_FMT(Type)
Definition fmt.h:21
Definition arg.h:14
型からkindを取得するためだけのベースクラス
Definition base.h:60
Res(unsigned int req_id, const SharedString &sub_field, const std::map< std::string, std::shared_ptr< ViewComponentData > > &data_diff, std::size_t length)
Definition view.h:116
std::map< std::string, std::shared_ptr< ViewComponentData > > data_diff
Definition view.h:113
SharedString sub_field
Definition view.h:112
Res(unsigned int req_id, const SharedString &sub_field, const std::map< std::string, std::shared_ptr< ViewComponentData > > &data_diff, const std::optional< std::vector< SharedString > > &data_ids)
Definition view.h:132
std::optional< std::vector< SharedString > > data_ids
Definition view.h:130
std::map< std::string, std::shared_ptr< ViewComponentData > > data_diff
Definition view.h:129
SharedString sub_field
Definition view.h:128
Definition base.h:65
std::optional< SharedString > text_ref_member
Definition view.h:27
int text_color
Definition view.h:28
int width
Definition view.h:32
std::optional< SharedString > text_ref_field
Definition view.h:27
int bg_color
Definition view.h:28
std::optional< double > step_
Definition view.h:30
SharedString text
Definition view.h:25
std::optional< double > min_
Definition view.h:29
std::optional< SharedString > on_click_member
Definition view.h:26
bool operator==(const ViewComponentData &other) const
Definition view.h:35
std::vector< ValAdaptor > option_
Definition view.h:31
bool operator!=(const ViewComponentData &other) const
Definition view.h:46
int type
Definition view.h:24
int height
Definition view.h:32
std::optional< double > max_
Definition view.h:29
std::optional< SharedString > on_click_field
Definition view.h:26
Definition view.h:65
std::vector< SharedString > data_ids
Definition view.h:68
std::map< std::string, std::shared_ptr< message::ViewComponentData > > components
Definition view.h:67
Definition view.h:72
ViewOld(const SharedString &field, const std::map< std::string, std::shared_ptr< ViewComponentData > > &data_diff, std::size_t length)
Definition view.h:86
ViewOld(const SharedString &field, const std::unordered_map< int, std::shared_ptr< ViewComponentData > > &data_diff, std::size_t length)
Definition view.h:77
std::map< std::string, std::shared_ptr< ViewComponentData > > data_diff
Definition view.h:74
SharedString field
Definition view.h:73
Definition view.h:94
std::optional< std::vector< SharedString > > data_ids
Definition view.h:97
std::map< std::string, std::shared_ptr< ViewComponentData > > data_diff
Definition view.h:96
SharedString field
Definition view.h:95
View(const SharedString &field, std::map< std::string, std::shared_ptr< ViewComponentData > > data_diff, std::optional< std::vector< SharedString > > data_ids)
Definition view.h:99
#define WEBCFACE_NS_END
Definition webcface-config.h:118
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:117