Debian Codegraph @

intl/icu_capi/bindings/cpp/ICU4XIanaToBcp47Mapper.hpp

raw
1 #ifndef ICU4XIanaToBcp47Mapper_HPP
2 #define ICU4XIanaToBcp47Mapper_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 "ICU4XIanaToBcp47Mapper.h"
13
14 class ICU4XDataProvider;
15 class ICU4XIanaToBcp47Mapper;
16 #include "ICU4XError.hpp"
17
18 /**
19 * A destruction policy for using ICU4XIanaToBcp47Mapper with std::unique_ptr.
20 */
21 struct ICU4XIanaToBcp47MapperDeleter {
22 void operator()(capi::ICU4XIanaToBcp47Mapper* l) const noexcept {
23 capi::ICU4XIanaToBcp47Mapper_destroy(l);
24 }
25 };
26
27 /**
28 * An object capable of mapping from an IANA time zone ID to a BCP-47 ID.
29 *
30 * This can be used via `try_set_iana_time_zone_id()` on [`ICU4XCustomTimeZone`].
31 *
32 * [`ICU4XCustomTimeZone`]: crate::timezone::ffi::ICU4XCustomTimeZone
33 *
34 * See the [Rust documentation for `IanaToBcp47Mapper`](https://docs.rs/icu/latest/icu/timezone/struct.IanaToBcp47Mapper.html) for more information.
35 */
36 class ICU4XIanaToBcp47Mapper {
37 public:
38
39 /**
40 * See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.IanaToBcp47Mapper.html#method.new) for more information.
41 */
42 static diplomat::result<ICU4XIanaToBcp47Mapper, ICU4XError> create(const ICU4XDataProvider& provider);
43
44 /**
45 * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/timezone/struct.IanaToBcp47MapperBorrowed.html#method.get) for more information.
46 *
47 * See the [Rust documentation for `iana_to_bcp47`](https://docs.rs/icu/latest/icu/timezone/struct.IanaBcp47RoundTripMapperBorrowed.html#method.iana_to_bcp47) for more information.
48 */
49 template<typename W> diplomat::result<std::monostate, ICU4XError> get_to_writeable(const std::string_view value, W& write) const;
50
51 /**
52 * See the [Rust documentation for `get`](https://docs.rs/icu/latest/icu/timezone/struct.IanaToBcp47MapperBorrowed.html#method.get) for more information.
53 *
54 * See the [Rust documentation for `iana_to_bcp47`](https://docs.rs/icu/latest/icu/timezone/struct.IanaBcp47RoundTripMapperBorrowed.html#method.iana_to_bcp47) for more information.
55 */
56 diplomat::result<std::string, ICU4XError> get(const std::string_view value) const;
57 inline const capi::ICU4XIanaToBcp47Mapper* AsFFI() const { return this->inner.get(); }
58 inline capi::ICU4XIanaToBcp47Mapper* AsFFIMut() { return this->inner.get(); }
59 inline explicit ICU4XIanaToBcp47Mapper(capi::ICU4XIanaToBcp47Mapper* i) : inner(i) {}
60 ICU4XIanaToBcp47Mapper() = default;
61 ICU4XIanaToBcp47Mapper(ICU4XIanaToBcp47Mapper&&) noexcept = default;
62 ICU4XIanaToBcp47Mapper& operator=(ICU4XIanaToBcp47Mapper&& other) noexcept = default;
63 private:
64 std::unique_ptr<capi::ICU4XIanaToBcp47Mapper, ICU4XIanaToBcp47MapperDeleter> inner;
65 };
66
67 #include "ICU4XDataProvider.hpp"
68
69 inline diplomat::result<ICU4XIanaToBcp47Mapper, ICU4XError> ICU4XIanaToBcp47Mapper::create(const ICU4XDataProvider& provider) {
70 auto diplomat_result_raw_out_value = capi::ICU4XIanaToBcp47Mapper_create(provider.AsFFI());
71 diplomat::result<ICU4XIanaToBcp47Mapper, ICU4XError> diplomat_result_out_value;
72 if (diplomat_result_raw_out_value.is_ok) {
73 diplomat_result_out_value = diplomat::Ok<ICU4XIanaToBcp47Mapper>(ICU4XIanaToBcp47Mapper(diplomat_result_raw_out_value.ok));
74 } else {
75 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
76 }
77 return diplomat_result_out_value;
78 }
79 template<typename W> inline diplomat::result<std::monostate, ICU4XError> ICU4XIanaToBcp47Mapper::get_to_writeable(const std::string_view value, W& write) const {
80 capi::DiplomatWriteable write_writer = diplomat::WriteableTrait<W>::Construct(write);
81 auto diplomat_result_raw_out_value = capi::ICU4XIanaToBcp47Mapper_get(this->inner.get(), value.data(), value.size(), &write_writer);
82 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
83 if (diplomat_result_raw_out_value.is_ok) {
84 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
85 } else {
86 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
87 }
88 return diplomat_result_out_value;
89 }
90 inline diplomat::result<std::string, ICU4XError> ICU4XIanaToBcp47Mapper::get(const std::string_view value) const {
91 std::string diplomat_writeable_string;
92 capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string);
93 auto diplomat_result_raw_out_value = capi::ICU4XIanaToBcp47Mapper_get(this->inner.get(), value.data(), value.size(), &diplomat_writeable_out);
94 diplomat::result<std::monostate, ICU4XError> diplomat_result_out_value;
95 if (diplomat_result_raw_out_value.is_ok) {
96 diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate());
97 } else {
98 diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
99 }
100 return diplomat_result_out_value.replace_ok(std::move(diplomat_writeable_string));
101 }
102 #endif