Aria 2.0.0
C++23 MVVM framework (C++20 minimum) — reactive, coroutine-first, ABI-layered
Loading...
Searching...
No Matches
view_adapter_base.hpp
Go to the documentation of this file.
1#pragma once
2
3// ============================================================================
4// view_adapter_base.hpp
5// ----------------------------------------------------------------------------
6// `ViewAdapterBase` — an opt-in base class for writing an `IViewAdapter`
7// without implementing all 25 pure virtuals.
8//
9// Why
10// ---
11// `IViewAdapter` is a wide interface by design: text, bool, int, int64,
12// uint64, float, double each with `set_` / `get_` / `on_*_changed`, plus
13// `set_visible`, `set_enabled`, `on_click`, `platform_name`. That is the
14// right shape for the four shipped first-party adapters, which support most
15// of it — but it makes the floor for a *new* adapter 25 methods regardless
16// of ambition. An adapter that only drives labels and buttons still has to
17// write out every numeric channel by hand, and hand-roll its own
18// "unsupported" path for each one to satisfy contract L-39.
19//
20// This base implements every operation as the compliant unsupported path
21// (warn once through the framework's diagnostics boundary, then return a
22// safe default), so an author overrides only what the platform genuinely
23// supports:
24//
25// class MyAdapter final : public ViewAdapterBase {
26// public:
27// std::string_view platform_name() const noexcept override {
28// return "mytoolkit"; // still required — no sane default
29// }
30//
31// void set_text(IView& v, std::string_view t) override { ... }
32// std::string get_text(IView& v) override { ... }
33// Subscription on_click(IView& v, std::function<void()> cb) override { ... }
34// // everything else: inherited, warns if a binding reaches it
35// };
36//
37// `IViewAdapter` itself is unchanged — it is shipped and ABI-stable, and
38// the four first-party adapters continue to derive from it directly. This
39// base is purely additive.
40//
41// Verifying an adapter
42// --------------------
43// The shared conformance battery is installed with the public headers, so a
44// third-party adapter can check itself against the same suite the built-in
45// ones run:
46//
47// #include "aria/binding/testing/adapter_conformance.hpp"
48//
49// See docs/cookbook/08-writing-a-view-adapter.md.
50// ============================================================================
51
52#include "aria/abi/export.hpp"
54
55#include <cstdint>
56#include <functional>
57#include <string>
58#include <string_view>
59
60namespace aria::binding {
61
70public:
71 ~ViewAdapterBase() override;
72
73 // ── Text ───────────────────────────────────────────────────────────
74 void set_text(IView& v, std::string_view text) override;
75 [[nodiscard]] std::string get_text(IView& v) override;
77 std::function<void(std::string_view)> cb) override;
78
79 // ── Bool ───────────────────────────────────────────────────────────
80 void set_bool(IView& v, bool value) override;
81 [[nodiscard]] bool get_bool(IView& v) override;
83 std::function<void(bool)> cb) override;
84
85 // ── Int ────────────────────────────────────────────────────────────
86 void set_int(IView& v, int value) override;
87 [[nodiscard]] int get_int(IView& v) override;
89 std::function<void(int)> cb) override;
90
91 // ── Int64 ──────────────────────────────────────────────────────────
92 void set_int64(IView& v, std::int64_t value) override;
93 [[nodiscard]] std::int64_t get_int64(IView& v) override;
95 std::function<void(std::int64_t)> cb) override;
96
97 // ── UInt64 ─────────────────────────────────────────────────────────
98 void set_uint64(IView& v, std::uint64_t value) override;
99 [[nodiscard]] std::uint64_t get_uint64(IView& v) override;
101 std::function<void(std::uint64_t)> cb) override;
102
103 // ── Float ──────────────────────────────────────────────────────────
104 void set_float(IView& v, float value) override;
105 [[nodiscard]] float get_float(IView& v) override;
107 std::function<void(float)> cb) override;
108
109 // ── Double ─────────────────────────────────────────────────────────
110 void set_double(IView& v, double value) override;
111 [[nodiscard]] double get_double(IView& v) override;
113 std::function<void(double)> cb) override;
114
115 // ── Visible / Enabled ──────────────────────────────────────────────
116 void set_visible(IView& v, bool visible) override;
117 void set_enabled(IView& v, bool enabled) override;
118
119 // ── Click ──────────────────────────────────────────────────────────
120 Subscription on_click(IView& v, std::function<void()> cb) override;
121
122protected:
132 virtual void report_unsupported(std::string_view op, const IView& v) const;
133};
134
135} // namespace aria::binding
RAII handle to a single subscription.
Definition subscription.hpp:44
Abstract platform adapter — knows how to read/write/observe widgets.
Definition view_adapter.hpp:80
Abstract platform widget reference.
Definition view_adapter.hpp:28
Base class defaulting every IViewAdapter operation to the compliant "unsupported" behaviour required ...
Definition view_adapter_base.hpp:69
void set_float(IView &v, float value) override
Subscription on_int_changed(IView &v, std::function< void(int)> cb) override
double get_double(IView &v) override
float get_float(IView &v) override
Subscription on_double_changed(IView &v, std::function< void(double)> cb) override
void set_text(IView &v, std::string_view text) override
void set_int(IView &v, int value) override
int get_int(IView &v) override
std::uint64_t get_uint64(IView &v) override
void set_visible(IView &v, bool visible) override
std::string get_text(IView &v) override
Subscription on_text_changed(IView &v, std::function< void(std::string_view)> cb) override
bool get_bool(IView &v) override
Subscription on_float_changed(IView &v, std::function< void(float)> cb) override
void set_uint64(IView &v, std::uint64_t value) override
Subscription on_uint64_changed(IView &v, std::function< void(std::uint64_t)> cb) override
virtual void report_unsupported(std::string_view op, const IView &v) const
Report that op has no implementation in this adapter.
std::int64_t get_int64(IView &v) override
Subscription on_int64_changed(IView &v, std::function< void(std::int64_t)> cb) override
void set_int64(IView &v, std::int64_t value) override
void set_enabled(IView &v, bool enabled) override
Subscription on_click(IView &v, std::function< void()> cb) override
Subscription on_bool_changed(IView &v, std::function< void(bool)> cb) override
void set_bool(IView &v, bool value) override
void set_double(IView &v, double value) override
#define ARIA_BINDING_API
Definition export.hpp:39
Definition binding_engine.hpp:25