slint/api/sixtyfps-cpp/include/sixtyfps_string.h
2020-05-18 17:09:40 +02:00

36 lines
1.2 KiB
C++

#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
};
}