ph.h 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. namespace ph {
  9. struct now_t {
  10. };
  11. inline constexpr auto now = now_t();
  12. struct I {
  13. QString operator()(const QString &value) const { return value; };
  14. };
  15. template <typename P>
  16. using Result = decltype(std::declval<P>()(QString()));
  17. struct phrase {
  18. phrase(const QString &initial);
  19. template <std::size_t Size>
  20. phrase(const char (&initial)[Size])
  21. : phrase(QString::fromUtf8(initial, Size - 1)) {
  22. }
  23. explicit phrase(rpl::producer<QString> initial);
  24. template <typename P = I, typename = Result<P>>
  25. Result<P> operator()(ph::now_t, P p = P()) const {
  26. return p(value.current());
  27. };
  28. template <typename P = I, typename = Result<P>>
  29. rpl::producer<Result<P>> operator()(P p = P()) const {
  30. return value.value() | rpl::map(p);
  31. };
  32. rpl::variable<QString> value;
  33. };
  34. now_t start_phrase_count();
  35. now_t check_phrase_count(int count);
  36. namespace details {
  37. template <int Count>
  38. using phrase_value_array = std::array<
  39. std::pair<not_null<phrase*>, rpl::producer<QString>>,
  40. Count>;
  41. template <std::size_t Count>
  42. void set_values(phrase_value_array<Count> &&data) {
  43. for (auto &[single, value] : data) {
  44. single->value = std::move(value);
  45. }
  46. }
  47. } // namespace details
  48. } // namespace ph