mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-29 21:34:50 +00:00
Add a shared string that can be used in properties
This commit is contained in:
parent
e6be2c91b8
commit
25bf149e13
14 changed files with 208 additions and 52 deletions
|
@ -1,16 +1,9 @@
|
|||
|
||||
namespace sixtyfps::internal {
|
||||
// FIXME: this is just required because of something wrong
|
||||
// with &str in cbindgen, but one should not have &str anyway
|
||||
using str = char;
|
||||
|
||||
// Workaround https://github.com/eqrion/cbindgen/issues/43
|
||||
struct ComponentVTable;
|
||||
}
|
||||
|
||||
|
||||
#include "sixtyfps_gl_internal.h"
|
||||
#include "sixtyfps_internal.h"
|
||||
#include "sixtyfps_gl_internal.h"
|
||||
|
||||
namespace sixtyfps {
|
||||
|
||||
|
|
36
api/sixtyfps-cpp/include/sixtyfps_string.h
Normal file
36
api/sixtyfps-cpp/include/sixtyfps_string.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#include <string_view>
|
||||
#include "sixtyfps_string_internal.h"
|
||||
|
||||
namespace sixtyfps {
|
||||
|
||||
struct SharedString
|
||||
{
|
||||
SharedString() { internal::sixtyfps_shared_string_from_bytes(this, "", 0); }
|
||||
SharedString(std::string_view s)
|
||||
{
|
||||
internal::sixtyfps_shared_string_from_bytes(this, s.data(), s.size());
|
||||
}
|
||||
SharedString(const SharedString &other)
|
||||
{
|
||||
internal::sixtyfps_shared_string_clone(this, &other);
|
||||
}
|
||||
~SharedString() { internal::sixtyfps_shared_string_drop(this); }
|
||||
SharedString &operator=(const SharedString &other)
|
||||
{
|
||||
internal::sixtyfps_shared_string_drop(this);
|
||||
internal::sixtyfps_shared_string_clone(this, &other);
|
||||
}
|
||||
SharedString &operator=(std::string_view s)
|
||||
{
|
||||
internal::sixtyfps_shared_string_drop(this);
|
||||
internal::sixtyfps_shared_string_from_bytes(this, s.data(), s.size());
|
||||
}
|
||||
SharedString &operator=(SharedString &&other) { std::swap(inner, other.inner); }
|
||||
|
||||
operator std::string_view() const { return internal::sixtyfps_shared_string_bytes(this); }
|
||||
auto data() const -> const char * { return internal::sixtyfps_shared_string_bytes(this); }
|
||||
|
||||
private:
|
||||
void *inner; // opaque
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue