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 <vector>
3#include <ostream>
4#include <memory>
5#include <utility>
6#ifdef WEBCFACE_MESON
7#include "webcface-config.h"
8#else
9#include "webcface/common/webcface-config.h"
10#endif
11#include "components.h"
12
14namespace internal {
15template <typename Component>
16class DataSetBuffer;
17class ViewBuf;
18} // namespace internal
19
26class WEBCFACE_DLL View : protected Field {
27 std::shared_ptr<internal::ViewBuf> sb;
28 mutable std::ostream os;
29
30 static constexpr std::nullptr_t TraitOk = nullptr;
31 template <typename T>
32 using EnableIfFormattable =
33 decltype(std::declval<std::ostream>() << std::declval<T>(), TraitOk);
34 template <typename T>
35 using EnableIfInvocable =
36 decltype(std::declval<T>()(std::declval<View>()), TraitOk);
37
38 public:
39 View();
40 View(const Field &base);
41 View(const Field &base, const SharedString &field)
42 : View(Field{base, field}) {}
43 View(const View &rhs) : View() { *this = rhs; }
44 View(View &&rhs) noexcept : View() { *this = std::move(rhs); }
45 View &operator=(const View &rhs);
46 View &operator=(View &&rhs) noexcept;
47 ~View();
48
50
51 using Field::lastName;
52 using Field::member;
53 using Field::name;
54 using Field::nameW;
59 View child(std::string_view field) const {
60 return this->Field::child(field);
61 }
66 View child(std::wstring_view field) const {
67 return this->Field::child(field);
68 }
72 View child(int index) const { return this->Field::child(index); }
77 View operator[](std::string_view field) const { return child(field); }
82 View operator[](std::wstring_view field) const { return child(field); }
87 View operator[](const char *field) const { return child(field); }
91 View operator[](const wchar_t *field) const { return child(field); }
96 View operator[](int index) const { return child(index); }
101 View parent() const { return this->Field::parent(); }
102
109 const View &
110 onChange(std::function<void WEBCFACE_CALL_FP(View)> callback) const;
117 template <typename F, typename std::enable_if_t<std::is_invocable_v<F>,
118 std::nullptr_t> = nullptr>
119 const View &onChange(F callback) const {
120 return onChange(
121 [callback = std::move(callback)](const auto &) { callback(); });
122 }
130 template <typename T>
131 [[deprecated]] void appendListener(T &&callback) const {
132 onChange(std::forward<T>(callback));
133 }
134
140 const View &request() const;
145 std::optional<std::vector<ViewComponent>> tryGet() const;
150 std::vector<ViewComponent> get() const {
151 return tryGet().value_or(std::vector<ViewComponent>{});
152 }
161 bool exists() const;
167 [[deprecated]] std::chrono::system_clock::time_point time() const;
168
173 const View &free() const;
174
184 const View &init() const;
194 template <typename T, EnableIfFormattable<T> = TraitOk>
195 const View &operator<<(T &&rhs) const {
196 os << std::forward<T>(rhs);
197 return *this;
198 }
199 const View &operator<<(std::ostream &(*os_manip)(std::ostream &)) const {
200 os_manip(os);
201 return *this;
202 }
209 template <bool C2, bool C3>
211 *this << std::move(vc.component_v);
212 return *this;
213 }
220 const View &operator<<(TemporalViewComponent vc) const;
228 template <typename F, EnableIfInvocable<F> = TraitOk>
229 const View &operator<<(const F &manip) const {
230 manip(*this);
231 return *this;
232 }
233
242 template <typename T>
243 const View &add(T &&rhs) const {
244 *this << std::forward<T>(rhs);
245 return *this;
246 }
247
255 const View &sync() const;
256
262 template <typename T, typename std::enable_if_t<std::is_same_v<T, View>,
263 std::nullptr_t> = nullptr>
264 bool operator==(const T &other) const {
265 return static_cast<Field>(*this) == static_cast<Field>(other);
266 }
267 template <typename T, typename std::enable_if_t<std::is_same_v<T, View>,
268 std::nullptr_t> = nullptr>
269 bool operator!=(const T &other) const {
270 return static_cast<Field>(*this) != static_cast<Field>(other);
271 }
272};
u8stringとstringとwstringをshared_ptrで持ち共有する
Definition encoding.h:69
Viewを構築するときに使う一時的なViewComponent.
Definition component_view.h:267
Viewの送受信データを表すクラス
Definition view.h:26
View(View &&rhs) noexcept
Definition view.h:44
const View & operator<<(T &&rhs) const
文字列にフォーマットし、textコンポーネントとして追加
Definition view.h:195
bool operator==(const T &other) const
Viewの参照先を比較
Definition view.h:264
const View & operator<<(std::ostream &(*os_manip)(std::ostream &)) const
Definition view.h:199
View operator[](int index) const
Definition view.h:96
const View & operator<<(TemporalComponent< true, C2, C3 > vc) const
コンポーネントを追加
Definition view.h:210
View operator[](std::wstring_view field) const
Definition view.h:82
View operator[](std::string_view field) const
Definition view.h:77
View(const View &rhs)
Definition view.h:43
const View & onChange(F callback) const
値が変化したときに呼び出されるコールバックを設定
Definition view.h:119
bool operator!=(const T &other) const
Definition view.h:269
std::vector< ViewComponent > get() const
Viewを取得する
Definition view.h:150
View operator[](const char *field) const
Definition view.h:87
void appendListener(T &&callback) const
Definition view.h:131
const View & operator<<(const F &manip) const
コンポーネントを追加
Definition view.h:229
View child(int index) const
Definition view.h:72
const View & add(T &&rhs) const
コンポーネントなどを追加
Definition view.h:243
View(const Field &base, const SharedString &field)
Definition view.h:41
View child(std::string_view field) const
「(thisの名前).(追加の名前)」を新しい名前とするField
Definition view.h:59
View child(std::wstring_view field) const
「(thisの名前).(追加の名前)」を新しい名前とするField (wstring)
Definition view.h:66
View operator[](const wchar_t *field) const
Definition view.h:91
View parent() const
nameの最後のピリオドの前までを新しい名前とするField
Definition view.h:101
View,Canvasなどで送信用にaddされたデータを管理する
Definition data_buffer.h:17
std::ostream & operator<<(std::ostream &os, const Arg &arg)
Definition func_info.cc:96
ClientDataの参照とメンバ名とデータ名を持つクラス
Definition field.h:70
Field parent() const
nameの最後のピリオドの前までを新しい名前とするField
Definition field.cc:33
Field child(const SharedString &field) const
Definition field.cc:42
Canvas2D, Canvas3D (, View) に要素をaddするときに使うインタフェース
Definition components.h:22
TemporalViewComponent component_v
Definition components.h:23
#define WEBCFACE_DLL
Definition webcface-config.h:60
#define WEBCFACE_NS_END
Definition webcface-config.h:104
#define WEBCFACE_NS_BEGIN
Definition webcface-config.h:103
#define WEBCFACE_CALL_FP
Definition webcface-config.h:98