Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:30:44

0001 // Copyright 2016 Klemens Morgenstern, Antony Polukhin
0002 //
0003 // Distributed under the Boost Software License, Version 1.0.
0004 // (See accompanying file LICENSE_1_0.txt
0005 // or copy at http://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // For more information, see http://www.boost.org
0008 
0009 #ifndef BOOST_DLL_DETAIL_TYPE_INFO_HPP_
0010 #define BOOST_DLL_DETAIL_TYPE_INFO_HPP_
0011 
0012 #include <typeinfo>
0013 #include <cstring>
0014 #include <boost/dll/config.hpp>
0015 #if defined(_MSC_VER) // MSVC, Clang-cl, and ICC on Windows
0016 #include <boost/winapi/basic_types.hpp>
0017 #endif
0018 
0019 namespace boost { namespace dll { namespace detail {
0020 
0021 #if defined(_MSC_VER) // MSVC, Clang-cl, and ICC on Windows
0022 
0023 #if defined ( _WIN64 )
0024 
0025 template<typename Class, typename Lib, typename Storage>
0026 const std::type_info& load_type_info(Lib & lib, Storage & storage)
0027 {
0028     struct RTTICompleteObjectLocator
0029     {
0030         boost::winapi::DWORD_ signature; //always zero ?
0031         boost::winapi::DWORD_ offset;    //offset of this vtable in the complete class
0032         boost::winapi::DWORD_ cdOffset;  //constructor displacement offset
0033         boost::winapi::DWORD_ pTypeDescriptorOffset; //TypeDescriptor of the complete class
0034         boost::winapi::DWORD_ pClassDescriptorOffset; //describes inheritance hierarchy (ignored)
0035     };
0036 
0037     RTTICompleteObjectLocator** vtable_p = &lib.template get<RTTICompleteObjectLocator*>(storage.template get_vtable<Class>());
0038 
0039     vtable_p--;
0040     auto vtable = *vtable_p;
0041 
0042     auto nat = reinterpret_cast<const char*>(lib.native());
0043 
0044     nat += vtable->pTypeDescriptorOffset;
0045 
0046     return *reinterpret_cast<const std::type_info*>(nat);
0047 
0048 }
0049 
0050 #else
0051 
0052 template<typename Class, typename Lib, typename Storage>
0053 const std::type_info& load_type_info(Lib & lib, Storage & storage)
0054 {
0055     struct RTTICompleteObjectLocator
0056     {
0057         boost::winapi::DWORD_ signature; //always zero ?
0058         boost::winapi::DWORD_ offset;    //offset of this vtable in the complete class
0059         boost::winapi::DWORD_ cdOffset;  //constructor displacement offset
0060         const std::type_info* pTypeDescriptor; //TypeDescriptor of the complete class
0061         void* pClassDescriptor; //describes inheritance hierarchy (ignored)
0062     };
0063 
0064     RTTICompleteObjectLocator** vtable_p = &lib.template get<RTTICompleteObjectLocator*>(storage.template get_vtable<Class>());
0065 
0066     vtable_p--;
0067     auto vtable = *vtable_p;
0068     return *vtable->pTypeDescriptor;
0069 
0070 }
0071 
0072 #endif //_WIN64
0073 
0074 #else
0075 
0076 template<typename Class, typename Lib, typename Storage>
0077 const std::type_info& load_type_info(Lib & lib, Storage & storage)
0078 {
0079     return lib.template get<const std::type_info>(storage.template get_type_info<Class>());
0080 
0081 }
0082 
0083 #endif
0084 
0085 
0086 }}}
0087 #endif /* BOOST_DLL_DETAIL_TYPE_INFO_HPP_ */