| 1 |
#ifndef ICU4XPluralRules_HPP |
| 2 |
#define ICU4XPluralRules_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 "ICU4XPluralRules.h" |
| 13 |
|
| 14 |
class ICU4XDataProvider; |
| 15 |
class ICU4XLocale; |
| 16 |
class ICU4XPluralRules; |
| 17 |
#include "ICU4XError.hpp" |
| 18 |
class ICU4XPluralOperands; |
| 19 |
#include "ICU4XPluralCategory.hpp" |
| 20 |
struct ICU4XPluralCategories; |
| 21 |
|
| 22 |
/** |
| 23 |
* A destruction policy for using ICU4XPluralRules with std::unique_ptr. |
| 24 |
*/ |
| 25 |
struct ICU4XPluralRulesDeleter { |
| 26 |
void operator()(capi::ICU4XPluralRules* l) const noexcept { |
| 27 |
capi::ICU4XPluralRules_destroy(l); |
| 28 |
} |
| 29 |
}; |
| 30 |
|
| 31 |
/** |
| 32 |
* See the [Rust documentation for `PluralRules`](https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html) for more information. |
| 33 |
*/ |
| 34 |
class ICU4XPluralRules { |
| 35 |
public: |
| 36 |
|
| 37 |
/** |
| 38 |
* Construct an [`ICU4XPluralRules`] for the given locale, for cardinal numbers |
| 39 |
* |
| 40 |
* See the [Rust documentation for `try_new_cardinal`](https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html#method.try_new_cardinal) for more information. |
| 41 |
*/ |
| 42 |
static diplomat::result<ICU4XPluralRules, ICU4XError> create_cardinal(const ICU4XDataProvider& provider, const ICU4XLocale& locale); |
| 43 |
|
| 44 |
/** |
| 45 |
* Construct an [`ICU4XPluralRules`] for the given locale, for ordinal numbers |
| 46 |
* |
| 47 |
* See the [Rust documentation for `try_new_ordinal`](https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html#method.try_new_ordinal) for more information. |
| 48 |
*/ |
| 49 |
static diplomat::result<ICU4XPluralRules, ICU4XError> create_ordinal(const ICU4XDataProvider& provider, const ICU4XLocale& locale); |
| 50 |
|
| 51 |
/** |
| 52 |
* Get the category for a given number represented as operands |
| 53 |
* |
| 54 |
* See the [Rust documentation for `category_for`](https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html#method.category_for) for more information. |
| 55 |
*/ |
| 56 |
ICU4XPluralCategory category_for(const ICU4XPluralOperands& op) const; |
| 57 |
|
| 58 |
/** |
| 59 |
* Get all of the categories needed in the current locale |
| 60 |
* |
| 61 |
* See the [Rust documentation for `categories`](https://docs.rs/icu/latest/icu/plurals/struct.PluralRules.html#method.categories) for more information. |
| 62 |
*/ |
| 63 |
ICU4XPluralCategories categories() const; |
| 64 |
inline const capi::ICU4XPluralRules* AsFFI() const { return this->inner.get(); } |
| 65 |
inline capi::ICU4XPluralRules* AsFFIMut() { return this->inner.get(); } |
| 66 |
inline explicit ICU4XPluralRules(capi::ICU4XPluralRules* i) : inner(i) {} |
| 67 |
ICU4XPluralRules() = default; |
| 68 |
ICU4XPluralRules(ICU4XPluralRules&&) noexcept = default; |
| 69 |
ICU4XPluralRules& operator=(ICU4XPluralRules&& other) noexcept = default; |
| 70 |
private: |
| 71 |
std::unique_ptr<capi::ICU4XPluralRules, ICU4XPluralRulesDeleter> inner; |
| 72 |
}; |
| 73 |
|
| 74 |
#include "ICU4XDataProvider.hpp" |
| 75 |
#include "ICU4XLocale.hpp" |
| 76 |
#include "ICU4XPluralOperands.hpp" |
| 77 |
#include "ICU4XPluralCategories.hpp" |
| 78 |
|
| 79 |
inline diplomat::result<ICU4XPluralRules, ICU4XError> ICU4XPluralRules::create_cardinal(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { |
| 80 |
auto diplomat_result_raw_out_value = capi::ICU4XPluralRules_create_cardinal(provider.AsFFI(), locale.AsFFI()); |
| 81 |
diplomat::result<ICU4XPluralRules, ICU4XError> diplomat_result_out_value; |
| 82 |
if (diplomat_result_raw_out_value.is_ok) { |
| 83 |
diplomat_result_out_value = diplomat::Ok<ICU4XPluralRules>(ICU4XPluralRules(diplomat_result_raw_out_value.ok)); |
| 84 |
} else { |
| 85 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 86 |
} |
| 87 |
return diplomat_result_out_value; |
| 88 |
} |
| 89 |
inline diplomat::result<ICU4XPluralRules, ICU4XError> ICU4XPluralRules::create_ordinal(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { |
| 90 |
auto diplomat_result_raw_out_value = capi::ICU4XPluralRules_create_ordinal(provider.AsFFI(), locale.AsFFI()); |
| 91 |
diplomat::result<ICU4XPluralRules, ICU4XError> diplomat_result_out_value; |
| 92 |
if (diplomat_result_raw_out_value.is_ok) { |
| 93 |
diplomat_result_out_value = diplomat::Ok<ICU4XPluralRules>(ICU4XPluralRules(diplomat_result_raw_out_value.ok)); |
| 94 |
} else { |
| 95 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 96 |
} |
| 97 |
return diplomat_result_out_value; |
| 98 |
} |
| 99 |
inline ICU4XPluralCategory ICU4XPluralRules::category_for(const ICU4XPluralOperands& op) const { |
| 100 |
return static_cast<ICU4XPluralCategory>(capi::ICU4XPluralRules_category_for(this->inner.get(), op.AsFFI())); |
| 101 |
} |
| 102 |
inline ICU4XPluralCategories ICU4XPluralRules::categories() const { |
| 103 |
capi::ICU4XPluralCategories diplomat_raw_struct_out_value = capi::ICU4XPluralRules_categories(this->inner.get()); |
| 104 |
return ICU4XPluralCategories{ .zero = std::move(diplomat_raw_struct_out_value.zero), .one = std::move(diplomat_raw_struct_out_value.one), .two = std::move(diplomat_raw_struct_out_value.two), .few = std::move(diplomat_raw_struct_out_value.few), .many = std::move(diplomat_raw_struct_out_value.many), .other = std::move(diplomat_raw_struct_out_value.other) }; |
| 105 |
} |
| 106 |
#endif |