| 1 |
#ifndef ICU4XFixedDecimal_HPP |
| 2 |
#define ICU4XFixedDecimal_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 "ICU4XFixedDecimal.h" |
| 13 |
|
| 14 |
class ICU4XFixedDecimal; |
| 15 |
#include "ICU4XError.hpp" |
| 16 |
#include "ICU4XFixedDecimalSign.hpp" |
| 17 |
#include "ICU4XFixedDecimalSignDisplay.hpp" |
| 18 |
#include "ICU4XRoundingIncrement.hpp" |
| 19 |
|
| 20 |
/** |
| 21 |
* A destruction policy for using ICU4XFixedDecimal with std::unique_ptr. |
| 22 |
*/ |
| 23 |
struct ICU4XFixedDecimalDeleter { |
| 24 |
void operator()(capi::ICU4XFixedDecimal* l) const noexcept { |
| 25 |
capi::ICU4XFixedDecimal_destroy(l); |
| 26 |
} |
| 27 |
}; |
| 28 |
|
| 29 |
/** |
| 30 |
* See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information. |
| 31 |
*/ |
| 32 |
class ICU4XFixedDecimal { |
| 33 |
public: |
| 34 |
|
| 35 |
/** |
| 36 |
* Construct an [`ICU4XFixedDecimal`] from an integer. |
| 37 |
* |
| 38 |
* See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information. |
| 39 |
*/ |
| 40 |
static ICU4XFixedDecimal create_from_i32(int32_t v); |
| 41 |
|
| 42 |
/** |
| 43 |
* Construct an [`ICU4XFixedDecimal`] from an integer. |
| 44 |
* |
| 45 |
* See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information. |
| 46 |
*/ |
| 47 |
static ICU4XFixedDecimal create_from_u32(uint32_t v); |
| 48 |
|
| 49 |
/** |
| 50 |
* Construct an [`ICU4XFixedDecimal`] from an integer. |
| 51 |
* |
| 52 |
* See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information. |
| 53 |
*/ |
| 54 |
static ICU4XFixedDecimal create_from_i64(int64_t v); |
| 55 |
|
| 56 |
/** |
| 57 |
* Construct an [`ICU4XFixedDecimal`] from an integer. |
| 58 |
* |
| 59 |
* See the [Rust documentation for `FixedDecimal`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html) for more information. |
| 60 |
*/ |
| 61 |
static ICU4XFixedDecimal create_from_u64(uint64_t v); |
| 62 |
|
| 63 |
/** |
| 64 |
* Construct an [`ICU4XFixedDecimal`] from an integer-valued float |
| 65 |
* |
| 66 |
* See the [Rust documentation for `try_from_f64`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.try_from_f64) for more information. |
| 67 |
* |
| 68 |
* See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. |
| 69 |
*/ |
| 70 |
static diplomat::result<ICU4XFixedDecimal, ICU4XError> create_from_f64_with_integer_precision(double f); |
| 71 |
|
| 72 |
/** |
| 73 |
* Construct an [`ICU4XFixedDecimal`] from an float, with a given power of 10 for the lower magnitude |
| 74 |
* |
| 75 |
* See the [Rust documentation for `try_from_f64`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.try_from_f64) for more information. |
| 76 |
* |
| 77 |
* See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. |
| 78 |
*/ |
| 79 |
static diplomat::result<ICU4XFixedDecimal, ICU4XError> create_from_f64_with_lower_magnitude(double f, int16_t magnitude); |
| 80 |
|
| 81 |
/** |
| 82 |
* Construct an [`ICU4XFixedDecimal`] from an float, for a given number of significant digits |
| 83 |
* |
| 84 |
* See the [Rust documentation for `try_from_f64`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.try_from_f64) for more information. |
| 85 |
* |
| 86 |
* See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. |
| 87 |
*/ |
| 88 |
static diplomat::result<ICU4XFixedDecimal, ICU4XError> create_from_f64_with_significant_digits(double f, uint8_t digits); |
| 89 |
|
| 90 |
/** |
| 91 |
* Construct an [`ICU4XFixedDecimal`] from an float, with enough digits to recover |
| 92 |
* the original floating point in IEEE 754 without needing trailing zeros |
| 93 |
* |
| 94 |
* See the [Rust documentation for `try_from_f64`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.try_from_f64) for more information. |
| 95 |
* |
| 96 |
* See the [Rust documentation for `FloatPrecision`](https://docs.rs/fixed_decimal/latest/fixed_decimal/enum.FloatPrecision.html) for more information. |
| 97 |
*/ |
| 98 |
static diplomat::result<ICU4XFixedDecimal, ICU4XError> create_from_f64_with_floating_precision(double f); |
| 99 |
|
| 100 |
/** |
| 101 |
* Construct an [`ICU4XFixedDecimal`] from a string. |
| 102 |
* |
| 103 |
* See the [Rust documentation for `from_str`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.from_str) for more information. |
| 104 |
*/ |
| 105 |
static diplomat::result<ICU4XFixedDecimal, ICU4XError> create_from_string(const std::string_view v); |
| 106 |
|
| 107 |
/** |
| 108 |
* See the [Rust documentation for `digit_at`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.digit_at) for more information. |
| 109 |
*/ |
| 110 |
uint8_t digit_at(int16_t magnitude) const; |
| 111 |
|
| 112 |
/** |
| 113 |
* See the [Rust documentation for `magnitude_range`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.magnitude_range) for more information. |
| 114 |
*/ |
| 115 |
int16_t magnitude_start() const; |
| 116 |
|
| 117 |
/** |
| 118 |
* See the [Rust documentation for `magnitude_range`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.magnitude_range) for more information. |
| 119 |
*/ |
| 120 |
int16_t magnitude_end() const; |
| 121 |
|
| 122 |
/** |
| 123 |
* See the [Rust documentation for `nonzero_magnitude_start`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.nonzero_magnitude_start) for more information. |
| 124 |
*/ |
| 125 |
int16_t nonzero_magnitude_start() const; |
| 126 |
|
| 127 |
/** |
| 128 |
* See the [Rust documentation for `nonzero_magnitude_end`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.nonzero_magnitude_end) for more information. |
| 129 |
*/ |
| 130 |
int16_t nonzero_magnitude_end() const; |
| 131 |
|
| 132 |
/** |
| 133 |
* See the [Rust documentation for `is_zero`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.is_zero) for more information. |
| 134 |
*/ |
| 135 |
bool is_zero() const; |
| 136 |
|
| 137 |
/** |
| 138 |
* Multiply the [`ICU4XFixedDecimal`] by a given power of ten. |
| 139 |
* |
| 140 |
* See the [Rust documentation for `multiply_pow10`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.multiply_pow10) for more information. |
| 141 |
*/ |
| 142 |
void multiply_pow10(int16_t power); |
| 143 |
|
| 144 |
/** |
| 145 |
* See the [Rust documentation for `sign`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.sign) for more information. |
| 146 |
*/ |
| 147 |
ICU4XFixedDecimalSign sign() const; |
| 148 |
|
| 149 |
/** |
| 150 |
* Set the sign of the [`ICU4XFixedDecimal`]. |
| 151 |
* |
| 152 |
* See the [Rust documentation for `set_sign`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.set_sign) for more information. |
| 153 |
*/ |
| 154 |
void set_sign(ICU4XFixedDecimalSign sign); |
| 155 |
|
| 156 |
/** |
| 157 |
* See the [Rust documentation for `apply_sign_display`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.apply_sign_display) for more information. |
| 158 |
*/ |
| 159 |
void apply_sign_display(ICU4XFixedDecimalSignDisplay sign_display); |
| 160 |
|
| 161 |
/** |
| 162 |
* See the [Rust documentation for `trim_start`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.trim_start) for more information. |
| 163 |
*/ |
| 164 |
void trim_start(); |
| 165 |
|
| 166 |
/** |
| 167 |
* See the [Rust documentation for `trim_end`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.trim_end) for more information. |
| 168 |
*/ |
| 169 |
void trim_end(); |
| 170 |
|
| 171 |
/** |
| 172 |
* Zero-pad the [`ICU4XFixedDecimal`] on the left to a particular position |
| 173 |
* |
| 174 |
* See the [Rust documentation for `pad_start`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.pad_start) for more information. |
| 175 |
*/ |
| 176 |
void pad_start(int16_t position); |
| 177 |
|
| 178 |
/** |
| 179 |
* Zero-pad the [`ICU4XFixedDecimal`] on the right to a particular position |
| 180 |
* |
| 181 |
* See the [Rust documentation for `pad_end`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.pad_end) for more information. |
| 182 |
*/ |
| 183 |
void pad_end(int16_t position); |
| 184 |
|
| 185 |
/** |
| 186 |
* Truncate the [`ICU4XFixedDecimal`] on the left to a particular position, deleting digits if necessary. This is useful for, e.g. abbreviating years |
| 187 |
* ("2022" -> "22") |
| 188 |
* |
| 189 |
* See the [Rust documentation for `set_max_position`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.set_max_position) for more information. |
| 190 |
*/ |
| 191 |
void set_max_position(int16_t position); |
| 192 |
|
| 193 |
/** |
| 194 |
* See the [Rust documentation for `trunc`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.trunc) for more information. |
| 195 |
*/ |
| 196 |
void trunc(int16_t position); |
| 197 |
|
| 198 |
/** |
| 199 |
* See the [Rust documentation for `trunc_to_increment`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.trunc_to_increment) for more information. |
| 200 |
*/ |
| 201 |
void trunc_to_increment(int16_t position, ICU4XRoundingIncrement increment); |
| 202 |
|
| 203 |
/** |
| 204 |
* See the [Rust documentation for `half_trunc`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_trunc) for more information. |
| 205 |
*/ |
| 206 |
void half_trunc(int16_t position); |
| 207 |
|
| 208 |
/** |
| 209 |
* See the [Rust documentation for `half_trunc_to_increment`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_trunc_to_increment) for more information. |
| 210 |
*/ |
| 211 |
void half_trunc_to_increment(int16_t position, ICU4XRoundingIncrement increment); |
| 212 |
|
| 213 |
/** |
| 214 |
* See the [Rust documentation for `expand`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.expand) for more information. |
| 215 |
*/ |
| 216 |
void expand(int16_t position); |
| 217 |
|
| 218 |
/** |
| 219 |
* See the [Rust documentation for `expand_to_increment`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.expand_to_increment) for more information. |
| 220 |
*/ |
| 221 |
void expand_to_increment(int16_t position, ICU4XRoundingIncrement increment); |
| 222 |
|
| 223 |
/** |
| 224 |
* See the [Rust documentation for `half_expand`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_expand) for more information. |
| 225 |
*/ |
| 226 |
void half_expand(int16_t position); |
| 227 |
|
| 228 |
/** |
| 229 |
* See the [Rust documentation for `half_expand_to_increment`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_expand_to_increment) for more information. |
| 230 |
*/ |
| 231 |
void half_expand_to_increment(int16_t position, ICU4XRoundingIncrement increment); |
| 232 |
|
| 233 |
/** |
| 234 |
* See the [Rust documentation for `ceil`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.ceil) for more information. |
| 235 |
*/ |
| 236 |
void ceil(int16_t position); |
| 237 |
|
| 238 |
/** |
| 239 |
* See the [Rust documentation for `ceil_to_increment`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.ceil_to_increment) for more information. |
| 240 |
*/ |
| 241 |
void ceil_to_increment(int16_t position, ICU4XRoundingIncrement increment); |
| 242 |
|
| 243 |
/** |
| 244 |
* See the [Rust documentation for `half_ceil`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_ceil) for more information. |
| 245 |
*/ |
| 246 |
void half_ceil(int16_t position); |
| 247 |
|
| 248 |
/** |
| 249 |
* See the [Rust documentation for `half_ceil_to_increment`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_ceil_to_increment) for more information. |
| 250 |
*/ |
| 251 |
void half_ceil_to_increment(int16_t position, ICU4XRoundingIncrement increment); |
| 252 |
|
| 253 |
/** |
| 254 |
* See the [Rust documentation for `floor`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.floor) for more information. |
| 255 |
*/ |
| 256 |
void floor(int16_t position); |
| 257 |
|
| 258 |
/** |
| 259 |
* See the [Rust documentation for `floor_to_increment`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.floor_to_increment) for more information. |
| 260 |
*/ |
| 261 |
void floor_to_increment(int16_t position, ICU4XRoundingIncrement increment); |
| 262 |
|
| 263 |
/** |
| 264 |
* See the [Rust documentation for `half_floor`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_floor) for more information. |
| 265 |
*/ |
| 266 |
void half_floor(int16_t position); |
| 267 |
|
| 268 |
/** |
| 269 |
* See the [Rust documentation for `half_floor_to_increment`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_floor_to_increment) for more information. |
| 270 |
*/ |
| 271 |
void half_floor_to_increment(int16_t position, ICU4XRoundingIncrement increment); |
| 272 |
|
| 273 |
/** |
| 274 |
* See the [Rust documentation for `half_even`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_even) for more information. |
| 275 |
*/ |
| 276 |
void half_even(int16_t position); |
| 277 |
|
| 278 |
/** |
| 279 |
* See the [Rust documentation for `half_even_to_increment`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.half_even_to_increment) for more information. |
| 280 |
*/ |
| 281 |
void half_even_to_increment(int16_t position, ICU4XRoundingIncrement increment); |
| 282 |
|
| 283 |
/** |
| 284 |
* Concatenates `other` to the end of `self`. |
| 285 |
* |
| 286 |
* If successful, `other` will be set to 0 and a successful status is returned. |
| 287 |
* |
| 288 |
* If not successful, `other` will be unchanged and an error is returned. |
| 289 |
* |
| 290 |
* See the [Rust documentation for `concatenate_end`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.concatenate_end) for more information. |
| 291 |
*/ |
| 292 |
diplomat::result<std::monostate, std::monostate> concatenate_end(ICU4XFixedDecimal& other); |
| 293 |
|
| 294 |
/** |
| 295 |
* Format the [`ICU4XFixedDecimal`] as a string. |
| 296 |
* |
| 297 |
* See the [Rust documentation for `write_to`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.write_to) for more information. |
| 298 |
*/ |
| 299 |
template<typename W> void to_string_to_writeable(W& to) const; |
| 300 |
|
| 301 |
/** |
| 302 |
* Format the [`ICU4XFixedDecimal`] as a string. |
| 303 |
* |
| 304 |
* See the [Rust documentation for `write_to`](https://docs.rs/fixed_decimal/latest/fixed_decimal/struct.FixedDecimal.html#method.write_to) for more information. |
| 305 |
*/ |
| 306 |
std::string to_string() const; |
| 307 |
inline const capi::ICU4XFixedDecimal* AsFFI() const { return this->inner.get(); } |
| 308 |
inline capi::ICU4XFixedDecimal* AsFFIMut() { return this->inner.get(); } |
| 309 |
inline explicit ICU4XFixedDecimal(capi::ICU4XFixedDecimal* i) : inner(i) {} |
| 310 |
ICU4XFixedDecimal() = default; |
| 311 |
ICU4XFixedDecimal(ICU4XFixedDecimal&&) noexcept = default; |
| 312 |
ICU4XFixedDecimal& operator=(ICU4XFixedDecimal&& other) noexcept = default; |
| 313 |
private: |
| 314 |
std::unique_ptr<capi::ICU4XFixedDecimal, ICU4XFixedDecimalDeleter> inner; |
| 315 |
}; |
| 316 |
|
| 317 |
|
| 318 |
inline ICU4XFixedDecimal ICU4XFixedDecimal::create_from_i32(int32_t v) { |
| 319 |
return ICU4XFixedDecimal(capi::ICU4XFixedDecimal_create_from_i32(v)); |
| 320 |
} |
| 321 |
inline ICU4XFixedDecimal ICU4XFixedDecimal::create_from_u32(uint32_t v) { |
| 322 |
return ICU4XFixedDecimal(capi::ICU4XFixedDecimal_create_from_u32(v)); |
| 323 |
} |
| 324 |
inline ICU4XFixedDecimal ICU4XFixedDecimal::create_from_i64(int64_t v) { |
| 325 |
return ICU4XFixedDecimal(capi::ICU4XFixedDecimal_create_from_i64(v)); |
| 326 |
} |
| 327 |
inline ICU4XFixedDecimal ICU4XFixedDecimal::create_from_u64(uint64_t v) { |
| 328 |
return ICU4XFixedDecimal(capi::ICU4XFixedDecimal_create_from_u64(v)); |
| 329 |
} |
| 330 |
inline diplomat::result<ICU4XFixedDecimal, ICU4XError> ICU4XFixedDecimal::create_from_f64_with_integer_precision(double f) { |
| 331 |
auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimal_create_from_f64_with_integer_precision(f); |
| 332 |
diplomat::result<ICU4XFixedDecimal, ICU4XError> diplomat_result_out_value; |
| 333 |
if (diplomat_result_raw_out_value.is_ok) { |
| 334 |
diplomat_result_out_value = diplomat::Ok<ICU4XFixedDecimal>(ICU4XFixedDecimal(diplomat_result_raw_out_value.ok)); |
| 335 |
} else { |
| 336 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 337 |
} |
| 338 |
return diplomat_result_out_value; |
| 339 |
} |
| 340 |
inline diplomat::result<ICU4XFixedDecimal, ICU4XError> ICU4XFixedDecimal::create_from_f64_with_lower_magnitude(double f, int16_t magnitude) { |
| 341 |
auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimal_create_from_f64_with_lower_magnitude(f, magnitude); |
| 342 |
diplomat::result<ICU4XFixedDecimal, ICU4XError> diplomat_result_out_value; |
| 343 |
if (diplomat_result_raw_out_value.is_ok) { |
| 344 |
diplomat_result_out_value = diplomat::Ok<ICU4XFixedDecimal>(ICU4XFixedDecimal(diplomat_result_raw_out_value.ok)); |
| 345 |
} else { |
| 346 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 347 |
} |
| 348 |
return diplomat_result_out_value; |
| 349 |
} |
| 350 |
inline diplomat::result<ICU4XFixedDecimal, ICU4XError> ICU4XFixedDecimal::create_from_f64_with_significant_digits(double f, uint8_t digits) { |
| 351 |
auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimal_create_from_f64_with_significant_digits(f, digits); |
| 352 |
diplomat::result<ICU4XFixedDecimal, ICU4XError> diplomat_result_out_value; |
| 353 |
if (diplomat_result_raw_out_value.is_ok) { |
| 354 |
diplomat_result_out_value = diplomat::Ok<ICU4XFixedDecimal>(ICU4XFixedDecimal(diplomat_result_raw_out_value.ok)); |
| 355 |
} else { |
| 356 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 357 |
} |
| 358 |
return diplomat_result_out_value; |
| 359 |
} |
| 360 |
inline diplomat::result<ICU4XFixedDecimal, ICU4XError> ICU4XFixedDecimal::create_from_f64_with_floating_precision(double f) { |
| 361 |
auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimal_create_from_f64_with_floating_precision(f); |
| 362 |
diplomat::result<ICU4XFixedDecimal, ICU4XError> diplomat_result_out_value; |
| 363 |
if (diplomat_result_raw_out_value.is_ok) { |
| 364 |
diplomat_result_out_value = diplomat::Ok<ICU4XFixedDecimal>(ICU4XFixedDecimal(diplomat_result_raw_out_value.ok)); |
| 365 |
} else { |
| 366 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 367 |
} |
| 368 |
return diplomat_result_out_value; |
| 369 |
} |
| 370 |
inline diplomat::result<ICU4XFixedDecimal, ICU4XError> ICU4XFixedDecimal::create_from_string(const std::string_view v) { |
| 371 |
auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimal_create_from_string(v.data(), v.size()); |
| 372 |
diplomat::result<ICU4XFixedDecimal, ICU4XError> diplomat_result_out_value; |
| 373 |
if (diplomat_result_raw_out_value.is_ok) { |
| 374 |
diplomat_result_out_value = diplomat::Ok<ICU4XFixedDecimal>(ICU4XFixedDecimal(diplomat_result_raw_out_value.ok)); |
| 375 |
} else { |
| 376 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 377 |
} |
| 378 |
return diplomat_result_out_value; |
| 379 |
} |
| 380 |
inline uint8_t ICU4XFixedDecimal::digit_at(int16_t magnitude) const { |
| 381 |
return capi::ICU4XFixedDecimal_digit_at(this->inner.get(), magnitude); |
| 382 |
} |
| 383 |
inline int16_t ICU4XFixedDecimal::magnitude_start() const { |
| 384 |
return capi::ICU4XFixedDecimal_magnitude_start(this->inner.get()); |
| 385 |
} |
| 386 |
inline int16_t ICU4XFixedDecimal::magnitude_end() const { |
| 387 |
return capi::ICU4XFixedDecimal_magnitude_end(this->inner.get()); |
| 388 |
} |
| 389 |
inline int16_t ICU4XFixedDecimal::nonzero_magnitude_start() const { |
| 390 |
return capi::ICU4XFixedDecimal_nonzero_magnitude_start(this->inner.get()); |
| 391 |
} |
| 392 |
inline int16_t ICU4XFixedDecimal::nonzero_magnitude_end() const { |
| 393 |
return capi::ICU4XFixedDecimal_nonzero_magnitude_end(this->inner.get()); |
| 394 |
} |
| 395 |
inline bool ICU4XFixedDecimal::is_zero() const { |
| 396 |
return capi::ICU4XFixedDecimal_is_zero(this->inner.get()); |
| 397 |
} |
| 398 |
inline void ICU4XFixedDecimal::multiply_pow10(int16_t power) { |
| 399 |
capi::ICU4XFixedDecimal_multiply_pow10(this->inner.get(), power); |
| 400 |
} |
| 401 |
inline ICU4XFixedDecimalSign ICU4XFixedDecimal::sign() const { |
| 402 |
return static_cast<ICU4XFixedDecimalSign>(capi::ICU4XFixedDecimal_sign(this->inner.get())); |
| 403 |
} |
| 404 |
inline void ICU4XFixedDecimal::set_sign(ICU4XFixedDecimalSign sign) { |
| 405 |
capi::ICU4XFixedDecimal_set_sign(this->inner.get(), static_cast<capi::ICU4XFixedDecimalSign>(sign)); |
| 406 |
} |
| 407 |
inline void ICU4XFixedDecimal::apply_sign_display(ICU4XFixedDecimalSignDisplay sign_display) { |
| 408 |
capi::ICU4XFixedDecimal_apply_sign_display(this->inner.get(), static_cast<capi::ICU4XFixedDecimalSignDisplay>(sign_display)); |
| 409 |
} |
| 410 |
inline void ICU4XFixedDecimal::trim_start() { |
| 411 |
capi::ICU4XFixedDecimal_trim_start(this->inner.get()); |
| 412 |
} |
| 413 |
inline void ICU4XFixedDecimal::trim_end() { |
| 414 |
capi::ICU4XFixedDecimal_trim_end(this->inner.get()); |
| 415 |
} |
| 416 |
inline void ICU4XFixedDecimal::pad_start(int16_t position) { |
| 417 |
capi::ICU4XFixedDecimal_pad_start(this->inner.get(), position); |
| 418 |
} |
| 419 |
inline void ICU4XFixedDecimal::pad_end(int16_t position) { |
| 420 |
capi::ICU4XFixedDecimal_pad_end(this->inner.get(), position); |
| 421 |
} |
| 422 |
inline void ICU4XFixedDecimal::set_max_position(int16_t position) { |
| 423 |
capi::ICU4XFixedDecimal_set_max_position(this->inner.get(), position); |
| 424 |
} |
| 425 |
inline void ICU4XFixedDecimal::trunc(int16_t position) { |
| 426 |
capi::ICU4XFixedDecimal_trunc(this->inner.get(), position); |
| 427 |
} |
| 428 |
inline void ICU4XFixedDecimal::trunc_to_increment(int16_t position, ICU4XRoundingIncrement increment) { |
| 429 |
capi::ICU4XFixedDecimal_trunc_to_increment(this->inner.get(), position, static_cast<capi::ICU4XRoundingIncrement>(increment)); |
| 430 |
} |
| 431 |
inline void ICU4XFixedDecimal::half_trunc(int16_t position) { |
| 432 |
capi::ICU4XFixedDecimal_half_trunc(this->inner.get(), position); |
| 433 |
} |
| 434 |
inline void ICU4XFixedDecimal::half_trunc_to_increment(int16_t position, ICU4XRoundingIncrement increment) { |
| 435 |
capi::ICU4XFixedDecimal_half_trunc_to_increment(this->inner.get(), position, static_cast<capi::ICU4XRoundingIncrement>(increment)); |
| 436 |
} |
| 437 |
inline void ICU4XFixedDecimal::expand(int16_t position) { |
| 438 |
capi::ICU4XFixedDecimal_expand(this->inner.get(), position); |
| 439 |
} |
| 440 |
inline void ICU4XFixedDecimal::expand_to_increment(int16_t position, ICU4XRoundingIncrement increment) { |
| 441 |
capi::ICU4XFixedDecimal_expand_to_increment(this->inner.get(), position, static_cast<capi::ICU4XRoundingIncrement>(increment)); |
| 442 |
} |
| 443 |
inline void ICU4XFixedDecimal::half_expand(int16_t position) { |
| 444 |
capi::ICU4XFixedDecimal_half_expand(this->inner.get(), position); |
| 445 |
} |
| 446 |
inline void ICU4XFixedDecimal::half_expand_to_increment(int16_t position, ICU4XRoundingIncrement increment) { |
| 447 |
capi::ICU4XFixedDecimal_half_expand_to_increment(this->inner.get(), position, static_cast<capi::ICU4XRoundingIncrement>(increment)); |
| 448 |
} |
| 449 |
inline void ICU4XFixedDecimal::ceil(int16_t position) { |
| 450 |
capi::ICU4XFixedDecimal_ceil(this->inner.get(), position); |
| 451 |
} |
| 452 |
inline void ICU4XFixedDecimal::ceil_to_increment(int16_t position, ICU4XRoundingIncrement increment) { |
| 453 |
capi::ICU4XFixedDecimal_ceil_to_increment(this->inner.get(), position, static_cast<capi::ICU4XRoundingIncrement>(increment)); |
| 454 |
} |
| 455 |
inline void ICU4XFixedDecimal::half_ceil(int16_t position) { |
| 456 |
capi::ICU4XFixedDecimal_half_ceil(this->inner.get(), position); |
| 457 |
} |
| 458 |
inline void ICU4XFixedDecimal::half_ceil_to_increment(int16_t position, ICU4XRoundingIncrement increment) { |
| 459 |
capi::ICU4XFixedDecimal_half_ceil_to_increment(this->inner.get(), position, static_cast<capi::ICU4XRoundingIncrement>(increment)); |
| 460 |
} |
| 461 |
inline void ICU4XFixedDecimal::floor(int16_t position) { |
| 462 |
capi::ICU4XFixedDecimal_floor(this->inner.get(), position); |
| 463 |
} |
| 464 |
inline void ICU4XFixedDecimal::floor_to_increment(int16_t position, ICU4XRoundingIncrement increment) { |
| 465 |
capi::ICU4XFixedDecimal_floor_to_increment(this->inner.get(), position, static_cast<capi::ICU4XRoundingIncrement>(increment)); |
| 466 |
} |
| 467 |
inline void ICU4XFixedDecimal::half_floor(int16_t position) { |
| 468 |
capi::ICU4XFixedDecimal_half_floor(this->inner.get(), position); |
| 469 |
} |
| 470 |
inline void ICU4XFixedDecimal::half_floor_to_increment(int16_t position, ICU4XRoundingIncrement increment) { |
| 471 |
capi::ICU4XFixedDecimal_half_floor_to_increment(this->inner.get(), position, static_cast<capi::ICU4XRoundingIncrement>(increment)); |
| 472 |
} |
| 473 |
inline void ICU4XFixedDecimal::half_even(int16_t position) { |
| 474 |
capi::ICU4XFixedDecimal_half_even(this->inner.get(), position); |
| 475 |
} |
| 476 |
inline void ICU4XFixedDecimal::half_even_to_increment(int16_t position, ICU4XRoundingIncrement increment) { |
| 477 |
capi::ICU4XFixedDecimal_half_even_to_increment(this->inner.get(), position, static_cast<capi::ICU4XRoundingIncrement>(increment)); |
| 478 |
} |
| 479 |
inline diplomat::result<std::monostate, std::monostate> ICU4XFixedDecimal::concatenate_end(ICU4XFixedDecimal& other) { |
| 480 |
auto diplomat_result_raw_out_value = capi::ICU4XFixedDecimal_concatenate_end(this->inner.get(), other.AsFFIMut()); |
| 481 |
diplomat::result<std::monostate, std::monostate> diplomat_result_out_value; |
| 482 |
if (diplomat_result_raw_out_value.is_ok) { |
| 483 |
diplomat_result_out_value = diplomat::Ok<std::monostate>(std::monostate()); |
| 484 |
} else { |
| 485 |
diplomat_result_out_value = diplomat::Err<std::monostate>(std::monostate()); |
| 486 |
} |
| 487 |
return diplomat_result_out_value; |
| 488 |
} |
| 489 |
template<typename W> inline void ICU4XFixedDecimal::to_string_to_writeable(W& to) const { |
| 490 |
capi::DiplomatWriteable to_writer = diplomat::WriteableTrait<W>::Construct(to); |
| 491 |
capi::ICU4XFixedDecimal_to_string(this->inner.get(), &to_writer); |
| 492 |
} |
| 493 |
inline std::string ICU4XFixedDecimal::to_string() const { |
| 494 |
std::string diplomat_writeable_string; |
| 495 |
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); |
| 496 |
capi::ICU4XFixedDecimal_to_string(this->inner.get(), &diplomat_writeable_out); |
| 497 |
return diplomat_writeable_string; |
| 498 |
} |
| 499 |
#endif |