C++: Expose conversion betwen Value and Image

Closes #350
This commit is contained in:
Olivier Goffart 2021-07-26 09:30:53 +02:00 committed by Olivier Goffart
parent 74bc9521b9
commit 07bf0974d7
5 changed files with 51 additions and 1 deletions

View file

@ -383,6 +383,17 @@ public:
}
}
/// Returns a std::optional that contains an Image if the type of this Value is
/// Type::Image, otherwise an empty optional is returned.
std::optional<Image> to_image() const
{
if (auto *img = cbindgen_private::sixtyfps_interpreter_value_to_image(&inner)) {
return *reinterpret_cast<const Image *>(img);
} else {
return {};
}
}
// template<typename T> std::optional<T> get() const;
/// Constructs a new Value that holds the double \a value.
@ -409,6 +420,12 @@ public:
cbindgen_private::sixtyfps_interpreter_value_new_struct(&struc.inner, &inner);
}
/// Constructs a new Value that holds the Image \a img.
Value(const Image &img)
{
cbindgen_private::sixtyfps_interpreter_value_new_image(&img, &inner);
}
/// Returns the type the variant holds.
Type type() const { return cbindgen_private::sixtyfps_interpreter_value_type(&inner); }