| 1 |
#ifndef ICU4XPluralOperands_HPP |
| 2 |
#define ICU4XPluralOperands_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 "ICU4XPluralOperands.h" |
| 13 |
|
| 14 |
class ICU4XPluralOperands; |
| 15 |
#include "ICU4XError.hpp" |
| 16 |
class ICU4XFixedDecimal; |
| 17 |
|
| 18 |
/** |
| 19 |
* A destruction policy for using ICU4XPluralOperands with std::unique_ptr. |
| 20 |
*/ |
| 21 |
struct ICU4XPluralOperandsDeleter { |
| 22 |
void operator()(capi::ICU4XPluralOperands* l) const noexcept { |
| 23 |
capi::ICU4XPluralOperands_destroy(l); |
| 24 |
} |
| 25 |
}; |
| 26 |
|
| 27 |
/** |
| 28 |
* See the [Rust documentation for `PluralOperands`](https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html) for more information. |
| 29 |
*/ |
| 30 |
class ICU4XPluralOperands { |
| 31 |
public: |
| 32 |
|
| 33 |
/** |
| 34 |
* Construct for a given string representing a number |
| 35 |
* |
| 36 |
* See the [Rust documentation for `from_str`](https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html#method.from_str) for more information. |
| 37 |
*/ |
| 38 |
static diplomat::result<ICU4XPluralOperands, ICU4XError> create_from_string(const std::string_view s); |
| 39 |
|
| 40 |
/** |
| 41 |
* Construct from a FixedDecimal |
| 42 |
* |
| 43 |
* Retains at most 18 digits each from the integer and fraction parts. |
| 44 |
*/ |
| 45 |
static ICU4XPluralOperands create_from_fixed_decimal(const ICU4XFixedDecimal& x); |
| 46 |
inline const capi::ICU4XPluralOperands* AsFFI() const { return this->inner.get(); } |
| 47 |
inline capi::ICU4XPluralOperands* AsFFIMut() { return this->inner.get(); } |
| 48 |
inline explicit ICU4XPluralOperands(capi::ICU4XPluralOperands* i) : inner(i) {} |
| 49 |
ICU4XPluralOperands() = default; |
| 50 |
ICU4XPluralOperands(ICU4XPluralOperands&&) noexcept = default; |
| 51 |
ICU4XPluralOperands& operator=(ICU4XPluralOperands&& other) noexcept = default; |
| 52 |
private: |
| 53 |
std::unique_ptr<capi::ICU4XPluralOperands, ICU4XPluralOperandsDeleter> inner; |
| 54 |
}; |
| 55 |
|
| 56 |
#include "ICU4XFixedDecimal.hpp" |
| 57 |
|
| 58 |
inline diplomat::result<ICU4XPluralOperands, ICU4XError> ICU4XPluralOperands::create_from_string(const std::string_view s) { |
| 59 |
auto diplomat_result_raw_out_value = capi::ICU4XPluralOperands_create_from_string(s.data(), s.size()); |
| 60 |
diplomat::result<ICU4XPluralOperands, ICU4XError> diplomat_result_out_value; |
| 61 |
if (diplomat_result_raw_out_value.is_ok) { |
| 62 |
diplomat_result_out_value = diplomat::Ok<ICU4XPluralOperands>(ICU4XPluralOperands(diplomat_result_raw_out_value.ok)); |
| 63 |
} else { |
| 64 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 65 |
} |
| 66 |
return diplomat_result_out_value; |
| 67 |
} |
| 68 |
inline ICU4XPluralOperands ICU4XPluralOperands::create_from_fixed_decimal(const ICU4XFixedDecimal& x) { |
| 69 |
return ICU4XPluralOperands(capi::ICU4XPluralOperands_create_from_fixed_decimal(x.AsFFI())); |
| 70 |
} |
| 71 |
#endif |