File indexing completed on 2025-09-15 08:31:23
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_DLL_IMPORT_MANGLED_HPP_
0009 #define BOOST_DLL_IMPORT_MANGLED_HPP_
0010
0011
0012
0013
0014
0015
0016
0017 #include <boost/dll/config.hpp>
0018 #if (__cplusplus < 201103L) && (!defined(_MSVC_LANG) || _MSVC_LANG < 201103L)
0019 # error This file requires C++11 at least!
0020 #endif
0021
0022 #include <boost/dll/config.hpp>
0023 #include <boost/dll/smart_library.hpp>
0024 #include <boost/dll/detail/import_mangled_helpers.hpp>
0025
0026 #include <memory> // std::addressof
0027 #include <type_traits>
0028
0029
0030 #ifdef BOOST_HAS_PRAGMA_ONCE
0031 # pragma once
0032 #endif
0033
0034 namespace boost { namespace dll { namespace experimental {
0035
0036 namespace detail
0037 {
0038
0039 template <class ... Ts>
0040 class mangled_library_function {
0041
0042 boost::dll::detail::shared_ptr<shared_library> lib_;
0043 function_tuple<Ts...> f_;
0044 public:
0045 constexpr mangled_library_function(const boost::dll::detail::shared_ptr<shared_library>& lib, Ts*... func_ptr) noexcept
0046 : lib_(lib)
0047 , f_(func_ptr...)
0048 {}
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058
0059 template <class... Args>
0060 auto operator()(Args&&... args) const
0061 -> decltype( f_(static_cast<Args&&>(args)...) )
0062 {
0063 return f_(static_cast<Args&&>(args)...);
0064 }
0065 };
0066
0067
0068 template<class Class, class Sequence>
0069 class mangled_library_mem_fn;
0070
0071 template <class Class, class ... Ts>
0072 class mangled_library_mem_fn<Class, sequence<Ts...>> {
0073
0074 typedef mem_fn_tuple<Ts...> call_tuple_t;
0075 boost::dll::detail::shared_ptr<shared_library> lib_;
0076 call_tuple_t f_;
0077
0078 public:
0079 constexpr mangled_library_mem_fn(const boost::dll::detail::shared_ptr<shared_library>& lib, typename Ts::mem_fn... func_ptr) noexcept
0080 : lib_(lib)
0081 , f_(func_ptr...)
0082 {}
0083
0084 template <class ClassIn, class... Args>
0085 auto operator()(ClassIn *cl, Args&&... args) const
0086 -> decltype( f_(cl, static_cast<Args&&>(args)...) )
0087 {
0088 return f_(cl, static_cast<Args&&>(args)...);
0089 }
0090 };
0091
0092
0093
0094
0095
0096 template<class Seq> struct is_variable : std::false_type {};
0097 template<typename T> struct is_variable<sequence<T>> : std::is_object<T> {};
0098
0099 template <class Sequence,
0100 bool isFunction = is_function_seq<Sequence>::value,
0101 bool isMemFn = is_mem_fn_seq <Sequence>::value,
0102 bool isVariable = is_variable <Sequence>::value>
0103 struct mangled_import_type;
0104
0105 template <class ...Args>
0106 struct mangled_import_type<sequence<Args...>, true,false,false>
0107 {
0108 typedef boost::dll::experimental::detail::mangled_library_function<Args...> type;
0109 static type make(
0110 const boost::dll::experimental::smart_library& p,
0111 const std::string& name)
0112 {
0113 return type(
0114 boost::dll::detail::make_shared<shared_library>(p.shared_lib()),
0115 std::addressof(p.get_function<Args>(name))...);
0116 }
0117 };
0118
0119 template <class Class, class ...Args>
0120 struct mangled_import_type<sequence<Class, Args...>, false, true, false>
0121 {
0122 typedef typename boost::dll::experimental::detail::make_mem_fn_seq<Class, Args...>::type actual_sequence;
0123 typedef typename boost::dll::experimental::detail::mangled_library_mem_fn<Class, actual_sequence> type;
0124
0125
0126 template<class ... ArgsIn>
0127 static type make_impl(
0128 const boost::dll::experimental::smart_library& p,
0129 const std::string & name,
0130 sequence<ArgsIn...> * )
0131 {
0132 return type(boost::dll::detail::make_shared<shared_library>(p.shared_lib()),
0133 p.get_mem_fn<typename ArgsIn::class_type, typename ArgsIn::func_type>(name)...);
0134 }
0135
0136 static type make(
0137 const boost::dll::experimental::smart_library& p,
0138 const std::string& name)
0139 {
0140 return make_impl(p, name, static_cast<actual_sequence*>(nullptr));
0141 }
0142
0143 };
0144
0145 template <class T>
0146 struct mangled_import_type<sequence<T>, false, false, true>
0147 {
0148 typedef boost::dll::detail::shared_ptr<T> type;
0149
0150 static type make(
0151 const boost::dll::experimental::smart_library& p,
0152 const std::string& name)
0153 {
0154 return type(
0155 boost::dll::detail::make_shared<shared_library>(p.shared_lib()),
0156 std::addressof(p.get_variable<T>(name)));
0157 }
0158
0159 };
0160
0161
0162 }
0163
0164
0165 #ifndef BOOST_DLL_DOXYGEN
0166 # define BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE inline typename \
0167 boost::dll::experimental::detail::mangled_import_type<boost::dll::experimental::detail::sequence<Args...>>::type
0168 #endif
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205
0206
0207
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227
0228
0229
0230 template <class ...Args>
0231 BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const boost::dll::fs::path& lib, const char* name,
0232 load_mode::type mode = load_mode::default_mode)
0233 {
0234 typedef typename boost::dll::experimental::detail::mangled_import_type<
0235 boost::dll::experimental::detail::sequence<Args...>> type;
0236
0237 return type::make(boost::dll::experimental::smart_library{lib, mode}, name);
0238 }
0239
0240
0241
0242
0243 template <class ...Args>
0244 BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const boost::dll::fs::path& lib, const std::string& name,
0245 load_mode::type mode = load_mode::default_mode)
0246 {
0247 return boost::dll::experimental::import_mangled<Args...>(lib, name.c_str(), mode);
0248 }
0249
0250
0251 template <class ...Args>
0252 BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const smart_library& lib, const char* name) {
0253 typedef typename boost::dll::experimental::detail::mangled_import_type<detail::sequence<Args...>> type;
0254
0255 return type::make(lib, name);
0256 }
0257
0258
0259 template <class ...Args>
0260 BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const smart_library& lib, const std::string& name) {
0261 return boost::dll::experimental::import_mangled<Args...>(lib, name.c_str());
0262 }
0263
0264
0265 template <class ...Args>
0266 BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(smart_library&& lib, const char* name) {
0267 typedef typename boost::dll::experimental::detail::mangled_import_type<detail::sequence<Args...>> type;
0268 return type::make(std::move(lib), name);
0269 }
0270
0271
0272 template <class ...Args>
0273 BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(smart_library&& lib, const std::string& name) {
0274 return boost::dll::experimental::import_mangled<Args...>(std::move(lib), name.c_str());
0275 }
0276
0277
0278 template <class ...Args>
0279 BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const shared_library& lib, const char* name) {
0280 typedef typename boost::dll::experimental::detail::mangled_import_type<detail::sequence<Args...>> type;
0281 return type::make(
0282 boost::dll::detail::make_shared<boost::dll::experimental::smart_library>(lib),
0283 name
0284 );
0285 }
0286
0287
0288 template <class ...Args>
0289 BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(const shared_library& lib, const std::string& name) {
0290 return boost::dll::experimental::import_mangled<Args...>(lib, name.c_str());
0291 }
0292
0293
0294 template <class ...Args>
0295 BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(shared_library&& lib, const char* name) {
0296 typedef typename boost::dll::experimental::detail::mangled_import_type<detail::sequence<Args...>> type;
0297 return type::make(
0298 boost::dll::experimental::smart_library{std::move(lib)},
0299 name
0300 );
0301 }
0302
0303
0304 template <class ...Args>
0305 BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE import_mangled(shared_library&& lib, const std::string& name) {
0306 return boost::dll::experimental::import_mangled<Args...>(std::move(lib), name.c_str());
0307 }
0308
0309 #undef BOOST_DLL_MANGLED_IMPORT_RESULT_TYPE
0310
0311 }}}
0312
0313
0314 #endif