Warning, file /include/boost/dll/import.hpp was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef BOOST_DLL_IMPORT_HPP
0009 #define BOOST_DLL_IMPORT_HPP
0010
0011 #include <boost/dll/config.hpp>
0012 #include <boost/dll/shared_library.hpp>
0013
0014 #include <memory> // std::addressof
0015 #include <type_traits>
0016
0017 #ifdef BOOST_HAS_PRAGMA_ONCE
0018 # pragma once
0019 #endif
0020
0021
0022
0023
0024
0025
0026 namespace boost { namespace dll {
0027
0028
0029 namespace detail {
0030
0031 template <class T>
0032 class library_function {
0033
0034 boost::dll::detail::shared_ptr<T> f_;
0035
0036 public:
0037 inline library_function(const boost::dll::detail::shared_ptr<shared_library>& lib, T* func_ptr) noexcept
0038 : f_(lib, func_ptr)
0039 {}
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 template <class... Args>
0050 inline auto operator()(Args&&... args) const
0051 -> decltype( (*f_)(static_cast<Args&&>(args)...) )
0052 {
0053 return (*f_)(static_cast<Args&&>(args)...);
0054 }
0055 };
0056
0057 template <class T>
0058 using import_type = typename std::conditional<
0059 std::is_object<T>::value,
0060 boost::dll::detail::shared_ptr<T>,
0061 boost::dll::detail::library_function<T>
0062 >::type;
0063 }
0064
0065
0066 #ifndef BOOST_DLL_DOXYGEN
0067 # define BOOST_DLL_IMPORT_RESULT_TYPE inline boost::dll::detail::import_type<T>
0068 #endif
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101
0102
0103
0104
0105
0106
0107 template <class T>
0108 BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(const boost::dll::fs::path& lib, const char* name,
0109 load_mode::type mode = load_mode::default_mode)
0110 {
0111 using type = boost::dll::detail::import_type<T>;
0112
0113 auto p = boost::dll::detail::make_shared<boost::dll::shared_library>(lib, mode);
0114 auto* addr = std::addressof(p->get<T>(name));
0115 return type(std::move(p), addr);
0116 }
0117
0118
0119 template <class T>
0120 BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(const boost::dll::fs::path& lib, const std::string& name,
0121 load_mode::type mode = load_mode::default_mode)
0122 {
0123 return dll::import_symbol<T>(lib, name.c_str(), mode);
0124 }
0125
0126
0127 template <class T>
0128 BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(const shared_library& lib, const char* name) {
0129 using type = boost::dll::detail::import_type<T>;
0130
0131 auto p = boost::dll::detail::make_shared<boost::dll::shared_library>(lib);
0132 return type(p, std::addressof(p->get<T>(name)));
0133 }
0134
0135
0136 template <class T>
0137 BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(const shared_library& lib, const std::string& name) {
0138 return dll::import_symbol<T>(lib, name.c_str());
0139 }
0140
0141
0142 template <class T>
0143 BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(shared_library&& lib, const char* name) {
0144 using type = boost::dll::detail::import_type<T>;
0145
0146 auto p = boost::dll::detail::make_shared<boost::dll::shared_library>(
0147 std::move(lib)
0148 );
0149 auto* addr = std::addressof(p->get<T>(name));
0150 return type(std::move(p), addr);
0151 }
0152
0153
0154 template <class T>
0155 BOOST_DLL_IMPORT_RESULT_TYPE import_symbol(shared_library&& lib, const std::string& name) {
0156 return dll::import_symbol<T>(std::move(lib), name.c_str());
0157 }
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168
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 template <class T>
0202 BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const boost::dll::fs::path& lib, const char* name,
0203 load_mode::type mode = load_mode::default_mode)
0204 {
0205 using type = boost::dll::detail::import_type<T>;
0206
0207 auto p = boost::dll::detail::make_shared<boost::dll::shared_library>(lib, mode);
0208 auto* addr = p->get<T*>(name);
0209 return type(std::move(p), addr);
0210 }
0211
0212
0213 template <class T>
0214 BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const boost::dll::fs::path& lib, const std::string& name,
0215 load_mode::type mode = load_mode::default_mode)
0216 {
0217 return dll::import_alias<T>(lib, name.c_str(), mode);
0218 }
0219
0220
0221 template <class T>
0222 BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const shared_library& lib, const char* name) {
0223 using type = boost::dll::detail::import_type<T>;
0224
0225 auto p = boost::dll::detail::make_shared<boost::dll::shared_library>(lib);
0226 auto* addr = p->get<T*>(name);
0227 return type(std::move(p), addr);
0228 }
0229
0230
0231 template <class T>
0232 BOOST_DLL_IMPORT_RESULT_TYPE import_alias(const shared_library& lib, const std::string& name) {
0233 return dll::import_alias<T>(lib, name.c_str());
0234 }
0235
0236
0237 template <class T>
0238 BOOST_DLL_IMPORT_RESULT_TYPE import_alias(shared_library&& lib, const char* name) {
0239 using type = boost::dll::detail::import_type<T>;
0240
0241 auto p = boost::dll::detail::make_shared<boost::dll::shared_library>(
0242 std::move(lib)
0243 );
0244 auto* addr = p->get<T*>(name);
0245 return type(std::move(p), addr);
0246 }
0247
0248
0249 template <class T>
0250 BOOST_DLL_IMPORT_RESULT_TYPE import_alias(shared_library&& lib, const std::string& name) {
0251 return dll::import_alias<T>(std::move(lib), name.c_str());
0252 }
0253
0254 #undef BOOST_DLL_IMPORT_RESULT_TYPE
0255
0256
0257 }}
0258
0259 #endif
0260