WebCFace 2.5.2
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 <optional>
6#include <unordered_map>
7
8#ifndef MSGPACK_DEFINE_MAP
9#define MSGPACK_DEFINE_MAP(...)
10#endif
11
13namespace message {
14
23 int type = 0;
25 std::optional<SharedString> on_click_member, on_click_field;
26 std::optional<SharedString> text_ref_member, text_ref_field;
27 int text_color = 0, bg_color = 0;
28 std::optional<double> min_ = std::nullopt, max_ = std::nullopt,
29 step_ = std::nullopt;
30 std::vector<ValAdaptor> option_;
31
32 ViewComponentData() = default;
33 bool operator==(const ViewComponentData &other) const {
34 return type == other.type && text == other.text &&
35 on_click_member == other.on_click_member &&
36 on_click_field == other.on_click_field &&
37 text_ref_member == other.text_ref_member &&
38 text_ref_field == other.text_ref_field &&
39 text_color == other.text_color && bg_color == other.bg_color &&
40 min_ == other.min_ && max_ == other.max_ &&
41 step_ == other.step_ && option_ == other.option_;
42 }
43 bool operator!=(const ViewComponentData &other) const {
44 return !(*this == other);
45 }
46
47 MSGPACK_DEFINE_MAP(MSGPACK_NVP("t", type), MSGPACK_NVP("x", text),
48 MSGPACK_NVP("L", on_click_member),
49 MSGPACK_NVP("l", on_click_field),
50 MSGPACK_NVP("R", text_ref_member),
51 MSGPACK_NVP("r", text_ref_field),
52 MSGPACK_NVP("c", text_color), MSGPACK_NVP("b", bg_color),
53 MSGPACK_NVP("im", min_), MSGPACK_NVP("ix", max_),
54 MSGPACK_NVP("is", step_), MSGPACK_NVP("io", option_))
55};
61struct ViewData {
62 std::map<std::string, std::shared_ptr<message::ViewComponentData>>
64 std::vector<SharedString> data_ids;
65};
66
67
68struct ViewOld : public MessageBase<MessageKind::view_old> {
70 std::map<std::string, std::shared_ptr<ViewComponentData>> data_diff;
71 std::size_t length = 0;
72 ViewOld() = default;
73 ViewOld(const SharedString &field,
74 const std::unordered_map<int, std::shared_ptr<ViewComponentData>>
75 &data_diff,
76 std::size_t length)
77 : field(field), data_diff(), length(length) {
78 for (auto &&vc : data_diff) {
79 this->data_diff.emplace(std::to_string(vc.first), vc.second);
80 }
81 }
82 ViewOld(const SharedString &field,
83 const std::map<std::string, std::shared_ptr<ViewComponentData>>
84 &data_diff,
85 std::size_t length)
86 : field(field), data_diff(data_diff), length(length) {}
87 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("d", data_diff),
88 MSGPACK_NVP("l", length))
89};
90struct View : public MessageBase<MessageKind::view> {
92 std::map<std::string, std::shared_ptr<ViewComponentData>> data_diff;
93 std::optional<std::vector<SharedString>> data_ids;
94 View() = default;
95 View(const SharedString &field,
96 std::map<std::string, std::shared_ptr<ViewComponentData>> data_diff,
97 std::optional<std::vector<SharedString>> data_ids)
98 : field(field), data_diff(std::move(data_diff)),
99 data_ids(std::move(data_ids)) {}
100 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("d", data_diff),
101 MSGPACK_NVP("l", data_ids))
102};
103
104template <>
106 : public MessageBase<MessageKind::view_old + MessageKind::res> {
107 unsigned int req_id = 0;
109 std::map<std::string, std::shared_ptr<ViewComponentData>> data_diff;
110 std::size_t length = 0;
111 Res() = default;
112 Res(unsigned int req_id, const SharedString &sub_field,
113 const std::map<std::string, std::shared_ptr<ViewComponentData>>
114 &data_diff,
115 std::size_t length)
116 : req_id(req_id), sub_field(sub_field), data_diff(data_diff),
117 length(length) {}
118 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
119 MSGPACK_NVP("d", data_diff), MSGPACK_NVP("l", length))
120};
121template <>
122struct Res<View> : public MessageBase<MessageKind::view + MessageKind::res> {
123 unsigned int req_id = 0;
125 std::map<std::string, std::shared_ptr<ViewComponentData>> data_diff;
126 std::optional<std::vector<SharedString>> data_ids;
127 Res() = default;
128 Res(unsigned int req_id, const SharedString &sub_field,
129 const std::map<std::string, std::shared_ptr<ViewComponentData>>
130 &data_diff,
131 const std::optional<std::vector<SharedString>> &data_ids)
132 : req_id(req_id), sub_field(sub_field), data_diff(data_diff),
133 data_ids(data_ids) {}
134 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
135 MSGPACK_NVP("d", data_diff), MSGPACK_NVP("l", data_ids))
136};
137
138} // namespace message
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
#define MSGPACK_DEFINE_MAP(...)
Definition canvas2d.h:10
型からkindを取得するためだけのベースクラス
Definition base.h:53
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:112
std::map< std::string, std::shared_ptr< ViewComponentData > > data_diff
Definition view.h:109
SharedString sub_field
Definition view.h:108
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:128
std::optional< std::vector< SharedString > > data_ids
Definition view.h:126
std::map< std::string, std::shared_ptr< ViewComponentData > > data_diff
Definition view.h:125
SharedString sub_field
Definition view.h:124
Definition base.h:58
std::optional< SharedString > text_ref_member
Definition view.h:26
int text_color
Definition view.h:27
std::optional< SharedString > text_ref_field
Definition view.h:26
int bg_color
Definition view.h:27
std::optional< double > step_
Definition view.h:29
SharedString text
Definition view.h:24
std::optional< double > min_
Definition view.h:28
std::optional< SharedString > on_click_member
Definition view.h:25
bool operator==(const ViewComponentData &other) const
Definition view.h:33
std::vector< ValAdaptor > option_
Definition view.h:30
bool operator!=(const ViewComponentData &other) const
Definition view.h:43
int type
Definition view.h:23
std::optional< double > max_
Definition view.h:28
std::optional< SharedString > on_click_field
Definition view.h:25
Definition view.h:61
std::vector< SharedString > data_ids
Definition view.h:64
std::map< std::string, std::shared_ptr< message::ViewComponentData > > components
Definition view.h:63
Definition view.h:68
ViewOld(const SharedString &field, const std::map< std::string, std::shared_ptr< ViewComponentData > > &data_diff, std::size_t length)
Definition view.h:82
ViewOld(const SharedString &field, const std::unordered_map< int, std::shared_ptr< ViewComponentData > > &data_diff, std::size_t length)
Definition view.h:73
std::map< std::string, std::shared_ptr< ViewComponentData > > data_diff
Definition view.h:70
SharedString field
Definition view.h:69
Definition view.h:90
std::optional< std::vector< SharedString > > data_ids
Definition view.h:93
std::map< std::string, std::shared_ptr< ViewComponentData > > data_diff
Definition view.h:92
SharedString field
Definition view.h:91
View(const SharedString &field, std::map< std::string, std::shared_ptr< ViewComponentData > > data_diff, std::optional< std::vector< SharedString > > data_ids)
Definition view.h:95
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103