| 1 |
#ifndef ICU4XTime_HPP |
| 2 |
#define ICU4XTime_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 "ICU4XTime.h" |
| 13 |
|
| 14 |
class ICU4XTime; |
| 15 |
#include "ICU4XError.hpp" |
| 16 |
|
| 17 |
/** |
| 18 |
* A destruction policy for using ICU4XTime with std::unique_ptr. |
| 19 |
*/ |
| 20 |
struct ICU4XTimeDeleter { |
| 21 |
void operator()(capi::ICU4XTime* l) const noexcept { |
| 22 |
capi::ICU4XTime_destroy(l); |
| 23 |
} |
| 24 |
}; |
| 25 |
|
| 26 |
/** |
| 27 |
* An ICU4X Time object representing a time in terms of hour, minute, second, nanosecond |
| 28 |
* |
| 29 |
* See the [Rust documentation for `Time`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html) for more information. |
| 30 |
*/ |
| 31 |
class ICU4XTime { |
| 32 |
public: |
| 33 |
|
| 34 |
/** |
| 35 |
* Creates a new [`ICU4XTime`] given field values |
| 36 |
* |
| 37 |
* See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html#method.try_new) for more information. |
| 38 |
*/ |
| 39 |
static diplomat::result<ICU4XTime, ICU4XError> create(uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond); |
| 40 |
|
| 41 |
/** |
| 42 |
* Creates a new [`ICU4XTime`] representing midnight (00:00.000). |
| 43 |
* |
| 44 |
* See the [Rust documentation for `midnight`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html#method.midnight) for more information. |
| 45 |
*/ |
| 46 |
static diplomat::result<ICU4XTime, ICU4XError> create_midnight(); |
| 47 |
|
| 48 |
/** |
| 49 |
* Returns the hour in this time |
| 50 |
* |
| 51 |
* See the [Rust documentation for `hour`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.hour) for more information. |
| 52 |
*/ |
| 53 |
uint8_t hour() const; |
| 54 |
|
| 55 |
/** |
| 56 |
* Returns the minute in this time |
| 57 |
* |
| 58 |
* See the [Rust documentation for `minute`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.minute) for more information. |
| 59 |
*/ |
| 60 |
uint8_t minute() const; |
| 61 |
|
| 62 |
/** |
| 63 |
* Returns the second in this time |
| 64 |
* |
| 65 |
* See the [Rust documentation for `second`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.second) for more information. |
| 66 |
*/ |
| 67 |
uint8_t second() const; |
| 68 |
|
| 69 |
/** |
| 70 |
* Returns the nanosecond in this time |
| 71 |
* |
| 72 |
* See the [Rust documentation for `nanosecond`](https://docs.rs/icu/latest/icu/calendar/struct.Time.html#structfield.nanosecond) for more information. |
| 73 |
*/ |
| 74 |
uint32_t nanosecond() const; |
| 75 |
inline const capi::ICU4XTime* AsFFI() const { return this->inner.get(); } |
| 76 |
inline capi::ICU4XTime* AsFFIMut() { return this->inner.get(); } |
| 77 |
inline explicit ICU4XTime(capi::ICU4XTime* i) : inner(i) {} |
| 78 |
ICU4XTime() = default; |
| 79 |
ICU4XTime(ICU4XTime&&) noexcept = default; |
| 80 |
ICU4XTime& operator=(ICU4XTime&& other) noexcept = default; |
| 81 |
private: |
| 82 |
std::unique_ptr<capi::ICU4XTime, ICU4XTimeDeleter> inner; |
| 83 |
}; |
| 84 |
|
| 85 |
|
| 86 |
inline diplomat::result<ICU4XTime, ICU4XError> ICU4XTime::create(uint8_t hour, uint8_t minute, uint8_t second, uint32_t nanosecond) { |
| 87 |
auto diplomat_result_raw_out_value = capi::ICU4XTime_create(hour, minute, second, nanosecond); |
| 88 |
diplomat::result<ICU4XTime, ICU4XError> diplomat_result_out_value; |
| 89 |
if (diplomat_result_raw_out_value.is_ok) { |
| 90 |
diplomat_result_out_value = diplomat::Ok<ICU4XTime>(ICU4XTime(diplomat_result_raw_out_value.ok)); |
| 91 |
} else { |
| 92 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 93 |
} |
| 94 |
return diplomat_result_out_value; |
| 95 |
} |
| 96 |
inline diplomat::result<ICU4XTime, ICU4XError> ICU4XTime::create_midnight() { |
| 97 |
auto diplomat_result_raw_out_value = capi::ICU4XTime_create_midnight(); |
| 98 |
diplomat::result<ICU4XTime, ICU4XError> diplomat_result_out_value; |
| 99 |
if (diplomat_result_raw_out_value.is_ok) { |
| 100 |
diplomat_result_out_value = diplomat::Ok<ICU4XTime>(ICU4XTime(diplomat_result_raw_out_value.ok)); |
| 101 |
} else { |
| 102 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 103 |
} |
| 104 |
return diplomat_result_out_value; |
| 105 |
} |
| 106 |
inline uint8_t ICU4XTime::hour() const { |
| 107 |
return capi::ICU4XTime_hour(this->inner.get()); |
| 108 |
} |
| 109 |
inline uint8_t ICU4XTime::minute() const { |
| 110 |
return capi::ICU4XTime_minute(this->inner.get()); |
| 111 |
} |
| 112 |
inline uint8_t ICU4XTime::second() const { |
| 113 |
return capi::ICU4XTime_second(this->inner.get()); |
| 114 |
} |
| 115 |
inline uint32_t ICU4XTime::nanosecond() const { |
| 116 |
return capi::ICU4XTime_nanosecond(this->inner.get()); |
| 117 |
} |
| 118 |
#endif |