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