__forceinline _To fast_dynamic_cast(_From* ptr) { // Not required, dynamic_cast already produces a compile-time error in this case // static_assert(std::is_polymorphic<_From>::value, "Type is not polymorphic!"); if (!ptr) return nullptr; DCAST_THREADLOCAL static ptrdiff_t offset = DCAST_NO_OFFSET; DCAST_THREADLOCAL static v_table_ptr src_vtable_ptr; v_table_ptr this_vtable = get_vtable(ptr); if (offset != DCAST_NO_OFFSET && src_vtable_ptr == this_vtable) { // In case we have a cache hit, casting the pointer is straightforward char* new_ptr = reinterpret_cast<char*>(ptr) + offset; return reinterpret_cast<_To>(new_ptr); } else { // Need to construct cache entry auto result = dynamic_cast<_To>(ptr); if (result == nullptr) return nullptr; src_vtable_ptr = this_vtable; offset = reinterpret_cast<const char*>(result) - reinterpret_cast<const char*>(ptr); return result; } };
bool intergen_bind_capture( coid::binstring* capture, uint instid ) override { if(instid >= 0xffU) return false; _instid = uint16(instid << 8U); _capture = capture; _vtable = _capture ? get_vtable_intercept() : get_vtable(); return true; }
static ifn_t* get_vtable_intercept() { if(_vtable2) return _vtable2; ifn_t* vtable1 = get_vtable(); _vtable2 = new ifn_t[3]; _vtable2[0] = vtable1[0]; _vtable2[1] = vtable1[1]; _vtable2[2] = vtable1[2]; return _vtable2; }
static void* _setupusb(void* context){ usbdevice* kb = context; // Set standard fields short vendor = kb->vendor, product = kb->product; const devcmd* vt = kb->vtable = get_vtable(vendor, product); kb->features = (IS_RGB(vendor, product) ? FEAT_STD_RGB : FEAT_STD_NRGB) & features_mask; if(IS_MOUSE(vendor, product)) kb->features |= FEAT_ADJRATE; if(IS_MONOCHROME(vendor, product)) kb->features |= FEAT_MONOCHROME; kb->usbdelay = USB_DELAY_DEFAULT; // Perform OS-specific setup DELAY_LONG(kb); if(os_setupusb(kb)) goto fail; // Make up a device name and serial if they weren't assigned if(!kb->serial[0]) snprintf(kb->serial, SERIAL_LEN, "%04x:%04x-NoID", kb->vendor, kb->product); if(!kb->name[0]) snprintf(kb->name, KB_NAME_LEN, "%s %s", vendor_str(kb->vendor), product_str(kb->product)); // Set up an input device for key events if(os_inputopen(kb)) goto fail; if(pthread_create(&kb->inputthread, 0, os_inputmain, kb)) goto fail; pthread_detach(kb->inputthread); if(os_setupindicators(kb)) goto fail; // Set up device vt->allocprofile(kb); vt->updateindicators(kb, 1); pthread_mutex_unlock(imutex(kb)); if(vt->start(kb, 0) && usb_tryreset(kb)) goto fail_noinput; // Make /dev path if(mkdevpath(kb)) goto fail_noinput; // Finished. Enter main loop int index = INDEX_OF(kb, keyboard); ckb_info("Setup finished for %s%d\n", devpath, index); updateconnected(); return devmain(kb); fail: pthread_mutex_unlock(imutex(kb)); fail_noinput: closeusb(kb); pthread_mutex_unlock(dmutex(kb)); return 0; }
static iref<thingface> get( thingface* __here__ ) { iref<n1::n2::thing> host = n1::n2::thing::get_thing(); if(!host) return 0; thingface_dispatcher* __disp__ = static_cast<thingface_dispatcher*>(__here__); if(!__disp__) __disp__ = new thingface_dispatcher; __disp__->_host.create(host.get()); __disp__->_vtable = _capture ? get_vtable_intercept() : get_vtable(); if(!host->_ifc) { __disp__->_cleaner = &_cleaner_callback; host->_ifc = __disp__; } return iref<thingface>(__disp__); }
static inline const rtti_object_locator *get_obj_locator( void *cppobj ) { const vtable_ptr *vtable = get_vtable( cppobj ); return (const rtti_object_locator *)vtable[-1]; }
static const cklass_method_entries_type::impl_type& get_method_entries( const ase_variant& self) { return *(static_cast<const cklass_method_entries_type::impl_type *>( get_vtable(self).impl_private_data)); }