| 1 |
#ifndef ICU4XWeekCalculator_HPP |
| 2 |
#define ICU4XWeekCalculator_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 "ICU4XWeekCalculator.h" |
| 13 |
|
| 14 |
class ICU4XDataProvider; |
| 15 |
class ICU4XLocale; |
| 16 |
class ICU4XWeekCalculator; |
| 17 |
#include "ICU4XError.hpp" |
| 18 |
#include "ICU4XIsoWeekday.hpp" |
| 19 |
struct ICU4XWeekendContainsDay; |
| 20 |
|
| 21 |
/** |
| 22 |
* A destruction policy for using ICU4XWeekCalculator with std::unique_ptr. |
| 23 |
*/ |
| 24 |
struct ICU4XWeekCalculatorDeleter { |
| 25 |
void operator()(capi::ICU4XWeekCalculator* l) const noexcept { |
| 26 |
capi::ICU4XWeekCalculator_destroy(l); |
| 27 |
} |
| 28 |
}; |
| 29 |
|
| 30 |
/** |
| 31 |
* A Week calculator, useful to be passed in to `week_of_year()` on Date and DateTime types |
| 32 |
* |
| 33 |
* See the [Rust documentation for `WeekCalculator`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html) for more information. |
| 34 |
*/ |
| 35 |
class ICU4XWeekCalculator { |
| 36 |
public: |
| 37 |
|
| 38 |
/** |
| 39 |
* Creates a new [`ICU4XWeekCalculator`] from locale data. |
| 40 |
* |
| 41 |
* See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#method.try_new) for more information. |
| 42 |
*/ |
| 43 |
static diplomat::result<ICU4XWeekCalculator, ICU4XError> create(const ICU4XDataProvider& provider, const ICU4XLocale& locale); |
| 44 |
|
| 45 |
/** |
| 46 |
* Additional information: [1](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.first_weekday), [2](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.min_week_days) |
| 47 |
*/ |
| 48 |
static ICU4XWeekCalculator create_from_first_day_of_week_and_min_week_days(ICU4XIsoWeekday first_weekday, uint8_t min_week_days); |
| 49 |
|
| 50 |
/** |
| 51 |
* Returns the weekday that starts the week for this object's locale |
| 52 |
* |
| 53 |
* See the [Rust documentation for `first_weekday`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.first_weekday) for more information. |
| 54 |
*/ |
| 55 |
ICU4XIsoWeekday first_weekday() const; |
| 56 |
|
| 57 |
/** |
| 58 |
* The minimum number of days overlapping a year required for a week to be |
| 59 |
* considered part of that year |
| 60 |
* |
| 61 |
* See the [Rust documentation for `min_week_days`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.min_week_days) for more information. |
| 62 |
*/ |
| 63 |
uint8_t min_week_days() const; |
| 64 |
|
| 65 |
/** |
| 66 |
* See the [Rust documentation for `weekend`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#method.weekend) for more information. |
| 67 |
*/ |
| 68 |
ICU4XWeekendContainsDay weekend() const; |
| 69 |
inline const capi::ICU4XWeekCalculator* AsFFI() const { return this->inner.get(); } |
| 70 |
inline capi::ICU4XWeekCalculator* AsFFIMut() { return this->inner.get(); } |
| 71 |
inline explicit ICU4XWeekCalculator(capi::ICU4XWeekCalculator* i) : inner(i) {} |
| 72 |
ICU4XWeekCalculator() = default; |
| 73 |
ICU4XWeekCalculator(ICU4XWeekCalculator&&) noexcept = default; |
| 74 |
ICU4XWeekCalculator& operator=(ICU4XWeekCalculator&& other) noexcept = default; |
| 75 |
private: |
| 76 |
std::unique_ptr<capi::ICU4XWeekCalculator, ICU4XWeekCalculatorDeleter> inner; |
| 77 |
}; |
| 78 |
|
| 79 |
#include "ICU4XDataProvider.hpp" |
| 80 |
#include "ICU4XLocale.hpp" |
| 81 |
#include "ICU4XWeekendContainsDay.hpp" |
| 82 |
|
| 83 |
inline diplomat::result<ICU4XWeekCalculator, ICU4XError> ICU4XWeekCalculator::create(const ICU4XDataProvider& provider, const ICU4XLocale& locale) { |
| 84 |
auto diplomat_result_raw_out_value = capi::ICU4XWeekCalculator_create(provider.AsFFI(), locale.AsFFI()); |
| 85 |
diplomat::result<ICU4XWeekCalculator, ICU4XError> diplomat_result_out_value; |
| 86 |
if (diplomat_result_raw_out_value.is_ok) { |
| 87 |
diplomat_result_out_value = diplomat::Ok<ICU4XWeekCalculator>(ICU4XWeekCalculator(diplomat_result_raw_out_value.ok)); |
| 88 |
} else { |
| 89 |
diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err)); |
| 90 |
} |
| 91 |
return diplomat_result_out_value; |
| 92 |
} |
| 93 |
inline ICU4XWeekCalculator ICU4XWeekCalculator::create_from_first_day_of_week_and_min_week_days(ICU4XIsoWeekday first_weekday, uint8_t min_week_days) { |
| 94 |
return ICU4XWeekCalculator(capi::ICU4XWeekCalculator_create_from_first_day_of_week_and_min_week_days(static_cast<capi::ICU4XIsoWeekday>(first_weekday), min_week_days)); |
| 95 |
} |
| 96 |
inline ICU4XIsoWeekday ICU4XWeekCalculator::first_weekday() const { |
| 97 |
return static_cast<ICU4XIsoWeekday>(capi::ICU4XWeekCalculator_first_weekday(this->inner.get())); |
| 98 |
} |
| 99 |
inline uint8_t ICU4XWeekCalculator::min_week_days() const { |
| 100 |
return capi::ICU4XWeekCalculator_min_week_days(this->inner.get()); |
| 101 |
} |
| 102 |
inline ICU4XWeekendContainsDay ICU4XWeekCalculator::weekend() const { |
| 103 |
capi::ICU4XWeekendContainsDay diplomat_raw_struct_out_value = capi::ICU4XWeekCalculator_weekend(this->inner.get()); |
| 104 |
return ICU4XWeekendContainsDay{ .monday = std::move(diplomat_raw_struct_out_value.monday), .tuesday = std::move(diplomat_raw_struct_out_value.tuesday), .wednesday = std::move(diplomat_raw_struct_out_value.wednesday), .thursday = std::move(diplomat_raw_struct_out_value.thursday), .friday = std::move(diplomat_raw_struct_out_value.friday), .saturday = std::move(diplomat_raw_struct_out_value.saturday), .sunday = std::move(diplomat_raw_struct_out_value.sunday) }; |
| 105 |
} |
| 106 |
#endif |