WebCFace 2.9.0
Web-based Communication Framework & Dashboard-like UI
Loading...
Searching...
No Matches
data_buffer.h
Go to the documentation of this file.
1#pragma once
3#include "webcface/view.h"
5#include <sstream>
6#include <memory>
7
9namespace internal {
16template <typename Component>
18 Field target_;
19 std::vector<Component> components_;
20 bool modified_;
21
22 public:
23 DataSetBuffer() : target_(), components_(), modified_(false) {}
24 explicit DataSetBuffer(const Field &base)
25 : target_(base), components_(), modified_(false) {}
26 DataSetBuffer(const DataSetBuffer &) = delete;
30
31 virtual ~DataSetBuffer() noexcept {
32 try {
33 onDestroy();
34 } catch (...) {
35 // ignore exception
36 }
37 }
38 void onDestroy() {
39 if (!target_.data_w.expired() && target_.isSelf()) {
40 sync();
41 }
42 }
43
44 void sync() {
45 if (modified_) {
46 modified_ = false;
47 onSync();
48 }
49 }
56 void onSync();
57
58 void init() {
59 components_.clear();
60 modified_ = true;
61 }
62
67 virtual void onAdd() {}
68 void add(Component &&cp) {
69 onAdd();
70 components_.push_back(std::move(cp));
71 modified_ = true;
72 }
79 void set(const std::vector<Component> &cv) {
80 onAdd();
81 components_ = cv;
82 modified_ = true;
83 sync();
84 }
85 void set(std::initializer_list<Component> cl) {
86 onAdd();
87 components_ = std::vector<Component>(cl.begin(), cl.end());
88 modified_ = true;
89 sync();
90 }
91 const std::vector<Component> &components() const { return components_; }
92};
93
94template <>
96template <>
98template <>
100template <>
102
107class ViewBuf final : public std::stringbuf,
108 public DataSetBuffer<TemporalViewComponent> {
113 int sync() override;
114
115 public:
122 void addVC(TemporalViewComponent &&vc);
123 void addText(std::string_view text,
124 const TemporalViewComponent *vc = nullptr);
126
127 explicit ViewBuf();
128 explicit ViewBuf(const Field &base);
129 ~ViewBuf() override;
130};
131
132class Canvas2DDataBuf final : public DataSetBuffer<TemporalCanvas2DComponent> {
133 double width_ = 0, height_ = 0;
134
135 public:
137 Canvas2DDataBuf() = default;
140 void onAdd() override { checkSize(); }
141 void checkSize() const {
142 if (width_ <= 0 || height_ <= 0) {
143 throw InvalidArgument("invalid Canvas2D size (" +
144 std::to_string(width_) + ", " +
145 std::to_string(height_) + ")");
146 }
147 }
148 void init(double width, double height) {
149 width_ = width;
150 height_ = height;
152 }
157 ~Canvas2DDataBuf() noexcept override {
158 try {
159 onDestroy();
160 } catch (...) {
161 // ignore exception
162 }
163 }
164};
165
166} // namespace internal
Definition component_canvas2d.h:148
Viewを構築するときに使う一時的なViewComponent.
Definition component_view.h:292
Definition data_buffer.h:132
Canvas2DDataBuf(const Field &base)
Definition data_buffer.h:138
~Canvas2DDataBuf() noexcept override
Definition data_buffer.h:157
void init(double width, double height)
Definition data_buffer.h:148
void checkSize() const
Definition data_buffer.h:141
void onAdd() override
add時のチェック
Definition data_buffer.h:140
View,Canvasなどで送信用にaddされたデータを管理する
Definition data_buffer.h:17
void init()
Definition data_buffer.h:58
void set(const std::vector< Component > &cv)
まとめてセット
Definition data_buffer.h:79
void set(std::initializer_list< Component > cl)
Definition data_buffer.h:85
virtual ~DataSetBuffer() noexcept
Definition data_buffer.h:31
DataSetBuffer()
Definition data_buffer.h:23
const std::vector< Component > & components() const
Definition data_buffer.h:91
void onDestroy()
Definition data_buffer.h:38
void add(Component &&cp)
Definition data_buffer.h:68
DataSetBuffer(const Field &base)
Definition data_buffer.h:24
DataSetBuffer(DataSetBuffer &&)=delete
DataSetBuffer & operator=(DataSetBuffer &&)=delete
void sync()
Definition data_buffer.h:44
DataSetBuffer & operator=(const DataSetBuffer &)=delete
void onSync()
データを処理しtargetにsetする
DataSetBuffer(const DataSetBuffer &)=delete
virtual void onAdd()
add時のチェック
Definition data_buffer.h:67
Viewの送信用データを保持する
Definition data_buffer.h:108
void syncSetBuf()
Definition data_buffer.h:125
ClientDataの参照とメンバ名とデータ名を持つクラス
Definition field.h:71
bool isSelf() const
memberがselfならtrue
Definition field.cc:218
std::weak_ptr< internal::ClientData > data_w
ClientDataの参照
Definition field.h:77
その他のパラメーターエラー
Definition exception.h:89
#define WEBCFACE_NS_END
Definition webcface-config.h:118
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:117