/* * VTUtils.hpp * Copyright (c) 2014 Eran Pe'er. * * This program is made available under the terms of the MIT License. * * Created on Jun 3, 2014 */ #pragma once #include #include #include "mockutils/VirtualOffestSelector.hpp" #include "union_cast.hpp" #pragma warning(disable:4191) namespace fakeit { class NoVirtualDtor { }; class VTUtils { public: template static unsigned int getOffset(R (C::*vMethod)(arglist...)) { auto sMethod = reinterpret_cast(vMethod); VirtualOffsetSelector offsetSelctor; return (offsetSelctor.*sMethod)(0); } template static typename std::enable_if::value, unsigned int>::type getDestructorOffset() { VirtualOffsetSelector offsetSelctor; union_cast(&offsetSelctor)->~C(); return offsetSelctor.offset; } template static typename std::enable_if::value, unsigned int>::type getDestructorOffset() { throw NoVirtualDtor(); } template static unsigned int getVTSize() { struct Derrived : public C { virtual void endOfVt() { } }; unsigned int vtSize = getOffset(&Derrived::endOfVt); return vtSize; } }; } #pragma warning(default:4191)