mirror of
https://github.com/slint-ui/slint.git
synced 2025-10-01 06:11:16 +00:00
Remove the null state in ComponentDefinition
This isn't needed as it turns out and a cleaner API this way
This commit is contained in:
parent
4705c455b9
commit
59d6866b13
1 changed files with 13 additions and 22 deletions
|
@ -422,17 +422,17 @@ class ComponentDefinition
|
||||||
{
|
{
|
||||||
friend class ComponentCompiler;
|
friend class ComponentCompiler;
|
||||||
|
|
||||||
union {
|
using ComponentDefinitionOpaque = sixtyfps::cbindgen_private::ComponentDefinitionOpaque;
|
||||||
sixtyfps::cbindgen_private::ComponentDefinitionOpaque inner;
|
ComponentDefinitionOpaque inner;
|
||||||
void *ptr;
|
|
||||||
};
|
ComponentDefinition() = delete;
|
||||||
|
// Internal constructor that takes ownership of the component definition
|
||||||
|
explicit ComponentDefinition(ComponentDefinitionOpaque &inner) : inner(inner) { }
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ComponentDefinition() { ptr = nullptr; }
|
|
||||||
ComponentDefinition(const ComponentDefinition &other)
|
ComponentDefinition(const ComponentDefinition &other)
|
||||||
{
|
{
|
||||||
ptr = nullptr;
|
sixtyfps_interpreter_component_definition_clone(&other.inner, &inner);
|
||||||
operator=(other);
|
|
||||||
}
|
}
|
||||||
ComponentDefinition &operator=(const ComponentDefinition &other)
|
ComponentDefinition &operator=(const ComponentDefinition &other)
|
||||||
{
|
{
|
||||||
|
@ -441,21 +441,12 @@ public:
|
||||||
if (this == &other)
|
if (this == &other)
|
||||||
return *this;
|
return *this;
|
||||||
|
|
||||||
if (ptr != nullptr)
|
sixtyfps_interpreter_component_definition_destructor(&inner);
|
||||||
sixtyfps_interpreter_component_definition_destructor(&inner);
|
sixtyfps_interpreter_component_definition_clone(&other.inner, &inner);
|
||||||
|
|
||||||
if (other.ptr != nullptr)
|
|
||||||
sixtyfps_interpreter_component_definition_clone(&other.inner, &inner);
|
|
||||||
else
|
|
||||||
ptr = nullptr;
|
|
||||||
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
~ComponentDefinition()
|
~ComponentDefinition() { sixtyfps_interpreter_component_definition_destructor(&inner); }
|
||||||
{
|
|
||||||
if (ptr != nullptr)
|
|
||||||
sixtyfps_interpreter_component_definition_destructor(&inner);
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class ComponentCompiler
|
class ComponentCompiler
|
||||||
|
@ -488,12 +479,12 @@ public:
|
||||||
std::optional<ComponentDefinition> build_from_source(std::string_view source_code,
|
std::optional<ComponentDefinition> build_from_source(std::string_view source_code,
|
||||||
std::string_view path)
|
std::string_view path)
|
||||||
{
|
{
|
||||||
ComponentDefinition result;
|
cbindgen_private::ComponentDefinitionOpaque result;
|
||||||
if (cbindgen_private::sixtyfps_interpreter_component_compiler_build_from_source(
|
if (cbindgen_private::sixtyfps_interpreter_component_compiler_build_from_source(
|
||||||
&inner, sixtyfps::private_api::string_to_slice(source_code),
|
&inner, sixtyfps::private_api::string_to_slice(source_code),
|
||||||
sixtyfps::private_api::string_to_slice(path), &result.inner)) {
|
sixtyfps::private_api::string_to_slice(path), &result)) {
|
||||||
|
|
||||||
return result;
|
return ComponentDefinition(result);
|
||||||
} else {
|
} else {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue