+
+ # Public constructor
+ print '%s *%s::_Create(const char *functionName, %s * pInstance) {' % (getWrapperInterfaceName(interface), getWrapperInterfaceName(interface), interface.name)
+ print r' std::map<void *, void *>::const_iterator it = g_WrappedObjects.find(pInstance);'
+ print r' if (it != g_WrappedObjects.end()) {'
+ print r' Wrap%s *pWrapper = (Wrap%s *)it->second;' % (interface.name, interface.name)
+ print r' assert(pWrapper);'
+ print r' assert(pWrapper->m_dwMagic == 0xd8365d6c);'
+ print r' assert(pWrapper->m_pInstance == pInstance);'
+ print r' if (pWrapper->m_pVtbl == *(void **)pInstance &&'
+ print r' pWrapper->m_NumMethods >= %s) {' % len(list(interface.iterBaseMethods()))
+ #print r' os::log("%s: fetched pvObj=%p pWrapper=%p pVtbl=%p\n", functionName, pInstance, pWrapper, pWrapper->m_pVtbl);'
+ print r' return pWrapper;'
+ print r' }'
+ print r' }'
+ print r' Wrap%s *pWrapper = new Wrap%s(pInstance);' % (interface.name, interface.name)
+ #print r' os::log("%%s: created %s pvObj=%%p pWrapper=%%p pVtbl=%%p\n", functionName, pInstance, pWrapper, pWrapper->m_pVtbl);' % interface.name
+ print r' g_WrappedObjects[pInstance] = pWrapper;'
+ print r' return pWrapper;'
+ print '}'
+ print
+
+ # Destructor