| 1 |
#ifndef ICU4XUnitsConverter_HPP |
| 2 |
#define ICU4XUnitsConverter_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 "ICU4XUnitsConverter.h" |
| 13 |
|
| 14 |
class ICU4XUnitsConverter; |
| 15 |
|
| 16 |
/** |
| 17 |
* A destruction policy for using ICU4XUnitsConverter with std::unique_ptr. |
| 18 |
*/ |
| 19 |
struct ICU4XUnitsConverterDeleter { |
| 20 |
void operator()(capi::ICU4XUnitsConverter* l) const noexcept { |
| 21 |
capi::ICU4XUnitsConverter_destroy(l); |
| 22 |
} |
| 23 |
}; |
| 24 |
|
| 25 |
/** |
| 26 |
* An ICU4X Units Converter object, capable of converting between two [`ICU4XMeasureUnit`]s. |
| 27 |
* |
| 28 |
* You can create an instance of this object using [`ICU4XUnitsConverterFactory`] by calling the `converter` method. |
| 29 |
* |
| 30 |
* See the [Rust documentation for `UnitsConverter`](https://docs.rs/icu/latest/icu/experimental/units/converter/struct.UnitsConverter.html) for more information. |
| 31 |
*/ |
| 32 |
class ICU4XUnitsConverter { |
| 33 |
public: |
| 34 |
|
| 35 |
/** |
| 36 |
* Converts the input value in float from the input unit to the output unit (that have been used to create this converter). |
| 37 |
* NOTE: |
| 38 |
* The conversion using floating-point operations is not as accurate as the conversion using ratios. |
| 39 |
* |
| 40 |
* See the [Rust documentation for `convert`](https://docs.rs/icu/latest/icu/experimental/units/converter/struct.UnitsConverter.html#method.convert) for more information. |
| 41 |
*/ |
| 42 |
double convert_f64(double value) const; |
| 43 |
|
| 44 |
/** |
| 45 |
* Clones the current [`ICU4XUnitsConverter`] object. |
| 46 |
* |
| 47 |
* See the [Rust documentation for `clone`](https://docs.rs/icu/latest/icu/experimental/units/converter/struct.UnitsConverter.html#method.clone) for more information. |
| 48 |
*/ |
| 49 |
ICU4XUnitsConverter clone() const; |
| 50 |
inline const capi::ICU4XUnitsConverter* AsFFI() const { return this->inner.get(); } |
| 51 |
inline capi::ICU4XUnitsConverter* AsFFIMut() { return this->inner.get(); } |
| 52 |
inline explicit ICU4XUnitsConverter(capi::ICU4XUnitsConverter* i) : inner(i) {} |
| 53 |
ICU4XUnitsConverter() = default; |
| 54 |
ICU4XUnitsConverter(ICU4XUnitsConverter&&) noexcept = default; |
| 55 |
ICU4XUnitsConverter& operator=(ICU4XUnitsConverter&& other) noexcept = default; |
| 56 |
private: |
| 57 |
std::unique_ptr<capi::ICU4XUnitsConverter, ICU4XUnitsConverterDeleter> inner; |
| 58 |
}; |
| 59 |
|
| 60 |
|
| 61 |
inline double ICU4XUnitsConverter::convert_f64(double value) const { |
| 62 |
return capi::ICU4XUnitsConverter_convert_f64(this->inner.get(), value); |
| 63 |
} |
| 64 |
inline ICU4XUnitsConverter ICU4XUnitsConverter::clone() const { |
| 65 |
return ICU4XUnitsConverter(capi::ICU4XUnitsConverter_clone(this->inner.get())); |
| 66 |
} |
| 67 |
#endif |