1 // This file is part of Desktop App Toolkit,
2 // a set of libraries for developing nice desktop applications.
3 //
4 // For license and copyright information please follow this link:
5 // https://github.com/desktop-app/legal/blob/master/LEGAL
6 //
7 #pragma once
8 
9 namespace ph {
10 
11 struct now_t {
12 };
13 
14 inline constexpr auto now = now_t();
15 
16 struct I {
operatorI17 	QString operator()(const QString &value) const { return value; };
18 };
19 
20 template <typename P>
21 using Result = decltype(std::declval<P>()(QString()));
22 
23 struct phrase {
24 	phrase(const QString &initial);
25 	template <std::size_t Size>
phrasephrase26 	phrase(const char (&initial)[Size])
27 	: phrase(QString::fromUtf8(initial, Size - 1)) {
28 	}
29 	explicit phrase(rpl::producer<QString> initial);
30 
31 	template <typename P = I, typename = Result<P>>
operatorphrase32 	Result<P> operator()(ph::now_t, P p = P()) const {
33 		return p(value.current());
34 	};
35 	template <typename P = I, typename = Result<P>>
operatorphrase36 	rpl::producer<Result<P>> operator()(P p = P()) const {
37 		return value.value() | rpl::map(p);
38 	};
39 
40 	rpl::variable<QString> value;
41 };
42 
43 now_t start_phrase_count();
44 now_t check_phrase_count(int count);
45 
46 namespace details {
47 
48 template <int Count>
49 using phrase_value_array = std::array<
50 	std::pair<not_null<phrase*>, rpl::producer<QString>>,
51 	Count>;
52 
53 template <std::size_t Count>
set_values(phrase_value_array<Count> && data)54 void set_values(phrase_value_array<Count> &&data) {
55 	for (auto &[single, value] : data) {
56 		single->value = std::move(value);
57 	}
58 }
59 
60 } // namespace details
61 } // namespace ph
62