Skip to content

Commit

Permalink
Re-generating C++ FFI wrappers
Browse files Browse the repository at this point in the history
  • Loading branch information
sffc committed Nov 13, 2021
1 parent f47e76e commit a7c2296
Show file tree
Hide file tree
Showing 16 changed files with 411 additions and 282 deletions.
24 changes: 12 additions & 12 deletions ffi/diplomat/cpp/docs/source/properties_maps_ffi.rst
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
``properties_maps::ffi``
========================

.. cpp:class:: ICU4XUnicodeScriptMapProperty
.. cpp:class:: ICU4XCodePointMapData16

An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/index.html>`__ for more information.
An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. For properties whose values fit into 16 bits. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/index.html>`__ for more information.

.. cpp:function:: static ICU4XUnicodeScriptMapPropertyResult try_get(const ICU4XDataProvider& provider)
.. cpp:function:: static ICU4XCodePointMapData16Response try_get_script(const ICU4XDataProvider& provider)

Gets a set for Unicode property ascii_hex_digit from a :cpp:class:`ICU4XDataProvider`. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/maps/fn.get_script.html>`__ for more information.
Gets a map for Unicode property Script from a :cpp:class:`ICU4XDataProvider`. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/maps/fn.get_script.html>`__ for more information.

.. cpp:function:: static ICU4XUnicodeScriptMapPropertyResult try_get_from_static(const ICU4XStaticDataProvider& provider)
.. cpp:function:: static ICU4XCodePointMapData16Response try_get_script_from_static(const ICU4XStaticDataProvider& provider)

Gets a set for Unicode property ascii_hex_digit from a :cpp:class:`ICU4XStaticDataProvider`. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/maps/fn.get_script.html>`__ for more information.
Gets a map for Unicode property Script from a :cpp:class:`ICU4XStaticDataProvider`. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/maps/fn.get_script.html>`__ for more information.

.. cpp:function:: uint32_t get(char32_t cp) const
.. cpp:function:: uint16_t get(char32_t cp) const

Gets the Script for a code point. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_codepointtrie/codepointtrie/struct.CodePointTrie.html#method.get_u32>`__ for more information.
Gets the value for a code point. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_codepointtrie/codepointtrie/struct.CodePointTrie.html#method.get_u32>`__ for more information.

.. cpp:struct:: ICU4XUnicodeScriptMapPropertyResult
.. cpp:struct:: ICU4XCodePointMapData16Response

.. cpp:member:: std::optional<ICU4XUnicodeScriptMapProperty> data
.. cpp:member:: std::optional<ICU4XCodePointMapData16> data

The :cpp:class:`ICU4XUnicodeScriptMapProperty`, if creation was successful.
The :cpp:class:`ICU4XCodePointMapData16`, if creation was successful.

.. cpp:member:: bool success

Whether creating the :cpp:class:`ICU4XUnicodeScriptMapProperty` was successful.
Whether creating the :cpp:class:`ICU4XCodePointMapData16` was successful.
14 changes: 7 additions & 7 deletions ffi/diplomat/cpp/docs/source/properties_sets_ffi.rst
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
``properties_sets::ffi``
========================

.. cpp:class:: ICU4XUnicodeSetProperty
.. cpp:class:: ICU4XCodePointSetData

An ICU4X Unicode Set Property object, capable of querying whether a code point is contained in a set based on a Unicode property. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/index.html>`__ for more information.

.. cpp:function:: static ICU4XUnicodeSetPropertyResult try_get_ascii_hex_digit(const ICU4XDataProvider& provider)
.. cpp:function:: static ICU4XCodePointSetDataResult try_get_ascii_hex_digit(const ICU4XDataProvider& provider)

Gets a set for Unicode property ascii_hex_digit from a :cpp:class:`ICU4XDataProvider`. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/sets/fn.get_ascii_hex_digit.html>`__ for more information.

.. cpp:function:: static ICU4XUnicodeSetPropertyResult try_get_ascii_hex_digit_from_static(const ICU4XStaticDataProvider& provider)
.. cpp:function:: static ICU4XCodePointSetDataResult try_get_ascii_hex_digit_from_static(const ICU4XStaticDataProvider& provider)

Gets a set for Unicode property ascii_hex_digit from a :cpp:class:`ICU4XStaticDataProvider`. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_properties/sets/fn.get_ascii_hex_digit.html>`__ for more information.

.. cpp:function:: bool contains(char32_t cp) const

Checks whether the code point is in the set. See `the Rust docs <https://unicode-org.github.io/icu4x-docs/doc/icu_uniset/struct.UnicodeSet.html#method.contains>`__ for more information.

.. cpp:struct:: ICU4XUnicodeSetPropertyResult
.. cpp:struct:: ICU4XCodePointSetDataResult

.. cpp:member:: std::optional<ICU4XUnicodeSetProperty> data
.. cpp:member:: std::optional<ICU4XCodePointSetData> data

The :cpp:class:`ICU4XUnicodeSetProperty`, if creation was successful.
The :cpp:class:`ICU4XCodePointSetData`, if creation was successful.

.. cpp:member:: bool success

Whether creating the :cpp:class:`ICU4XUnicodeSetProperty` was successful.
Whether creating the :cpp:class:`ICU4XCodePointSetData` was successful.
19 changes: 10 additions & 9 deletions ffi/diplomat/cpp/examples/properties/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
// called LICENSE at the top level of the ICU4X source tree
// (online at: https://github.com/unicode-org/icu4x/blob/main/LICENSE ).

#include "../../include/ICU4XUnicodeSetProperty.hpp"
#include "../../include/ICU4XUnicodeScriptMapProperty.hpp"
#include "../../include/ICU4XCodePointSetData.hpp"
#include "../../include/ICU4XCodePointMapData16.hpp"
#include "../../include/ICU4XCodePointMapData16Response.hpp"

#include <iostream>

const std::string_view path = "../../../../../provider/testdata/data/json/";

int test_set_property(ICU4XUnicodeSetPropertyResult result, char32_t included, char32_t excluded) {
int test_set_property(ICU4XCodePointSetDataResult result, char32_t included, char32_t excluded) {
if (!result.success) {
std::cout << "Failed to create ICU4XUnicodeSetProperty" << std::endl;
std::cout << "Failed to create ICU4XCodePointSetData" << std::endl;
return 1;
}
bool contains1 = result.data.value().contains(included);
Expand All @@ -26,9 +27,9 @@ int test_set_property(ICU4XUnicodeSetPropertyResult result, char32_t included, c
return 0;
}

int test_script_map_property(ICU4XUnicodeScriptMapPropertyResult result, char32_t sample, uint32_t expected) {
int test_map_16_property(ICU4XCodePointMapData16Response result, char32_t sample, uint32_t expected) {
if (!result.success) {
std::cout << "Failed to create ICU4XUnicodeScriptMapProperty" << std::endl;
std::cout << "Failed to create ICU4XCodePointMapData16" << std::endl;
return 1;
}
uint32_t actual = result.data.value().get(sample);
Expand All @@ -47,16 +48,16 @@ int main() {
int result;

result = test_set_property(
ICU4XUnicodeSetProperty::try_get_ascii_hex_digit(dp),
ICU4XCodePointSetData::try_get_ascii_hex_digit(dp),
u'3',
u''
);
if (result != 0) {
return result;
}

result = test_script_map_property(
ICU4XUnicodeScriptMapProperty::try_get(dp),
result = test_map_16_property(
ICU4XCodePointMapData16::try_get_script(dp),
u'',
17 // Script::Han
);
Expand Down
28 changes: 28 additions & 0 deletions ffi/diplomat/cpp/include/ICU4XCodePointMapData16.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef ICU4XCodePointMapData16_H
#define ICU4XCodePointMapData16_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct ICU4XCodePointMapData16 ICU4XCodePointMapData16;
#include "ICU4XDataProvider.h"
#include "ICU4XCodePointMapData16Response.h"
#include "ICU4XStaticDataProvider.h"

ICU4XCodePointMapData16Response ICU4XCodePointMapData16_try_get_script(const ICU4XDataProvider* provider);

ICU4XCodePointMapData16Response ICU4XCodePointMapData16_try_get_script_from_static(const ICU4XStaticDataProvider* provider);

uint16_t ICU4XCodePointMapData16_get(const ICU4XCodePointMapData16* self, char32_t cp);
void ICU4XCodePointMapData16_destroy(ICU4XCodePointMapData16* self);

#ifdef __cplusplus
}
#endif
#endif
85 changes: 85 additions & 0 deletions ffi/diplomat/cpp/include/ICU4XCodePointMapData16.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#ifndef ICU4XCodePointMapData16_HPP
#define ICU4XCodePointMapData16_HPP
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <algorithm>
#include <memory>
#include <variant>
#include <optional>
#include <span>
#include "diplomat_runtime.hpp"

namespace capi {
#include "ICU4XCodePointMapData16.h"
}

class ICU4XDataProvider;
struct ICU4XCodePointMapData16Response;
class ICU4XStaticDataProvider;

/**
* A destruction policy for using ICU4XCodePointMapData16 with std::unique_ptr.
*/
struct ICU4XCodePointMapData16Deleter {
void operator()(capi::ICU4XCodePointMapData16* l) const noexcept {
capi::ICU4XCodePointMapData16_destroy(l);
}
};
class ICU4XCodePointMapData16 {
public:

/**
* Gets a map for Unicode property Script from a [`ICU4XDataProvider`].
* See [the Rust docs](https://unicode-org.github.io/icu4x-docs/doc/icu_properties/maps/fn.get_script.html) for more information.
*/
static ICU4XCodePointMapData16Response try_get_script(const ICU4XDataProvider& provider);

/**
* Gets a map for Unicode property Script from a [`ICU4XStaticDataProvider`].
* See [the Rust docs](https://unicode-org.github.io/icu4x-docs/doc/icu_properties/maps/fn.get_script.html) for more information.
*/
static ICU4XCodePointMapData16Response try_get_script_from_static(const ICU4XStaticDataProvider& provider);

/**
* Gets the value for a code point.
* See [the Rust docs](https://unicode-org.github.io/icu4x-docs/doc/icu_codepointtrie/codepointtrie/struct.CodePointTrie.html#method.get_u32) for more information.
*/
uint16_t get(char32_t cp) const;
inline const capi::ICU4XCodePointMapData16* AsFFI() const { return this->inner.get(); }
inline capi::ICU4XCodePointMapData16* AsFFIMut() { return this->inner.get(); }
inline ICU4XCodePointMapData16(capi::ICU4XCodePointMapData16* i) : inner(i) {}
private:
std::unique_ptr<capi::ICU4XCodePointMapData16, ICU4XCodePointMapData16Deleter> inner;
};

#include "ICU4XDataProvider.hpp"
#include "ICU4XCodePointMapData16Response.hpp"
#include "ICU4XStaticDataProvider.hpp"

inline ICU4XCodePointMapData16Response ICU4XCodePointMapData16::try_get_script(const ICU4XDataProvider& provider) {
capi::ICU4XCodePointMapData16Response diplomat_raw_struct_out_value = capi::ICU4XCodePointMapData16_try_get_script(provider.AsFFI());
auto diplomat_optional_raw_out_value_data = diplomat_raw_struct_out_value.data;
std::optional<ICU4XCodePointMapData16> diplomat_optional_out_value_data;
if (diplomat_optional_raw_out_value_data != nullptr) {
diplomat_optional_out_value_data = ICU4XCodePointMapData16(diplomat_optional_raw_out_value_data);
} else {
diplomat_optional_out_value_data = std::nullopt;
}
return ICU4XCodePointMapData16Response{ .data = std::move(diplomat_optional_out_value_data), .success = std::move(diplomat_raw_struct_out_value.success) };
}
inline ICU4XCodePointMapData16Response ICU4XCodePointMapData16::try_get_script_from_static(const ICU4XStaticDataProvider& provider) {
capi::ICU4XCodePointMapData16Response diplomat_raw_struct_out_value = capi::ICU4XCodePointMapData16_try_get_script_from_static(provider.AsFFI());
auto diplomat_optional_raw_out_value_data = diplomat_raw_struct_out_value.data;
std::optional<ICU4XCodePointMapData16> diplomat_optional_out_value_data;
if (diplomat_optional_raw_out_value_data != nullptr) {
diplomat_optional_out_value_data = ICU4XCodePointMapData16(diplomat_optional_raw_out_value_data);
} else {
diplomat_optional_out_value_data = std::nullopt;
}
return ICU4XCodePointMapData16Response{ .data = std::move(diplomat_optional_out_value_data), .success = std::move(diplomat_raw_struct_out_value.success) };
}
inline uint16_t ICU4XCodePointMapData16::get(char32_t cp) const {
return capi::ICU4XCodePointMapData16_get(this->inner.get(), cp);
}
#endif
24 changes: 24 additions & 0 deletions ffi/diplomat/cpp/include/ICU4XCodePointMapData16Response.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef ICU4XCodePointMapData16Response_H
#define ICU4XCodePointMapData16Response_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif
typedef struct ICU4XCodePointMapData16 ICU4XCodePointMapData16;

typedef struct ICU4XCodePointMapData16Response {
ICU4XCodePointMapData16* data;
bool success;
} ICU4XCodePointMapData16Response;

void ICU4XCodePointMapData16Response_destroy(ICU4XCodePointMapData16Response* self);

#ifdef __cplusplus
}
#endif
#endif
42 changes: 42 additions & 0 deletions ffi/diplomat/cpp/include/ICU4XCodePointMapData16Response.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#ifndef ICU4XCodePointMapData16Response_HPP
#define ICU4XCodePointMapData16Response_HPP
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include <algorithm>
#include <memory>
#include <variant>
#include <optional>
#include <span>
#include "diplomat_runtime.hpp"

namespace capi {
#include "ICU4XCodePointMapData16Response.h"
}

class ICU4XCodePointMapData16;

/**
* A destruction policy for using ICU4XCodePointMapData16Response with std::unique_ptr.
*/
struct ICU4XCodePointMapData16ResponseDeleter {
void operator()(capi::ICU4XCodePointMapData16Response* l) const noexcept {
capi::ICU4XCodePointMapData16Response_destroy(l);
}
};
struct ICU4XCodePointMapData16Response {
public:

/**
* The [`ICU4XCodePointMapData16`], if creation was successful.
*/
std::optional<ICU4XCodePointMapData16> data;

/**
* Whether creating the [`ICU4XCodePointMapData16`] was successful.
*/
bool success;
};


#endif
24 changes: 24 additions & 0 deletions ffi/diplomat/cpp/include/ICU4XCodePointMapDataResponse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#ifndef ICU4XCodePointMapDataResponse_H
#define ICU4XCodePointMapDataResponse_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif
typedef struct ICU4XCodePointMapData16 ICU4XCodePointMapData16;

typedef struct ICU4XCodePointMapDataResponse {
ICU4XCodePointMapData16* data;
bool success;
} ICU4XCodePointMapDataResponse;

void ICU4XCodePointMapDataResponse_destroy(ICU4XCodePointMapDataResponse* self);

#ifdef __cplusplus
}
#endif
#endif
28 changes: 28 additions & 0 deletions ffi/diplomat/cpp/include/ICU4XCodePointSetData.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#ifndef ICU4XCodePointSetData_H
#define ICU4XCodePointSetData_H
#include <stdio.h>
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#include "diplomat_runtime.h"

#ifdef __cplusplus
extern "C" {
#endif

typedef struct ICU4XCodePointSetData ICU4XCodePointSetData;
#include "ICU4XDataProvider.h"
#include "ICU4XCodePointSetDataResult.h"
#include "ICU4XStaticDataProvider.h"

ICU4XCodePointSetDataResult ICU4XCodePointSetData_try_get_ascii_hex_digit(const ICU4XDataProvider* provider);

ICU4XCodePointSetDataResult ICU4XCodePointSetData_try_get_ascii_hex_digit_from_static(const ICU4XStaticDataProvider* provider);

bool ICU4XCodePointSetData_contains(const ICU4XCodePointSetData* self, char32_t cp);
void ICU4XCodePointSetData_destroy(ICU4XCodePointSetData* self);

#ifdef __cplusplus
}
#endif
#endif
Loading

0 comments on commit a7c2296

Please sign in to comment.