mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-27 12:29:41 +00:00
Add a SharedArray type
This is based on the SharedString code and will allow sharing ownership of arrays between Rust and C++.
This commit is contained in:
parent
6863c3f631
commit
e4ab64f858
4 changed files with 246 additions and 1 deletions
42
api/sixtyfps-cpp/include/sixtyfps_sharedarray.h
Normal file
42
api/sixtyfps-cpp/include/sixtyfps_sharedarray.h
Normal file
|
@ -0,0 +1,42 @@
|
|||
#pragma once
|
||||
#include "sixtyfps_sharedarray_internal.h"
|
||||
|
||||
namespace sixtyfps {
|
||||
|
||||
template<typename T>
|
||||
struct SharedArray
|
||||
{
|
||||
SharedArray()
|
||||
{
|
||||
internal::sixtyfps_shared_array_new_null(reinterpret_cast<SharedArray<uint8_t> *>(this));
|
||||
}
|
||||
explicit SharedArray(void *inner) : inner(inner) { }
|
||||
|
||||
SharedArray(const SharedArray &other)
|
||||
{
|
||||
internal::sixtyfps_shared_array_clone(
|
||||
reinterpret_cast<SharedArray<uint8_t> *>(this),
|
||||
reinterpret_cast<const SharedArray<uint8_t> *>(&other));
|
||||
}
|
||||
~SharedArray()
|
||||
{
|
||||
internal::sixtyfps_shared_array_drop(reinterpret_cast<SharedArray<uint8_t> *>(this));
|
||||
}
|
||||
SharedArray &operator=(const SharedArray &other)
|
||||
{
|
||||
internal::sixtyfps_shared_array_drop(reinterpret_cast<SharedArray<uint8_t> *>(this));
|
||||
internal::sixtyfps_shared_array_clone(
|
||||
reinterpret_cast<SharedArray<uint8_t> *>(this),
|
||||
reinterpret_cast<const SharedArray<uint8_t> *>(&other));
|
||||
return *this;
|
||||
}
|
||||
SharedArray &operator=(SharedArray &&other)
|
||||
{
|
||||
std::swap(inner, other.inner);
|
||||
return *this;
|
||||
}
|
||||
|
||||
private:
|
||||
void *inner; // opaque
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue