WebCFace 2.5.2
Web-based Communication Framework & Dashboard-like UI
Loading...
Searching...
No Matches
canvas2d.h
Go to the documentation of this file.
1#pragma once
2#include "./base.h"
4#include <optional>
5#include <unordered_map>
6#include <vector>
7#include <array>
8
9#ifndef MSGPACK_DEFINE_MAP
10#define MSGPACK_DEFINE_MAP(...)
11#endif
12
14namespace message {
15
17 int type = 0;
18 std::array<double, 2> origin_pos;
19 double origin_rot;
20 int color = 0, fill = 0;
22 std::optional<int> geometry_type;
23 std::vector<double> properties;
24 std::optional<SharedString> on_click_member, on_click_field;
27 bool operator==(const Canvas2DComponentData &other) const {
28 return type == other.type && origin_pos == other.origin_pos &&
29 origin_rot == other.origin_rot && color == other.color &&
30 fill == other.fill && stroke_width == other.stroke_width &&
31 geometry_type == other.geometry_type &&
32 properties == other.properties &&
33 on_click_member == other.on_click_member &&
34 on_click_field == other.on_click_field && text == other.text;
35 }
36 bool operator!=(const Canvas2DComponentData &other) const {
37 return !(*this == other);
38 }
39 MSGPACK_DEFINE_MAP(MSGPACK_NVP("t", type), MSGPACK_NVP("op", origin_pos),
40 MSGPACK_NVP("or", origin_rot), MSGPACK_NVP("c", color),
41 MSGPACK_NVP("f", fill), MSGPACK_NVP("s", stroke_width),
42 MSGPACK_NVP("gt", geometry_type),
43 MSGPACK_NVP("gp", properties),
44 MSGPACK_NVP("L", on_click_member),
45 MSGPACK_NVP("l", on_click_field), MSGPACK_NVP("x", text))
46};
48 double width = 0, height = 0;
49 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> components;
50 std::vector<SharedString> data_ids;
51 Canvas2DData() = default;
52 Canvas2DData(double width, double height)
53 : width(width), height(height), components(), data_ids() {}
54};
55
56struct Canvas2D : public MessageBase<MessageKind::canvas2d> {
58 double width, height;
59 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> data_diff;
60 std::optional<std::vector<SharedString>> data_ids;
61 Canvas2D() = default;
63 const SharedString &field, double width, double height,
64 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> data_diff,
65 std::optional<std::vector<SharedString>> data_ids)
66 : field(field), width(width), height(height),
67 data_diff(std::move(data_diff)), data_ids(std::move(data_ids)) {}
68 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("w", width),
69 MSGPACK_NVP("h", height), MSGPACK_NVP("d", data_diff),
70 MSGPACK_NVP("l", data_ids))
71};
72struct Canvas2DOld : public MessageBase<MessageKind::canvas2d_old> {
74 double width, height;
75 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> data_diff;
76 std::size_t length;
77 Canvas2DOld() = default;
79 const SharedString &field, double width, double height,
80 const std::unordered_map<int, std::shared_ptr<Canvas2DComponentData>>
81 &data_diff,
82 std::size_t length)
83 : field(field), width(width), height(height), data_diff(),
84 length(length) {
85 for (const auto &vc : data_diff) {
86 this->data_diff.emplace(std::to_string(vc.first), vc.second);
87 }
88 }
90 const SharedString &field, double width, double height,
91 const std::map<std::string, std::shared_ptr<Canvas2DComponentData>>
92 &data_diff,
93 std::size_t length)
94 : field(field), width(width), height(height), data_diff(data_diff),
95 length(length) {}
96 MSGPACK_DEFINE_MAP(MSGPACK_NVP("f", field), MSGPACK_NVP("w", width),
97 MSGPACK_NVP("h", height), MSGPACK_NVP("d", data_diff),
98 MSGPACK_NVP("l", length))
99};
100template <>
102 : public MessageBase<MessageKind::canvas2d_old + MessageKind::res> {
103 unsigned int req_id = 0;
105 double width = 0, height = 0;
106 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> data_diff;
107 std::size_t length;
108 Res() = default;
109 Res(unsigned int req_id, const SharedString &sub_field, double width,
110 double height,
111 const std::map<std::string, std::shared_ptr<Canvas2DComponentData>>
112 &data_diff,
113 std::size_t length)
114 : req_id(req_id), sub_field(sub_field), width(width), height(height),
115 data_diff(data_diff), length(length) {}
116 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
117 MSGPACK_NVP("w", width), MSGPACK_NVP("h", height),
118 MSGPACK_NVP("d", data_diff), MSGPACK_NVP("l", length))
119};
120template <>
122 : public MessageBase<MessageKind::canvas2d + MessageKind::res> {
123 unsigned int req_id = 0;
125 double width = 0, height = 0;
126 std::map<std::string, std::shared_ptr<Canvas2DComponentData>> data_diff;
127 std::optional<std::vector<SharedString>> data_ids;
128 Res() = default;
129 Res(unsigned int req_id, const SharedString &sub_field, double width,
130 double height,
131 const std::map<std::string, std::shared_ptr<Canvas2DComponentData>>
132 &data_diff,
133 const std::optional<std::vector<SharedString>> &data_ids)
134 : req_id(req_id), sub_field(sub_field), width(width), height(height),
135 data_diff(data_diff), data_ids(data_ids) {}
136 MSGPACK_DEFINE_MAP(MSGPACK_NVP("i", req_id), MSGPACK_NVP("f", sub_field),
137 MSGPACK_NVP("w", width), MSGPACK_NVP("h", height),
138 MSGPACK_NVP("d", data_diff), MSGPACK_NVP("l", data_ids))
139};
140
141} // namespace message
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
#define MSGPACK_DEFINE_MAP(...)
Definition canvas2d.h:10
int color
Definition canvas2d.h:20
bool operator==(const Canvas2DComponentData &other) const
Definition canvas2d.h:27
int fill
Definition canvas2d.h:20
std::array< double, 2 > origin_pos
Definition canvas2d.h:18
SharedString text
Definition canvas2d.h:25
bool operator!=(const Canvas2DComponentData &other) const
Definition canvas2d.h:36
std::optional< SharedString > on_click_member
Definition canvas2d.h:24
std::vector< double > properties
Definition canvas2d.h:23
std::optional< int > geometry_type
Definition canvas2d.h:22
int type
Definition canvas2d.h:17
double origin_rot
Definition canvas2d.h:19
double stroke_width
Definition canvas2d.h:21
std::optional< SharedString > on_click_field
Definition canvas2d.h:24
Definition canvas2d.h:47
std::map< std::string, std::shared_ptr< Canvas2DComponentData > > components
Definition canvas2d.h:49
std::vector< SharedString > data_ids
Definition canvas2d.h:50
Canvas2DData(double width, double height)
Definition canvas2d.h:52
Definition canvas2d.h:72
Canvas2DOld(const SharedString &field, double width, double height, const std::map< std::string, std::shared_ptr< Canvas2DComponentData > > &data_diff, std::size_t length)
Definition canvas2d.h:89
double height
Definition canvas2d.h:74
Canvas2DOld(const SharedString &field, double width, double height, const std::unordered_map< int, std::shared_ptr< Canvas2DComponentData > > &data_diff, std::size_t length)
Definition canvas2d.h:78
std::size_t length
Definition canvas2d.h:76
SharedString field
Definition canvas2d.h:73
std::map< std::string, std::shared_ptr< Canvas2DComponentData > > data_diff
Definition canvas2d.h:75
Definition canvas2d.h:56
std::optional< std::vector< SharedString > > data_ids
Definition canvas2d.h:60
Canvas2D(const SharedString &field, double width, double height, std::map< std::string, std::shared_ptr< Canvas2DComponentData > > data_diff, std::optional< std::vector< SharedString > > data_ids)
Definition canvas2d.h:62
double height
Definition canvas2d.h:58
SharedString field
Definition canvas2d.h:57
std::map< std::string, std::shared_ptr< Canvas2DComponentData > > data_diff
Definition canvas2d.h:59
型からkindを取得するためだけのベースクラス
Definition base.h:53
Res(unsigned int req_id, const SharedString &sub_field, double width, double height, const std::map< std::string, std::shared_ptr< Canvas2DComponentData > > &data_diff, std::size_t length)
Definition canvas2d.h:109
std::size_t length
Definition canvas2d.h:107
SharedString sub_field
Definition canvas2d.h:104
std::map< std::string, std::shared_ptr< Canvas2DComponentData > > data_diff
Definition canvas2d.h:106
std::optional< std::vector< SharedString > > data_ids
Definition canvas2d.h:127
Res(unsigned int req_id, const SharedString &sub_field, double width, double height, const std::map< std::string, std::shared_ptr< Canvas2DComponentData > > &data_diff, const std::optional< std::vector< SharedString > > &data_ids)
Definition canvas2d.h:129
SharedString sub_field
Definition canvas2d.h:124
std::map< std::string, std::shared_ptr< Canvas2DComponentData > > data_diff
Definition canvas2d.h:126
Definition base.h:58
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103