Debian Codegraph @

intl/icu_capi/bindings/cpp/ICU4XBcp47ToIanaMapper.hpp

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