summaryrefslogtreecommitdiffstats
path: root/intl/icu_capi/cpp/include/ICU4XWeekCalculator.hpp
blob: ace3c97c4f9240c2563b6df787f7bccdf6b27ac7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef ICU4XWeekCalculator_HPP
#define ICU4XWeekCalculator_HPP
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <algorithm>
#include <memory>
#include <variant>
#include <optional>
#include "diplomat_runtime.hpp"

#include "ICU4XWeekCalculator.h"

class ICU4XDataProvider;
class ICU4XLocale;
class ICU4XWeekCalculator;
#include "ICU4XError.hpp"
#include "ICU4XIsoWeekday.hpp"

/**
 * A destruction policy for using ICU4XWeekCalculator with std::unique_ptr.
 */
struct ICU4XWeekCalculatorDeleter {
  void operator()(capi::ICU4XWeekCalculator* l) const noexcept {
    capi::ICU4XWeekCalculator_destroy(l);
  }
};

/**
 * A Week calculator, useful to be passed in to `week_of_year()` on Date and DateTime types
 * 
 * See the [Rust documentation for `WeekCalculator`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html) for more information.
 */
class ICU4XWeekCalculator {
 public:

  /**
   * Creates a new [`ICU4XWeekCalculator`] from locale data.
   * 
   * See the [Rust documentation for `try_new`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#method.try_new) for more information.
   */
  static diplomat::result<ICU4XWeekCalculator, ICU4XError> create(const ICU4XDataProvider& provider, const ICU4XLocale& locale);

  /**
   * 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)
   */
  static ICU4XWeekCalculator create_from_first_day_of_week_and_min_week_days(ICU4XIsoWeekday first_weekday, uint8_t min_week_days);

  /**
   * Returns the weekday that starts the week for this object's locale
   * 
   * See the [Rust documentation for `first_weekday`](https://docs.rs/icu/latest/icu/calendar/week/struct.WeekCalculator.html#structfield.first_weekday) for more information.
   */
  ICU4XIsoWeekday first_weekday() const;

  /**
   * The minimum number of days overlapping a year required for a week to be
   * considered part of that year
   * 
   * 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.
   */
  uint8_t min_week_days() const;
  inline const capi::ICU4XWeekCalculator* AsFFI() const { return this->inner.get(); }
  inline capi::ICU4XWeekCalculator* AsFFIMut() { return this->inner.get(); }
  inline ICU4XWeekCalculator(capi::ICU4XWeekCalculator* i) : inner(i) {}
  ICU4XWeekCalculator() = default;
  ICU4XWeekCalculator(ICU4XWeekCalculator&&) noexcept = default;
  ICU4XWeekCalculator& operator=(ICU4XWeekCalculator&& other) noexcept = default;
 private:
  std::unique_ptr<capi::ICU4XWeekCalculator, ICU4XWeekCalculatorDeleter> inner;
};

#include "ICU4XDataProvider.hpp"
#include "ICU4XLocale.hpp"

inline diplomat::result<ICU4XWeekCalculator, ICU4XError> ICU4XWeekCalculator::create(const ICU4XDataProvider& provider, const ICU4XLocale& locale) {
  auto diplomat_result_raw_out_value = capi::ICU4XWeekCalculator_create(provider.AsFFI(), locale.AsFFI());
  diplomat::result<ICU4XWeekCalculator, ICU4XError> diplomat_result_out_value;
  if (diplomat_result_raw_out_value.is_ok) {
    diplomat_result_out_value = diplomat::Ok<ICU4XWeekCalculator>(ICU4XWeekCalculator(diplomat_result_raw_out_value.ok));
  } else {
    diplomat_result_out_value = diplomat::Err<ICU4XError>(static_cast<ICU4XError>(diplomat_result_raw_out_value.err));
  }
  return diplomat_result_out_value;
}
inline ICU4XWeekCalculator ICU4XWeekCalculator::create_from_first_day_of_week_and_min_week_days(ICU4XIsoWeekday first_weekday, uint8_t min_week_days) {
  return ICU4XWeekCalculator(capi::ICU4XWeekCalculator_create_from_first_day_of_week_and_min_week_days(static_cast<capi::ICU4XIsoWeekday>(first_weekday), min_week_days));
}
inline ICU4XIsoWeekday ICU4XWeekCalculator::first_weekday() const {
  return static_cast<ICU4XIsoWeekday>(capi::ICU4XWeekCalculator_first_weekday(this->inner.get()));
}
inline uint8_t ICU4XWeekCalculator::min_week_days() const {
  return capi::ICU4XWeekCalculator_min_week_days(this->inner.get());
}
#endif