Debian Codegraph @

intl/icu_capi/bindings/cpp/ICU4XCalendar.hpp

raw
1 #ifndef ICU4XCalendar_HPP
2 #define ICU4XCalendar_HPP
3 #include <stdint.h>
4 #include <stddef.h>
5 #include <stdbool.h>
6 #include <algorithm>
7 #include <memory>
8 #include <variant>
9 #include <optional>
10 #include "diplomat_runtime.hpp"
11
12 #include "ICU4XCalendar.h"
13
14 class ICU4XDataProvider;
15 class ICU4XLocale;
16 class ICU4XCalendar;
17 #include "ICU4XError.hpp"
18 #include "ICU4XAnyCalendarKind.hpp"
19
20 /**
21 * A destruction policy for using ICU4XCalendar with std::unique_ptr.
22 */
23 struct ICU4XCalendarDeleter {
24 void operator()(capi::ICU4XCalendar* l) const noexcept {
25 capi::ICU4XCalendar_destroy(l);
26 }
27 };
28
29 /**
30 * See the [Rust documentation for `AnyCalendar`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html) for more information.
31 */
32 class ICU4XCalendar {
33 public:
34
35 /**
36 * Creates a new [`ICU4XCalendar`] from the specified date and time.
37 *
38 * See the [Rust documentation for `new_for_locale`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html#method.new_for_locale) for more information.
39 */
40 static diplomat::result<ICU4XCalendar, ICU4XError> create_for_locale(const ICU4XDataProvider& provider, const ICU4XLocale& locale);
41
42 /**
43 * Creates a new [`ICU4XCalendar`] from the specified date and time.
44 *
45 * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html#method.new) for more information.
46 */
47 static diplomat::result<ICU4XCalendar, ICU4XError> create_for_kind(const ICU4XDataProvider& provider, ICU4XAnyCalendarKind kind);
48
49 /**
50 * Returns the kind of this calendar
51 *
52 * See the [Rust documentation for `kind`](https://docs.rs/icu/latest/icu/calendar/enum.AnyCalendar.html#method.kind) for more information.
53 */
54 ICU4XAnyCalendarKind kind() const;
55 inline const capi::ICU4XCalendar* AsFFI() const { return this->inner.get(); }
56 inline capi::ICU4XCalendar* AsFFIMut() { return this->inner.get(); }
57 inline explicit ICU4XCalendar(capi::ICU4XCalendar* i) : inner(i) {}
58 ICU4XCalendar() = default;
59 ICU4XCalendar(ICU4XCalendar&&) noexcept = default;
60 ICU4XCalendar& operator=(ICU4XCalendar&& other) noexcept = default;
61 private:
62 std::unique_ptr<capi::ICU4XCalendar, ICU4XCalendarDeleter> inner;
63 };
64
65 #include "ICU4XDataProvider.hpp"
66 #include "ICU4XLocale.hpp"
67
68 inline diplomat::result<ICU4XCalendar, ICU4XError> ICU4XCalendar::create_for_locale(const ICU4XDataProvider& provider, const ICU4XLocale& locale) {
69 auto diplomat_result_raw_out_value = capi::ICU4XCalendar_create_for_locale(provider.AsFFI(), locale.AsFFI());
70 diplomat::result<ICU4XCalendar, ICU4XError> diplomat_result_out_value;
71 if (diplomat_result_raw_out_value.is_ok) {
72 diplomat_result_out_value = diplomat::Ok<ICU4XCalendar>(ICU4XCalendar(diplomat_result_raw_out_value.ok));
73 } else {
74 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
75 }
76 return diplomat_result_out_value;
77 }
78 inline diplomat::result<ICU4XCalendar, ICU4XError> ICU4XCalendar::create_for_kind(const ICU4XDataProvider& provider, ICU4XAnyCalendarKind kind) {
79 auto diplomat_result_raw_out_value = capi::ICU4XCalendar_create_for_kind(provider.AsFFI(), static_cast<capi::ICU4XAnyCalendarKind>(kind));
80 diplomat::result<ICU4XCalendar, ICU4XError> diplomat_result_out_value;
81 if (diplomat_result_raw_out_value.is_ok) {
82 diplomat_result_out_value = diplomat::Ok<ICU4XCalendar>(ICU4XCalendar(diplomat_result_raw_out_value.ok));
83 } else {
84 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
85 }
86 return diplomat_result_out_value;
87 }
88 inline ICU4XAnyCalendarKind ICU4XCalendar::kind() const {
89 return static_cast<ICU4XAnyCalendarKind>(capi::ICU4XCalendar_kind(this->inner.get()));
90 }
91 #endif