summaryrefslogtreecommitdiffstats
path: root/intl/icu_capi/cpp/include/ICU4XPluralOperands.hpp
blob: 635011f14f03e29e792a0c714ee30838ef954779 (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
#ifndef ICU4XPluralOperands_HPP
#define ICU4XPluralOperands_HPP
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <algorithm>
#include <memory>
#include <variant>
#include <optional>
#include "diplomat_runtime.hpp"

#include "ICU4XPluralOperands.h"

class ICU4XPluralOperands;
#include "ICU4XError.hpp"

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

/**
 * FFI version of `PluralOperands`.
 * 
 * See the [Rust documentation for `PluralOperands`](https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html) for more information.
 */
class ICU4XPluralOperands {
 public:

  /**
   * Construct for a given string representing a number
   * 
   * See the [Rust documentation for `from_str`](https://docs.rs/icu/latest/icu/plurals/struct.PluralOperands.html#method.from_str) for more information.
   */
  static diplomat::result<ICU4XPluralOperands, ICU4XError> create_from_string(const std::string_view s);
  inline const capi::ICU4XPluralOperands* AsFFI() const { return this->inner.get(); }
  inline capi::ICU4XPluralOperands* AsFFIMut() { return this->inner.get(); }
  inline ICU4XPluralOperands(capi::ICU4XPluralOperands* i) : inner(i) {}
  ICU4XPluralOperands() = default;
  ICU4XPluralOperands(ICU4XPluralOperands&&) noexcept = default;
  ICU4XPluralOperands& operator=(ICU4XPluralOperands&& other) noexcept = default;
 private:
  std::unique_ptr<capi::ICU4XPluralOperands, ICU4XPluralOperandsDeleter> inner;
};


inline diplomat::result<ICU4XPluralOperands, ICU4XError> ICU4XPluralOperands::create_from_string(const std::string_view s) {
  auto diplomat_result_raw_out_value = capi::ICU4XPluralOperands_create_from_string(s.data(), s.size());
  diplomat::result<ICU4XPluralOperands, ICU4XError> diplomat_result_out_value;
  if (diplomat_result_raw_out_value.is_ok) {
    diplomat_result_out_value = diplomat::Ok<ICU4XPluralOperands>(ICU4XPluralOperands(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;
}
#endif