26#include <unordered_map>
32#include <rtl/strbuf.hxx>
33#include <rtl/ustring.hxx>
35#include <typelib/typedescription.h>
45 virtual ~Generated() {};
47 virtual std::type_info *
get()
const = 0;
50class GeneratedPlain:
public Generated {
52 GeneratedPlain(std::unique_ptr<std::type_info> && info): info_(
std::move(info)) {};
54 std::type_info *
get()
const override {
return info_.get(); }
57 std::unique_ptr<std::type_info> info_;
60class GeneratedPad:
public Generated {
62 GeneratedPad(std::unique_ptr<
char[]> && pad): pad_(
std::move(pad)) {};
64 ~GeneratedPad()
override {
get()->~type_info(); }
66 std::type_info *
get() const override final
67 {
return reinterpret_cast<std::type_info *
>(pad_.get()); }
70 std::unique_ptr<char[]> pad_;
75 typedef std::unordered_map< OUString, std::type_info * > t_rtti_map;
78 std::vector<OString> m_rttiNames;
94 :
m_hApp( dlopen(
nullptr, RTLD_LAZY ) )
108 OUString
const & unoName = OUString::unacquired(&pTypeDescr.pTypeName);
110 t_rtti_map::const_iterator iFind(
m_rttis.find( unoName ) );
112 return iFind->second;
114 std::type_info * rtti;
117 OStringBuffer buf( 64 );
118 buf.append(
"_ZTIN" );
122 std::u16string_view token(
o3tl::getToken(unoName, 0,
'.', index ) );
123 buf.append(
static_cast<sal_Int32
>(token.size()) );
125 buf.append( c_token );
130 OString symName( buf.makeStringAndClear() );
132 rtti =
static_cast<std::type_info *
>(dlsym(
m_hApp, symName.getStr() ));
134 rtti =
static_cast<std::type_info *
>(dlsym( RTLD_DEFAULT, symName.getStr() ));
139 std::pair< t_rtti_map::iterator, bool > insertion (
140 m_rttis.insert( t_rtti_map::value_type( unoName, rtti ) ) );
141 SAL_WARN_IF( !insertion.second,
"bridges",
"key " << unoName <<
" already in rtti map" );
150 rtti = iFind2->second->get();
157 char const * rttiName = symName.getStr() +4;
159 SAL_INFO(
"bridges",
"Generated rtti for " << rttiName);
161 std::unique_ptr<Generated> newRtti;
162 switch (pTypeDescr.eTypeClass) {
163 case typelib_TypeClass_EXCEPTION:
165 typelib_CompoundTypeDescription
const & ctd
167 typelib_CompoundTypeDescription
const &
>(
169 if (ctd.pBaseTypeDescription)
172 std::type_info * base_rtti = getRTTI(
173 ctd.pBaseTypeDescription->aBase);
174 m_rttiNames.emplace_back(OString(rttiName));
175 std::unique_ptr<std::type_info> info(
178 newRtti.reset(
new GeneratedPlain(std::move(info)));
183 m_rttiNames.emplace_back(OString(rttiName));
184 std::unique_ptr<std::type_info> info(
186 newRtti.reset(
new GeneratedPlain(std::move(info)));
190 case typelib_TypeClass_INTERFACE:
192 typelib_InterfaceTypeDescription
const & itd
194 typelib_InterfaceTypeDescription
const &
>(
196 std::vector<std::type_info *> bases;
197 for (sal_Int32 i = 0;
i != itd.nBaseTypes; ++
i) {
198 bases.push_back(getRTTI(itd.ppBaseTypes[i]->aBase));
200 switch (itd.nBaseTypes) {
203 m_rttiNames.emplace_back(OString(rttiName));
204 std::unique_ptr<std::type_info> info(
206 m_rttiNames.back().getStr()));
207 newRtti.reset(
new GeneratedPlain(std::move(info)));
212 m_rttiNames.emplace_back(OString(rttiName));
213 std::unique_ptr<std::type_info> info(
215 m_rttiNames.back().getStr(),
219 newRtti.reset(
new GeneratedPlain(std::move(info)));
224 m_rttiNames.emplace_back(OString(rttiName));
225 auto pad = std::make_unique<char[]>(
227 + ((itd.nBaseTypes - 1)
233 m_rttiNames.back().getStr(),
236 for (sal_Int32 i = 0;
i != itd.nBaseTypes; ++
i)
246 newRtti.reset(
new GeneratedPad(std::move(pad)));
255 rtti = newRtti->get();
258 SAL_WARN_IF( !insertion.second,
"bridges",
"key " << unoName <<
" already in generated rtti map" );
266 static RTTI theRttiFactory;
267 static std::mutex theMutex;
268 std::lock_guard aGuard(theMutex);
269 return theRttiFactory.getRTTI(
type);
const __class_type_info * __base_type
unsigned int __base_count
__base_class_type_info __base_info[1]
t_rtti_map m_generatedRttis
#define SAL_WARN_IF(condition, area, stream)
#define SAL_INFO(area, stream)
struct _typelib_TypeDescription typelib_TypeDescription
std::basic_string_view< charT, traits > getToken(std::basic_string_view< charT, traits > sv, charT delimiter, std::size_t &position)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
std::type_info * getRtti(typelib_TypeDescription const &type)