Change Model::row_data to return an Option<T> (#873)

Change Model::row_data to return an Option<T> (rust) or std::optional<T> (c++)

Co-authored-by: Olivier Goffart <olivier@woboq.com>
Co-authored-by: Simon Hausmann <hausmann@gmail.com>
This commit is contained in:
Tobias Hunger 2022-01-26 13:55:38 +01:00 committed by GitHub
parent e2ec76f9ef
commit e3c4209b1f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
24 changed files with 229 additions and 102 deletions

View file

@ -462,9 +462,13 @@ inline Value::Value(const std::shared_ptr<sixtyfps::Model<Value>> &model)
return reinterpret_cast<ModelWrapper *>(self.instance)->model->row_count();
};
auto row_data = [](VRef<ModelAdaptorVTable> self, uintptr_t row, ValueOpaque *out) {
Value v = reinterpret_cast<ModelWrapper *>(self.instance)->model->row_data(int(row));
*out = v.inner;
cbindgen_private::sixtyfps_interpreter_value_new(&v.inner);
std::optional<Value> v = reinterpret_cast<ModelWrapper *>(self.instance)->model->row_data(int(row));
if (v.has_value()) {
*out = v->inner;
cbindgen_private::sixtyfps_interpreter_value_new(&v->inner);
return true;
}
return false;
};
auto set_row_data = [](VRef<ModelAdaptorVTable> self, uintptr_t row, const ValueOpaque *value) {
Value v = *reinterpret_cast<const Value *>(value);