/***mockcpp is a C/C++ mock framework.Copyright [2008] [Darwin Yuan <darwin.yuan@gmail.com>]Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License athttp://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.***/#include <typeinfo>#include <string.h>#include <mockcpp/mockcpp.h>#if defined(_MSC_VER)#include <mockcpp/MsvcRtti.h>#endifMOCKCPP_NS_START///////////////////////////////////////////////////////////////////////namespace{#if defined(__GNUC__)const unsigned int EXTRA_VTBL_SLOT = 2;#elif defined(_MSC_VER)const unsigned int EXTRA_VTBL_SLOT = 1;#endifconst unsigned int SLOTS_PER_VTBL = MOCKCPP_MAX_VTBL_SIZE + EXTRA_VTBL_SLOT;unsigned int times = 0;}///////////////////////////////////////////////////////////////////////void** createVtbls(unsigned int numberOfVptr){void **p = new void*[numberOfVptr * SLOTS_PER_VTBL];(void)memset(p, 0, sizeof(void *) * numberOfVptr * SLOTS_PER_VTBL);return p;}void freeVtbls(void** vtbl, unsigned int numberOfVptr){#if defined(_MSC_VER)RTTIClassHierarchyDescriptor* desc = 0;for(unsigned int i=0; i<numberOfVptr; i++){int base = i*SLOTS_PER_VTBL;if(vtbl[base] != 0){RTTICompleteObjectLocator* rtti = (RTTICompleteObjectLocator*)vtbl[base];desc = rtti->pClassDescriptor;delete rtti;}}if(desc != 0){delete desc;}#endifdelete [] vtbl;}///////////////////////////////////////////////////////////////////////unsigned int getRealVtblIndex(unsigned int indexOfVptr, unsigned int indexOfVtbl){return indexOfVptr * SLOTS_PER_VTBL + EXTRA_VTBL_SLOT + indexOfVtbl ;}///////////////////////////////////////////////////////////////////////void initializeVtbls(void** vptr, void**vtbl, unsigned int numberOfVptr, const std::type_info& info, bool hasRtti){#if defined(_MSC_VER)RTTIClassHierarchyDescriptor * desc = 0;if(hasRtti){desc = new RTTIClassHierarchyDescriptor(numberOfVptr > 1 ? true : false);}#endiffor(unsigned int i=0; i<numberOfVptr; i++){int base = i*SLOTS_PER_VTBL;#if defined(__GNUC__)vtbl[base + 0] = (void*)(-1*(sizeof(void*)*i));vtbl[base + 1] = (void*)&info;#elif defined(_MSC_VER)//FIXMEvtbl[base + 0] = hasRtti ? new RTTICompleteObjectLocator(i, info, desc) : 0;#endifvptr[i] = (void*)&vtbl[base + EXTRA_VTBL_SLOT];}}///////////////////////////////////////////////////////////////////////MOCKCPP_NS_END
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。