Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
692 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef Float64Vec_H | ||
#define Float64Vec_H | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include "diplomat_runtime.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct Float64Vec Float64Vec; | ||
|
||
Float64Vec* Float64Vec_new(const double* v_data, size_t v_len); | ||
|
||
void Float64Vec_fill_slice(const Float64Vec* self, double* v_data, size_t v_len); | ||
|
||
void Float64Vec_set_value(Float64Vec* self, const double* new_slice_data, size_t new_slice_len); | ||
void Float64Vec_destroy(Float64Vec* self); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef MyString_H | ||
#define MyString_H | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include "diplomat_runtime.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct MyString MyString; | ||
|
||
MyString* MyString_new(const char* v_data, size_t v_len); | ||
|
||
void MyString_set_str(MyString* self, const char* new_str_data, size_t new_str_len); | ||
|
||
void MyString_get_str(const MyString* self, DiplomatWriteable* writeable); | ||
|
||
void MyString_make_uppercase(char* v_data, size_t v_len); | ||
void MyString_destroy(MyString* self); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ Documentation | |
|
||
option_ffi | ||
result_ffi | ||
slices_ffi | ||
structs_ffi | ||
|
||
Indices and tables | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
``slices::ffi`` | ||
=============== | ||
|
||
.. cpp:class:: Float64Vec | ||
|
||
.. cpp:function:: static Float64Vec new_(const diplomat::span<double> v) | ||
|
||
.. cpp:function:: void fill_slice(diplomat::span<double> v) const | ||
|
||
.. cpp:function:: void set_value(const diplomat::span<double> new_slice) | ||
|
||
.. cpp:class:: MyString | ||
|
||
.. cpp:function:: static MyString new_(const std::string_view v) | ||
|
||
.. cpp:function:: void set_str(const std::string_view new_str) | ||
|
||
.. cpp:function:: template<typename W> void get_str_to_writeable(W& writeable) const | ||
|
||
.. cpp:function:: std::string get_str() const | ||
|
||
.. cpp:function:: static void make_uppercase(std::string_view v) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#ifndef Float64Vec_H | ||
#define Float64Vec_H | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include "diplomat_runtime.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct Float64Vec Float64Vec; | ||
|
||
Float64Vec* Float64Vec_new(const double* v_data, size_t v_len); | ||
|
||
void Float64Vec_fill_slice(const Float64Vec* self, double* v_data, size_t v_len); | ||
|
||
void Float64Vec_set_value(Float64Vec* self, const double* new_slice_data, size_t new_slice_len); | ||
void Float64Vec_destroy(Float64Vec* self); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
#ifndef Float64Vec_HPP | ||
#define Float64Vec_HPP | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include <algorithm> | ||
#include <memory> | ||
#include <variant> | ||
#include <optional> | ||
#include "diplomat_runtime.hpp" | ||
|
||
namespace capi { | ||
#include "Float64Vec.h" | ||
} | ||
|
||
class Float64Vec; | ||
|
||
/** | ||
* A destruction policy for using Float64Vec with std::unique_ptr. | ||
*/ | ||
struct Float64VecDeleter { | ||
void operator()(capi::Float64Vec* l) const noexcept { | ||
capi::Float64Vec_destroy(l); | ||
} | ||
}; | ||
class Float64Vec { | ||
public: | ||
static Float64Vec new_(const diplomat::span<double> v); | ||
void fill_slice(diplomat::span<double> v) const; | ||
void set_value(const diplomat::span<double> new_slice); | ||
inline const capi::Float64Vec* AsFFI() const { return this->inner.get(); } | ||
inline capi::Float64Vec* AsFFIMut() { return this->inner.get(); } | ||
inline Float64Vec(capi::Float64Vec* i) : inner(i) {} | ||
Float64Vec() = default; | ||
Float64Vec(Float64Vec&&) noexcept = default; | ||
Float64Vec& operator=(Float64Vec&& other) noexcept = default; | ||
private: | ||
std::unique_ptr<capi::Float64Vec, Float64VecDeleter> inner; | ||
}; | ||
|
||
|
||
inline Float64Vec Float64Vec::new_(const diplomat::span<double> v) { | ||
return Float64Vec(capi::Float64Vec_new(v.data(), v.size())); | ||
} | ||
inline void Float64Vec::fill_slice(diplomat::span<double> v) const { | ||
capi::Float64Vec_fill_slice(this->inner.get(), v.data(), v.size()); | ||
} | ||
inline void Float64Vec::set_value(const diplomat::span<double> new_slice) { | ||
capi::Float64Vec_set_value(this->inner.get(), new_slice.data(), new_slice.size()); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef MyString_H | ||
#define MyString_H | ||
#include <stdio.h> | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include "diplomat_runtime.h" | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct MyString MyString; | ||
|
||
MyString* MyString_new(const char* v_data, size_t v_len); | ||
|
||
void MyString_set_str(MyString* self, const char* new_str_data, size_t new_str_len); | ||
|
||
void MyString_get_str(const MyString* self, DiplomatWriteable* writeable); | ||
|
||
void MyString_make_uppercase(char* v_data, size_t v_len); | ||
void MyString_destroy(MyString* self); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
#ifndef MyString_HPP | ||
#define MyString_HPP | ||
#include <stdint.h> | ||
#include <stddef.h> | ||
#include <stdbool.h> | ||
#include <algorithm> | ||
#include <memory> | ||
#include <variant> | ||
#include <optional> | ||
#include "diplomat_runtime.hpp" | ||
|
||
namespace capi { | ||
#include "MyString.h" | ||
} | ||
|
||
class MyString; | ||
|
||
/** | ||
* A destruction policy for using MyString with std::unique_ptr. | ||
*/ | ||
struct MyStringDeleter { | ||
void operator()(capi::MyString* l) const noexcept { | ||
capi::MyString_destroy(l); | ||
} | ||
}; | ||
class MyString { | ||
public: | ||
static MyString new_(const std::string_view v); | ||
void set_str(const std::string_view new_str); | ||
template<typename W> void get_str_to_writeable(W& writeable) const; | ||
std::string get_str() const; | ||
static void make_uppercase(std::string_view v); | ||
inline const capi::MyString* AsFFI() const { return this->inner.get(); } | ||
inline capi::MyString* AsFFIMut() { return this->inner.get(); } | ||
inline MyString(capi::MyString* i) : inner(i) {} | ||
MyString() = default; | ||
MyString(MyString&&) noexcept = default; | ||
MyString& operator=(MyString&& other) noexcept = default; | ||
private: | ||
std::unique_ptr<capi::MyString, MyStringDeleter> inner; | ||
}; | ||
|
||
|
||
inline MyString MyString::new_(const std::string_view v) { | ||
return MyString(capi::MyString_new(v.data(), v.size())); | ||
} | ||
inline void MyString::set_str(const std::string_view new_str) { | ||
capi::MyString_set_str(this->inner.get(), new_str.data(), new_str.size()); | ||
} | ||
template<typename W> inline void MyString::get_str_to_writeable(W& writeable) const { | ||
capi::DiplomatWriteable writeable_writer = diplomat::WriteableTrait<W>::Construct(writeable); | ||
capi::MyString_get_str(this->inner.get(), &writeable_writer); | ||
} | ||
inline std::string MyString::get_str() const { | ||
std::string diplomat_writeable_string; | ||
capi::DiplomatWriteable diplomat_writeable_out = diplomat::WriteableFromString(diplomat_writeable_string); | ||
capi::MyString_get_str(this->inner.get(), &diplomat_writeable_out); | ||
return diplomat_writeable_string; | ||
} | ||
inline void MyString::make_uppercase(std::string_view v) { | ||
capi::MyString_make_uppercase(v.data(), v.size()); | ||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
// Automatically generated by Diplomat | ||
|
||
#pragma warning disable 0105 | ||
using System; | ||
using System.Runtime.InteropServices; | ||
|
||
using DiplomatFeatures.Diplomat; | ||
#pragma warning restore 0105 | ||
|
||
namespace DiplomatFeatures; | ||
|
||
#nullable enable | ||
|
||
public partial class Float64Vec: IDisposable | ||
{ | ||
private unsafe Raw.Float64Vec* _inner; | ||
|
||
/// <summary> | ||
/// Creates a managed <c>Float64Vec</c> from a raw handle. | ||
/// </summary> | ||
/// <remarks> | ||
/// Safety: you should not build two managed objects using the same raw handle (may causes use-after-free and double-free). | ||
/// </remarks> | ||
/// <remarks> | ||
/// This constructor assumes the raw struct is allocated on Rust side. | ||
/// If implemented, the custom Drop implementation on Rust side WILL run on destruction. | ||
/// </remarks> | ||
public unsafe Float64Vec(Raw.Float64Vec* handle) | ||
{ | ||
_inner = handle; | ||
} | ||
|
||
/// <returns> | ||
/// A <c>Float64Vec</c> allocated on Rust side. | ||
/// If a custom Drop implementation is implemented on Rust side, it WILL run on destruction. | ||
/// </returns> | ||
public static Float64Vec New(double[] v) | ||
{ | ||
unsafe | ||
{ | ||
nuint vLength = (nuint)v.Length; | ||
fixed (double* vPtr = v) | ||
{ | ||
Raw.Float64Vec* retVal = Raw.Float64Vec.New(vPtr, vLength); | ||
return new Float64Vec(retVal); | ||
} | ||
} | ||
} | ||
|
||
public void FillSlice(double[] v) | ||
{ | ||
unsafe | ||
{ | ||
if (_inner == null) | ||
{ | ||
throw new ObjectDisposedException("Float64Vec"); | ||
} | ||
nuint vLength = (nuint)v.Length; | ||
fixed (double* vPtr = v) | ||
{ | ||
Raw.Float64Vec.FillSlice(_inner, vPtr, vLength); | ||
} | ||
} | ||
} | ||
|
||
public void SetValue(double[] newSlice) | ||
{ | ||
unsafe | ||
{ | ||
if (_inner == null) | ||
{ | ||
throw new ObjectDisposedException("Float64Vec"); | ||
} | ||
nuint newSliceLength = (nuint)newSlice.Length; | ||
fixed (double* newSlicePtr = newSlice) | ||
{ | ||
Raw.Float64Vec.SetValue(_inner, newSlicePtr, newSliceLength); | ||
} | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Returns the underlying raw handle. | ||
/// </summary> | ||
public unsafe Raw.Float64Vec* AsFFI() | ||
{ | ||
return _inner; | ||
} | ||
|
||
/// <summary> | ||
/// Destroys the underlying object immediately. | ||
/// </summary> | ||
public void Dispose() | ||
{ | ||
unsafe | ||
{ | ||
if (_inner == null) | ||
{ | ||
return; | ||
} | ||
|
||
Raw.Float64Vec.Destroy(_inner); | ||
_inner = null; | ||
|
||
GC.SuppressFinalize(this); | ||
} | ||
} | ||
|
||
~Float64Vec() | ||
{ | ||
Dispose(); | ||
} | ||
} |
Oops, something went wrong.