| 1 |
#ifndef ICU4XMetazoneCalculator_HPP |
| 2 |
#define ICU4XMetazoneCalculator_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 "ICU4XMetazoneCalculator.h" |
| 13 |
|
| 14 |
class ICU4XDataProvider; |
| 15 |
class ICU4XMetazoneCalculator; |
| 16 |
#include "ICU4XError.hpp" |
| 17 |
|
| 18 |
/** |
| 19 |
* A destruction policy for using ICU4XMetazoneCalculator with std::unique_ptr. |
| 20 |
*/ |
| 21 |
struct ICU4XMetazoneCalculatorDeleter { |
| 22 |
void operator()(capi::ICU4XMetazoneCalculator* l) const noexcept { |
| 23 |
capi::ICU4XMetazoneCalculator_destroy(l); |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
/** |
| 28 |
* An object capable of computing the metazone from a timezone. |
| 29 |
* |
| 30 |
* This can be used via `maybe_calculate_metazone()` on [`ICU4XCustomTimeZone`]. |
| 31 |
* |
| 32 |
* [`ICU4XCustomTimeZone`]: crate::timezone::ffi::ICU4XCustomTimeZone |
| 33 |
* |
| 34 |
* See the [Rust documentation for `MetazoneCalculator`](https://docs.rs/icu/latest/icu/timezone/struct.MetazoneCalculator.html) for more information. |
| 35 |
*/ |
| 36 |
class ICU4XMetazoneCalculator { |
| 37 |
public: |
| 38 |
|
| 39 |
/** |
| 40 |
* See the [Rust documentation for `new`](https://docs.rs/icu/latest/icu/timezone/struct.MetazoneCalculator.html#method.new) for more information. |
| 41 |
*/ |
| 42 |
static diplomat::result<ICU4XMetazoneCalculator, ICU4XError> create(const ICU4XDataProvider& provider); |
| 43 |
inline const capi::ICU4XMetazoneCalculator* AsFFI() const { return this->inner.get(); } |
| 44 |
inline capi::ICU4XMetazoneCalculator* AsFFIMut() { return this->inner.get(); } |
| 45 |
inline explicit ICU4XMetazoneCalculator(capi::ICU4XMetazoneCalculator* i) : inner(i) {} |
| 46 |
ICU4XMetazoneCalculator() = default; |
| 47 |
ICU4XMetazoneCalculator(ICU4XMetazoneCalculator&&) noexcept = default; |
| 48 |
ICU4XMetazoneCalculator& operator=(ICU4XMetazoneCalculator&& other) noexcept = default; |
| 49 |
private: |
| 50 |
std::unique_ptr<capi::ICU4XMetazoneCalculator, ICU4XMetazoneCalculatorDeleter> inner; |
| 51 |
}; |
| 52 |
|
| 53 |
#include "ICU4XDataProvider.hpp" |
| 54 |
|
| 55 |
inline diplomat::result<ICU4XMetazoneCalculator, ICU4XError> ICU4XMetazoneCalculator::create(const ICU4XDataProvider& provider) { |
| 56 |
auto diplomat_result_raw_out_value = capi::ICU4XMetazoneCalculator_create(provider.AsFFI()); |
| 57 |
diplomat::result<ICU4XMetazoneCalculator, ICU4XError> diplomat_result_out_value; |
| 58 |
if (diplomat_result_raw_out_value.is_ok) { |
| 59 |
diplomat_result_out_value = diplomat::Ok<ICU4XMetazoneCalculator>(ICU4XMetazoneCalculator(diplomat_result_raw_out_value.ok)); |
| 60 |
} else { |
| 61 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 62 |
} |
| 63 |
return diplomat_result_out_value; |
| 64 |
} |
| 65 |
#endif |