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>,
67 std::less<>>
69 std::vector<SharedString> data_ids;
70};
71
72
73struct ViewOld : public MessageBase<MessageKind::view_old> {
75 std::map<std::string, std::shared_ptr<ViewComponentData>> data_diff;
76 std::size_t length = 0;
77 ViewOld() = default;
78 ViewOld(const SharedString &field,
79 const std::unordered_map<int, std::shared_ptr<ViewComponentData>>
80 &data_diff,
81 std::size_t length)
82 : field(field), data_diff(), length(length) {
83 for (auto &&vc : data_diff) {
84 this->data_diff.emplace(std::to_string(vc.first), vc.second);
85 }
86 }
87 ViewOld(const SharedString &field,
88 const std::map<std::string, std::shared_ptr<ViewComponentData>>
89 &data_diff,
90 std::size_t length)
91 : field(field), data_diff(data_diff), length(length) {}
92 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("d", data_diff),
93 MSGPACK_NVP("l", length))
94};
95struct View : public MessageBase<MessageKind::view> {
97 std::map<std::string, std::shared_ptr<ViewComponentData>, std::less<>>
99 std::optional<std::vector<SharedString>> data_ids;
100 View() = default;
101 View(const SharedString &field,
102 std::map<std::string, std::shared_ptr<ViewComponentData>, std::less<>>
103 data_diff,
104 std::optional<std::vector<SharedString>> data_ids)
105 : field(field), data_diff(std::move(data_diff)),
106 data_ids(std::move(data_ids)) {}
107 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("d", data_diff),
108 MSGPACK_NVP("l", data_ids))
109};
110
111template <>
113 : public MessageBase<MessageKind::view_old + MessageKind::res> {
114 unsigned int req_id = 0;
116 std::map<std::string, std::shared_ptr<ViewComponentData>> data_diff;
117 std::size_t length = 0;
118 Res() = default;
119 Res(unsigned int req_id, const SharedString &sub_field,
120 const std::map<std::string, std::shared_ptr<ViewComponentData>>
121 &data_diff,
122 std::size_t length)
123 : req_id(req_id), sub_field(sub_field), data_diff(data_diff),
124 length(length) {}
125 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
126 MSGPACK_NVP("d", data_diff), MSGPACK_NVP("l", length))
127};
128template <>
129struct Res<View> : public MessageBase<MessageKind::view + MessageKind::res> {
130 unsigned int req_id = 0;
132 std::map<std::string, std::shared_ptr<ViewComponentData>, std::less<>>
134 std::optional<std::vector<SharedString>> data_ids;
135 Res() = default;
136 Res(unsigned int req_id, const SharedString &sub_field,
137 const std::map<std::string, std::shared_ptr<ViewComponentData>,
138 std::less<>> &data_diff,
139 const std::optional<std::vector<SharedString>> &data_ids)
140 : req_id(req_id), sub_field(sub_field), data_diff(data_diff),
141 data_ids(data_ids) {}
142 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
143 MSGPACK_NVP("d", data_diff), MSGPACK_NVP("l", data_ids))
144};
145
146} // namespace message
148
150WEBCFACE_MESSAGE_FMT(webcface::message::Res<webcface::message::View>)
151WEBCFACE_MESSAGE_FMT(webcface::message::Entry<webcface::message::View>)
152WEBCFACE_MESSAGE_FMT(webcface::message::Req<webcface::message::View>)
154WEBCFACE_MESSAGE_FMT(webcface::message::Res<webcface::message::ViewOld>)
155WEBCFACE_MESSAGE_FMT(webcface::message::Entry<webcface::message::ViewOld>)
156WEBCFACE_MESSAGE_FMT(webcface::message::Req<webcface::message::ViewOld>)
#define MSGPACK_DEFINE_MAP(...)
Definition base.h:18
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:159
#define WEBCFACE_MESSAGE_FMT(Type)
Definition fmt.h:21
Definition arg.h:14
型からkindを取得するためだけのベースクラス
Definition base.h:68
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:119
std::map< std::string, std::shared_ptr< ViewComponentData > > data_diff
Definition view.h:116
SharedString sub_field
Definition view.h:115
std::optional< std::vector< SharedString > > data_ids
Definition view.h:134
std::map< std::string, std::shared_ptr< ViewComponentData >, std::less<> > data_diff
Definition view.h:133
Res(unsigned int req_id, const SharedString &sub_field, const std::map< std::string, std::shared_ptr< ViewComponentData >, std::less<> > &data_diff, const std::optional< std::vector< SharedString > > &data_ids)
Definition view.h:136
SharedString sub_field
Definition view.h:131
Definition base.h:73
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:69
std::map< std::string, std::shared_ptr< message::ViewComponentData >, std::less<> > components
Definition view.h:68
Definition view.h:73
ViewOld(const SharedString &field, const std::map< std::string, std::shared_ptr< ViewComponentData > > &data_diff, std::size_t length)
Definition view.h:87
ViewOld(const SharedString &field, const std::unordered_map< int, std::shared_ptr< ViewComponentData > > &data_diff, std::size_t length)
Definition view.h:78
std::map< std::string, std::shared_ptr< ViewComponentData > > data_diff
Definition view.h:75
SharedString field
Definition view.h:74
Definition view.h:95
std::optional< std::vector< SharedString > > data_ids
Definition view.h:99
View(const SharedString &field, std::map< std::string, std::shared_ptr< ViewComponentData >, std::less<> > data_diff, std::optional< std::vector< SharedString > > data_ids)
Definition view.h:101
std::map< std::string, std::shared_ptr< ViewComponentData >, std::less<> > data_diff
Definition view.h:98
SharedString field
Definition view.h:96
#define WEBCFACE_NS_END
Definition webcface-config.h:118
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:117