HikoGUI
A low latency retained GUI
Loading...
Searching...
No Matches
observed.hpp
1// Copyright Take Vos 2022.
2// Distributed under the Boost Software License, Version 1.0.
3// (See accompanying file LICENSE_1_0.txt or copy at https://www.boost.org/LICENSE_1_0.txt)
4
5#pragma once
6
7#include "group_ptr.hpp"
8#include "../macros.hpp"
9#include <memory>
10#include <vector>
11#include <string>
12
13hi_export_module(hikogui.observer : observed);
14
15hi_export namespace hi { inline namespace v1 {
16
21
22 void const * const ptr;
23 path_type const& path;
24};
25
30class observed_base : public enable_group_ptr<observed_base, void(observable_msg)> {
31public:
32 virtual ~observed_base() = default;
33 observed_base(observed_base const&) = delete;
34 observed_base(observed_base&&) = delete;
35 observed_base& operator=(observed_base const&) = delete;
36 observed_base& operator=(observed_base&&) = delete;
37 constexpr observed_base() noexcept = default;
38
43 [[nodiscard]] virtual void const *get() const noexcept = 0;
44
49 [[nodiscard]] virtual void *get() noexcept = 0;
50};
51
54public:
55 using value_type = T;
56 using path_type = observable_msg::path_type;
57
58 ~observed() = default;
59
64 template<typename... Args>
65 constexpr observed(Args&&...args) noexcept : observed_base(), _value(std::forward<Args>(args)...)
66 {
67 }
68
69 [[nodiscard]] void const *get() const noexcept override
70 {
71 return std::addressof(_value);
72 }
73
74 [[nodiscard]] void *get() noexcept override
75 {
76 return std::addressof(_value);
77 }
78
79private:
80 value_type _value;
81};
82
83}} // namespace hi::inline v1
STL namespace.
The HikoGUI namespace.
Definition array_generic.hpp:20
DOXYGEN BUG.
Definition algorithm_misc.hpp:20
Definition observed.hpp:17
std::vector< std::string > path_type
The type of the path used for notifying observers.
Definition observed.hpp:20
An abstract observed object.
Definition observed.hpp:30
virtual void const * get() const noexcept=0
Get a pointer to the current value.
Definition observed.hpp:53
void * get() noexcept override
Get a pointer to the current value.
Definition observed.hpp:74
void const * get() const noexcept override
Get a pointer to the current value.
Definition observed.hpp:69
constexpr observed(Args &&...args) noexcept
Construct the shared state and initialize the value.
Definition observed.hpp:65
T addressof(T... args)