| 1 |
#ifndef ICU4XReorderedIndexMap_HPP |
| 2 |
#define ICU4XReorderedIndexMap_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 "ICU4XReorderedIndexMap.h" |
| 13 |
|
| 14 |
|
| 15 |
/** |
| 16 |
* A destruction policy for using ICU4XReorderedIndexMap with std::unique_ptr. |
| 17 |
*/ |
| 18 |
struct ICU4XReorderedIndexMapDeleter { |
| 19 |
void operator()(capi::ICU4XReorderedIndexMap* l) const noexcept { |
| 20 |
capi::ICU4XReorderedIndexMap_destroy(l); |
| 21 |
} |
| 22 |
}; |
| 23 |
|
| 24 |
/** |
| 25 |
* Thin wrapper around a vector that maps visual indices to source indices |
| 26 |
* |
| 27 |
* `map[visualIndex] = sourceIndex` |
| 28 |
* |
| 29 |
* Produced by `reorder_visual()` on [`ICU4XBidi`]. |
| 30 |
*/ |
| 31 |
class ICU4XReorderedIndexMap { |
| 32 |
public: |
| 33 |
|
| 34 |
/** |
| 35 |
* Get this as a slice/array of indices |
| 36 |
* |
| 37 |
* Lifetimes: `this` must live at least as long as the output. |
| 38 |
*/ |
| 39 |
const diplomat::span<const size_t> as_slice() const; |
| 40 |
|
| 41 |
/** |
| 42 |
* The length of this map |
| 43 |
*/ |
| 44 |
size_t len() const; |
| 45 |
|
| 46 |
/** |
| 47 |
* Whether this map is empty |
| 48 |
*/ |
| 49 |
bool is_empty() const; |
| 50 |
|
| 51 |
/** |
| 52 |
* Get element at `index`. Returns 0 when out of bounds |
| 53 |
* (note that 0 is also a valid in-bounds value, please use `len()` |
| 54 |
* to avoid out-of-bounds) |
| 55 |
*/ |
| 56 |
size_t get(size_t index) const; |
| 57 |
inline const capi::ICU4XReorderedIndexMap* AsFFI() const { return this->inner.get(); } |
| 58 |
inline capi::ICU4XReorderedIndexMap* AsFFIMut() { return this->inner.get(); } |
| 59 |
inline explicit ICU4XReorderedIndexMap(capi::ICU4XReorderedIndexMap* i) : inner(i) {} |
| 60 |
ICU4XReorderedIndexMap() = default; |
| 61 |
ICU4XReorderedIndexMap(ICU4XReorderedIndexMap&&) noexcept = default; |
| 62 |
ICU4XReorderedIndexMap& operator=(ICU4XReorderedIndexMap&& other) noexcept = default; |
| 63 |
private: |
| 64 |
std::unique_ptr<capi::ICU4XReorderedIndexMap, ICU4XReorderedIndexMapDeleter> inner; |
| 65 |
}; |
| 66 |
|
| 67 |
|
| 68 |
inline const diplomat::span<const size_t> ICU4XReorderedIndexMap::as_slice() const { |
| 69 |
capi::DiplomatUsizeView diplomat_slice_raw_out_value = capi::ICU4XReorderedIndexMap_as_slice(this->inner.get()); |
| 70 |
diplomat::span<const size_t> slice(diplomat_slice_raw_out_value.data, diplomat_slice_raw_out_value.len); |
| 71 |
return slice; |
| 72 |
} |
| 73 |
inline size_t ICU4XReorderedIndexMap::len() const { |
| 74 |
return capi::ICU4XReorderedIndexMap_len(this->inner.get()); |
| 75 |
} |
| 76 |
inline bool ICU4XReorderedIndexMap::is_empty() const { |
| 77 |
return capi::ICU4XReorderedIndexMap_is_empty(this->inner.get()); |
| 78 |
} |
| 79 |
inline size_t ICU4XReorderedIndexMap::get(size_t index) const { |
| 80 |
return capi::ICU4XReorderedIndexMap_get(this->inner.get(), index); |
| 81 |
} |
| 82 |
#endif |