#pragma once #ifdef _MSC_VER #include "mockutils/mscpp/VirtualTable.hpp" #else #include "mockutils/gcc/VirtualTable.hpp" #endif #include "mockutils/MethodProxy.hpp" #include "Destructible.hpp" namespace fakeit { struct InvocationHandlerCollection { static const unsigned int VT_COOKIE_INDEX = 0; virtual Destructible *getInvocatoinHandlerPtrById(unsigned int index) = 0; static InvocationHandlerCollection *getInvocationHandlerCollection(void *instance) { VirtualTableBase &vt = VirtualTableBase::getVTable(instance); InvocationHandlerCollection *invocationHandlerCollection = (InvocationHandlerCollection *) vt.getCookie( InvocationHandlerCollection::VT_COOKIE_INDEX); return invocationHandlerCollection; } }; template class MethodProxyCreator { //using MethodProxyPtrType = R(MethodProxyCreator::*)(arglist...); public: template MethodProxy createMethodProxy(unsigned int offset) { return MethodProxy(id, offset, union_cast(&MethodProxyCreator::methodProxyX < id > )); } protected: R methodProxy(unsigned int id, arglist &... args) { InvocationHandlerCollection *invocationHandlerCollection = InvocationHandlerCollection::getInvocationHandlerCollection( this); MethodInvocationHandler *invocationHandler = (MethodInvocationHandler *) invocationHandlerCollection->getInvocatoinHandlerPtrById( id); return invocationHandler->handleMethodInvocation(args...); } template R methodProxyX(arglist ... args) { return methodProxy(id, args...); } }; }