mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-28 04:45:13 +00:00
Even better way to use enums from C++
This commit is contained in:
parent
0674c4f544
commit
bd4bcdfeb3
2 changed files with 7 additions and 18 deletions
|
@ -10,26 +10,12 @@ struct Resource
|
|||
public:
|
||||
using Tag = internal::types::Resource::Tag;
|
||||
|
||||
Resource() : data(create()) { }
|
||||
Resource(const SharedString &file_path) : data(create())
|
||||
{
|
||||
::new (&data.embedded_data)
|
||||
internal::types::Resource::AbsoluteFilePath_Body { Tag::AbsoluteFilePath,
|
||||
file_path };
|
||||
}
|
||||
Resource() : data(Data::None()) { }
|
||||
Resource(const SharedString &file_path) : data(Data::AbsoluteFilePath(file_path)) { }
|
||||
|
||||
private:
|
||||
internal::types::Resource data;
|
||||
|
||||
static internal::types::Resource create()
|
||||
{
|
||||
union U {
|
||||
U() { data.tag = Tag::None; }
|
||||
internal::types::Resource data;
|
||||
~U() { }
|
||||
} u;
|
||||
return u.data;
|
||||
}
|
||||
using Data = internal::types::Resource;
|
||||
Data data;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue