14#ifndef CPPINTEROP_CPPINTEROP_H
15#define CPPINTEROP_CPPINTEROP_H
17#ifdef CPPINTEROP_DISPATCH_H
18#error "CppInterOp.h and Dispatch.h are mutually exclusive — include only one."
26#include <initializer_list>
35#include "CppInterOp/CppInterOpDecl.inc"
62 void** vptr = *
reinterpret_cast<void***
>(inst);
70 std::unique_ptr<VTableOverlay, VTableOverlayDeleter>;
87 void* inst, DeclRef base,
88 std::initializer_list<std::pair<ConstFuncRef, void*>> overrides,
89 std::size_t n_extra_prefix_slots = 0,
90 VTableOverlayDtorHook on_destroy =
nullptr,
void* cleanup_data =
nullptr) {
91 std::vector<ConstFuncRef> methods;
92 std::vector<void*> fns;
93 methods.reserve(overrides.size());
94 fns.reserve(overrides.size());
95 for (
const auto& p : overrides) {
96 methods.push_back(p.first);
97 fns.push_back(p.second);
100 inst, base, methods.data(), fns.data(), methods.size(),
101 n_extra_prefix_slots, on_destroy, cleanup_data)};
static constexpr int kVTableOverlayPrefixSize
std::unique_ptr< VTableOverlay, VTableOverlayDeleter > UniqueVTableOverlay
void *& VTableOverlayExtraSlot(void *inst, std::size_t i)
Address of the i-th extra-prefix slot of an instance with an overlay installed via MakeVTableOverlay(...
void DestroyVTableOverlay(VTableOverlay *overlay)
UniqueVTableOverlay MakeUniqueVTableOverlay(void *inst, DeclRef base, std::initializer_list< std::pair< ConstFuncRef, void * > > overrides, std::size_t n_extra_prefix_slots=0, VTableOverlayDtorHook on_destroy=nullptr, void *cleanup_data=nullptr)
Owning wrapper over MakeVTableOverlay: each pair maps a virtual method of polymorphic class base to i...
VTableOverlay * MakeVTableOverlay(void *inst, ConstDeclRef base, const ConstFuncRef *methods, void *const *overlay_fns, std::size_t n_overlays, std::size_t n_extra_prefix_slots, VTableOverlayDtorHook on_destroy, void *cleanup_data)
void operator()(VTableOverlay *o) const noexcept