WebCFace 2.5.2
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, const TemporalViewComponent *vc = nullptr);
125
126 explicit ViewBuf();
127 explicit ViewBuf(const Field &base);
128 ~ViewBuf() override;
129};
130
131class Canvas2DDataBuf final : public DataSetBuffer<TemporalCanvas2DComponent> {
132 double width_ = 0, height_ = 0;
133
134 public:
136 Canvas2DDataBuf() = default;
139 void onAdd() override { checkSize(); }
140 void checkSize() const {
141 if (width_ <= 0 && height_ <= 0) {
142 throw std::invalid_argument("Canvas2D size is invalid (" +
143 std::to_string(width_) + ", " +
144 std::to_string(height_) + ")");
145 }
146 }
147 void init(double width, double height) {
148 width_ = width;
149 height_ = height;
151 }
156 ~Canvas2DDataBuf() noexcept override {
157 try {
158 onDestroy();
159 } catch (...) {
160 // ignore exception
161 }
162 }
163};
164
165} // namespace internal
Definition component_canvas2d.h:137
Viewを構築するときに使う一時的なViewComponent.
Definition component_view.h:267
Definition data_buffer.h:131
Canvas2DDataBuf(const Field &base)
Definition data_buffer.h:137
~Canvas2DDataBuf() noexcept override
Definition data_buffer.h:156
void init(double width, double height)
Definition data_buffer.h:147
void checkSize() const
Definition data_buffer.h:140
void onAdd() override
add時のチェック
Definition data_buffer.h:139
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:124
ClientDataの参照とメンバ名とデータ名を持つクラス
Definition field.h:70
bool isSelf() const
memberがselfならtrue
Definition field.cc:142
std::weak_ptr< internal::ClientData > data_w
ClientDataの参照
Definition field.h:76
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103