C++: rename component_type to static_vtable

Then there is no reference to "component" in vtable.h
This commit is contained in:
Olivier Goffart 2021-01-14 09:39:21 +01:00
parent 1bcf446078
commit 090039094f
18 changed files with 26 additions and 23 deletions

View file

@ -112,7 +112,7 @@ public:
void init_items(Component *c, ItemTree items) const
{
cbindgen_private::sixtyfps_component_init_items(
vtable::VRef<ComponentVTable> { &Component::component_type, c }, items, &inner);
vtable::VRef<ComponentVTable> { &Component::static_vtable, c }, items, &inner);
}
template<typename Component>
@ -547,7 +547,7 @@ public:
vtable::VRef<private_api::ComponentVTable> item_at(int i) const
{
const auto &x = inner->data.at(i);
return { &C::component_type, const_cast<C *>(&(**x.ptr)) };
return { &C::static_vtable, const_cast<C *>(&(**x.ptr)) };
}
void compute_layout(cbindgen_private::Rect parent_rect) const
@ -555,7 +555,7 @@ public:
if (!inner)
return;
for (auto &x : inner->data) {
(*x.ptr)->apply_layout({ &C::component_type, const_cast<C *>(&(**x.ptr)) },
(*x.ptr)->apply_layout({ &C::static_vtable, const_cast<C *>(&(**x.ptr)) },
parent_rect);
}
}

View file

@ -66,7 +66,7 @@ struct VRcInner {
template<typename VTable_, typename X_> friend class VWeak;
private:
VRcInner() : layout {} {}
const VTable *vtable = &X::component_type;
const VTable *vtable = &X::static_vtable;
int strong_ref = 1;
int weak_ref = 1;
std::uint16_t data_offset = offsetof(VRcInner, data);
@ -108,6 +108,9 @@ public:
new(this) VRc(other);
return *this;
}
/// Construct a new VRc holding an X.
///
/// The type X must have a static member `static_vtable` of type VTable
template<typename ...Args> static VRc make(Args... args) {
auto mem = ::operator new(sizeof(VRcInner<VTable, X>), static_cast<std::align_val_t>(alignof(VRcInner<VTable, X>)));
auto inner = new (mem) VRcInner<VTable, X>;